I have a sqlite db and i want to insert row in it . I used this code .
-(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);
}
and it's log : data inserted .
When i do this :
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 is null .
ANy ideea what is happening ? Any help will be appreciate . Thanks.
Aucun commentaire:
Enregistrer un commentaire