我尝试从sqlite中检索数据。不幸的是,该表填充了空值。
控制台显示FIRST ID RECUPERÉ : (null)
。你能告诉我你的意见吗?
这是代码:
NSString * statementID = [NSString stringWithFormat:@"SELECT id_message FROM messages;"];
const char * sql_stmt_id = [statementID UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(contactDB, sql_stmt_id, -1, &compiledStatement, NULL) == SQLITE_OK)
{
[tableauMsgReceived removeAllObjects];
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
[tableauMsgReceived addObject:[NSString stringWithFormat:@"%s",(char *) sqlite3_column_text(compiledStatement, 0)]];
NSLog(@"First ID : %@", [tableauMsgReceived objectAtIndex:0]);
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(contactDB);
答案 0 :(得分:0)
如果NSLog
为tableauMsgReceived
,则nil
语句将为您的代码提供结果的唯一方式。
你需要做的地方:
tableauMsgReceived = [[NSMutableArray alloc] init];
答案 1 :(得分:0)
首先,确保你做过像
这样的事情tableauMsgReceived = [[NSMutableArray alloc] init];
然后,检查数据库是否成功打开
if (sqlite3_open([YourDBPath UTF8String], &yourDatabase) == SQLITE_OK){}
最后一件事,也许你可以试试
[tableauMsgReceived addObject:[NSString stringWithUTF8String:(const char *)sqlite3_column_text(statement, 0)]];