我创建了我的表并使用firefox sqlite管理器扩展插入了我的数据,保存并添加了我的sqlitefile,它是“notifications.sqlite”,之后我编写了此代码,但它会输出我没有什么。如何使用firefox插件创建.sqlite文件
打开.sqlite文件和.db文件有什么不同吗?我怎样才能正常打开我的数据库?
* UPDATE: *调试完毕后作为朋友评论它在这条线的问题:
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"notifications.sqlite"]];
后
if ([filemgr fileExistsAtPath: databasePath ] == YES)
如果不是YES这样就失去了一切,所以databasePath有点问题
我的表如下:
CREATE TABLE "quotes_type" ("type_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "content" VARCHAR)
,这里是我的努力打开.sqlite文件:
- (void)viewDidLoad{
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"notifications.sqlite"]];
sqlite3_stmt *statement;
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: databasePath ] == YES)
{
if (sqlite3_open([databasePath UTF8String], &contactDB) == SQLITE_OK)
{
NSString *qrycount = [NSString stringWithFormat: @"select * from quotes_type"];
const char *count_stmt = [qrycount UTF8String];
sqlite3_prepare_v2(contactDB, count_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_ERROR) {
NSAssert1(0,@"Error when selecting rows %s",sqlite3_errmsg(contactDB));
} else {
NSLog(@"negin");
int myid=sqlite3_column_int(statement, 0);
NSString *text = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,1)];
NSLog(@"myid is %d",myid);
NSLog(@"text is %@",text);
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
}
else NSLog(@"openning has problem");
}
}
你使用调试器来检查哪些说法究竟失败?为什么不使用'sqlite3_errmsg()'来报告错误信息而不是“打开有问题”? – 2013-04-07 14:36:51
我曾经使用它,它会去打开语句问题是在sqlite_open之后的某处,因为我没有任何nslog输出 – Nickool 2013-04-07 14:40:23
我编辑了我的问题,但同时它似乎有人正在编辑我,我失去了我我appologize – Nickool 2013-04-07 14:44:38