我正在尝试从我的文档目录中打开 sqlite 数据库:
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *dbFileName = [docDir stringByAppendingPathComponent:@"DatabaseName.sqlite"];
self.db = [FMDatabase databaseWithPath:dbFileName];
self.db.logsErrors = YES;
self.db = _db;
if ([self.db open]) {
NSLog(@"database opened");
}
NSLog(@"docDir = %@",[NSString stringWithFormat:@"%@%@",docDir,dbFileName]);
NSLog 显示奇怪的路径docDir
=/Users/userName/Documents/Users/userName/Documents/DatabaseName.sqlite
而不是/Users/userName/Documents/DatabaseName.sqlite
. 打开时没有错误或警告。
在此之后,我尝试从我的表中获取 count(*)
NSString *queryString = [NSString stringWithFormat:@"SELECT count(*) FROM histories"];
FMResultSet *result = [self.db executeQuery:queryString];
NSLog(@"count = %i", [result intForColumnIndex:0]);
当 10k 行时数据库有更多,但 NSLog 显示为 0。应用程序不适用于 iOS,仅适用于命令行。我在哪里可以找到问题?