Ios 无法使用FMDB读取数据
我用的是FMDB。我创建并插入到表中。它很好用 idx INTEGER非空默认0主键自动递增 topicId Varchar不为空 listChat BLOB不为空 但我无法从listChat中获取所有数据。这是我的密码: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
- (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。检查上面的代码