我有一个sqlite数据库,我想在其中插入行。我用过这段代码。
-(void)InsertRecords{
NSString *insertSQL = [NSString stringWithFormat:
@"INSERT INTO notes (id, title, content,dataAdd,category) VALUES (\"%@\", \"%@\", \"%@\" ,\"%@\",\"%@\")",
@"1",
@"mountain",
@"Prahova",
@"12.09.2019",
@"public"];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_stmt *updateStmt = nil;
sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
if(sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL) == SQLITE_OK){
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(@"data inserted");
}
else{
NSLog(@"Error while creating update statement. '%s'", sqlite3_errmsg(contactDB));
}
}
else{
NSLog(@"Error while creating update statement. '%s'", sqlite3_errmsg(contactDB));
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
并且它是日志:已插入数据。
当我这样做时:
querySQL1 = @"select id from notes where category LIKE 'public'";
const char *query_stmt = [querySQL1 UTF8String];
sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL);
NSString *idNr;
while (sqlite3_step(statement) == SQLITE_ROW)
{
idNr =[[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(statement, 0)];
}
NSLog(@"%@",idNr);
idNr为空。
ANy ideea发生了什么?任何帮助将不胜感激。感谢。