Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法使用FMDB读取数据_Ios_Sqlite_Fmdb - Fatal编程技术网

Ios 无法使用FMDB读取数据

Ios 无法使用FMDB读取数据,ios,sqlite,fmdb,Ios,Sqlite,Fmdb,我用的是FMDB。我创建并插入到表中。它很好用 idx INTEGER非空默认0主键自动递增 topicId Varchar不为空 listChat BLOB不为空 但我无法从listChat中获取所有数据。这是我的密码: - (NSMutableArray*)readChatHistoryFromDatabaseWithTopicId:(NSString *)topicId { NSMutableArray *listChat = [[NSMutableArray alloc] ini

我用的是FMDB。我创建并插入到表中。它很好用

idx INTEGER非空默认0主键自动递增

topicId Varchar不为空

listChat BLOB不为空

但我无法从listChat中获取所有数据。这是我的密码:

- (NSMutableArray*)readChatHistoryFromDatabaseWithTopicId:(NSString *)topicId {
    NSMutableArray *listChat = [[NSMutableArray alloc] init];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *path = [self databasePath];
    if ([fileManager fileExistsAtPath:path] == YES) {
        FMDatabase *database = [FMDatabase databaseWithPath:path];
        if (database) {
            [database open];
            NSString *query = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE topicId=\"%@\"", OCSDK_CHAT_HISTORY_TABLE_NAME, topicId];
            FMResultSet *results = [database executeQuery:query];
            [results next];
            NSData *notesData = [results dataForColumn:@"listChat"];
            [listChat addObject:notesData];
            NSLog(@"notes: %@", listChat);
        }
        [database close];
    }
    return listChat;
}
它打印:

我的代码有什么问题?

更改代码:

- (NSMutableArray*)readChatHistoryFromDatabaseWithTopicId:(NSString *)topicId {
    NSMutableArray *listChat = [[NSMutableArray alloc] init];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *path = [self databasePath];
    if ([fileManager fileExistsAtPath:path] == YES) {
        FMDatabase *database = [FMDatabase databaseWithPath:path];
        if (database) {
            [database open];
            NSString *query = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE topicId=\"%@\"", OCSDK_CHAT_HISTORY_TABLE_NAME, topicId];
            FMResultSet *results = [database executeQuery:query];
            while([results next]) {

              NSString *noteString = [results stringForColumn:@"topicId"]
              [listChat addObject: noteString];
              NSLog(@"notes: %@", listChat);
          }
        }
        [database close];
    }
    return listChat;
}
您正在从数据库中获取密钥topicId的NSData值。您需要取回NSStringvalue。检查上面的代码