0

您好,我正在使用 FMDB 来使用 SQLite 数据库。我有下一个代码:

FMDatabase *db = [FMDatabase databaseWithPath:@"stories_db.sqlite"];
[db open];
FMResultSet *resultsFavorite = [db executeQuery:@"SELECT * from favorites"];

但是 [db open] 上显示错误;

2013-10-23 11:08:22.951 Pasakas [1013:a0b] 错误打开!:14

在此处输入图像描述

也许我应该改变路径?

4

1 回答 1

1

您必须提供数据库的路径而不是数据库的名称,

尝试

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *path = [docsPath stringByAppendingPathComponent:@"stories_db.sqlite"];

FMDatabase *db = [FMDatabase databaseWithPath:path];
[db open];
FMResultSet *resultsFavorite = [db executeQuery:@"SELECT * from favorites"];
于 2013-10-23T08:18:11.300 回答