【发布时间】: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