【问题标题】:sqlite3 db created but table doesn't existsqlite3 db 创建但表不存在
【发布时间】:2014-03-21 17:10:53
【问题描述】:

在 Mac 上使用 sqlite3 的内置命令行工具,我运行下面的 sql 模式(由 Lynda.com 教程创建)来创建一个 sql 数据库,数据库bwrss.db 显示为已在下载架构所在的文件夹。然后我运行了本教程提供的这段代码,它应该读取并显示在我创建数据库时插入的提要 ID

-(void) dispRow:(NSDictionary *) row {
    message(@"row %@ [%@]", row [@"title"], row [@"url"]);
}

-(void) testDatabase {
    RSSDB *db;
    NSString * dbfn = @"bwrss.db";

    db = [[RSSDB alloc] initWithRSSDBFilename:dbfn];
    message(@"RSSDB version %@", [db getVersion]);

    for (NSNumber *n in [db getFeedIDs]) {
        NSDictionary *feed = [db getFeedRow:n];
        [self dispRow:feed];
    }
}

但是,当我运行代码时,它只显示版本号(来自 testDatabase 方法的第 4 行),而没有其他内容。它在 xCode 控制台中显示此错误。

2014-03-21 10:00:51.052 Testbed[1381:a0b] bindSQL: could not prepare statement (no such table: main.feed) CREATE UNIQUE INDEX IF NOT EXISTS feedUrl ON feed(url)
2014-03-21 10:00:51.056 Testbed[1381:a0b] bindSQL: could not prepare statement (no such table: feed) SELECT id FROM feed ORDER BY LOWER(title)
2014-03-21 10:00:51.058 Testbed[1381:a0b] rowFromPreparedQuery: could not get row: no such table: feed

Lynda.com 讲师说,如果它只显示版本,则意味着您可能必须从模拟器中删除该应用程序,以便加载新数据,因为我们在前面的部分中创建了该应用程序的多个版本。

错误消息显示“没有这样的表:提要”,但数据库显示为已创建。你能解释为什么会这样吗? db 文件与项目不在同一个目录中,但我的理解是它不必是。

架构

-- bwrss.sql
-- by Bill Weinman - http://bw.org/contact/
-- SQLite database for BW RSS iOS app
-- Copyright 2009-2010 The BearHeart Group LLC

-- This script creates the database tables for the BW RSS application
-- and seeds the feed table with initial records. 

DROP TABLE IF EXISTS feed;
DROP TABLE IF EXISTS item;

CREATE TABLE feed (
    id      INTEGER PRIMARY KEY,    -- unique id for this record
    url     TEXT,                   -- url for data
    title   TEXT,                   -- title of the feed
    desc    TEXT,                   -- description of the feed
    pubdate TEXT,                   -- feed last update date/time
    stamp   TEXT DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE item (
    id      INTEGER PRIMARY KEY,    -- unique id for this record
    feed_id INTEGER,                -- feed id
    url     TEXT,                   -- url of item
    title   TEXT,                   -- title of the item
    desc    TEXT,                   -- description of the item
    pubdate TEXT,                   -- publication date/time of this item
    stamp   TEXT DEFAULT CURRENT_TIMESTAMP
);

CREATE UNIQUE INDEX feedUrl ON feed(url);

INSERT INTO feed (url, title, desc) VALUES (
    'http://feeds.feedburner.com/lyndablog',
    'lynda.blog',
    'the blog of lynda.com'
);

INSERT INTO feed (url, title, desc) VALUES (
    'http://feeds.feedburner.com/lyndacom-new-releases',
    'lynda.com New Releases',
    'lynda.com New Releases RSS Feed.'
);

INSERT INTO feed (url, title, desc) VALUES (
    'http://billweinman.wordpress.com/feed/',
    'Bill Weinman''s Technology Blog',
    'because it''s all about the data'
);

【问题讨论】:

    标签: ios objective-c sqlite


    【解决方案1】:

    如果我在 ios 模拟器中打开,我也会遇到同样的问题。

    2014-10-23 00:47:34.166 RSS[10465:544566] bindSQL: could not prepare statement (no such table: main.feed) CREATE UNIQUE INDEX IF NOT EXISTS feedUrl ON feed(url)
    2014-10-23 00:47:34.167 RSS[10465:544566] bindSQL: could not prepare statement (no such table: feed) SELECT id FROM feed ORDER BY LOWER(title)
    2014-10-23 00:47:34.167 RSS[10465:544566] rowFromPreparedQuery: could not get row: no such table: feed
    2014-10-23 00:47:34.167 RSS[10465:544566] bindSQL: could not prepare statement (no such table: feed) SELECT id FROM feed ORDER BY LOWER(title)
    2014-10-23 00:47:34.167 RSS[10465:544566] rowFromPreparedQuery: could not get row: no such table: feed
    2014-10-23 00:47:34.168 RSS[10465:544566] bindSQL: could not prepare statement (no such table: feed) SELECT id FROM feed ORDER BY LOWER(title)
    2014-10-23 00:47:34.168 RSS[10465:544566] rowFromPreparedQuery: could not get row: no such table: feed
    2014-10-23 00:47:34.169 RSS[10465:544566] bindSQL: could not prepare statement (no such table: feed) SELECT id FROM feed ORDER BY LOWER(title)
    2014-10-23 00:47:34.169 RSS[10465:544566] rowFromPreparedQuery: could not get row: no such table: feed
    

    但在普通设备中它可以工作

    也许这是方法中的原因:

    • BWDB.m / - (NSNumber *) insertRow:(NSDictionary *) 记录
    • BWDB.m / - (void) updateRow:(NSDictionary *) recordforRowID:(NSNumber *) rowID

    [self bindSQL:[query UTF8String] withVargs:(va_list)dValues.mutableBytes];
    

    错误:

    .../BWDB/BWDB.m:276:48: Used type 'va_list' (aka '__builtin_va_list') where arithmetic or pointer type is required
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-04
      • 2011-08-17
      • 2015-01-01
      • 1970-01-01
      • 2016-12-05
      • 2012-01-28
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多