帮助,而不是在SQlite中进行UPDATE工作。执行查询但不会发生更改
const char *dbPath=[databasePath UTF8String];
if (sqlite3_open(dbPath, &contactDB)==SQLITE_OK) {
NSLog(@"database Opened");
const char* updateQuery="update poi set test=\"111\"";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(contactDB, updateQuery, -1, &stmt, NULL)==SQLITE_OK) {
NSLog(@"Query Executed");
}
}
sqlite3_close(contactDB);
答案 0 :(得分:0)
您尚未执行查询:
sqlite3_prepare_v2
- 准备好不执行(影响),你需要执行它
试试这个:
const char *dbPath=[databasePath UTF8String];
if (sqlite3_open(dbPath, &contactDB)==SQLITE_OK) {
NSLog(@"database Opened");
const char* updateQuery="update poi set test=\"111\"";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(contactDB, updateQuery, -1, &stmt, NULL)==SQLITE_OK) {
NSLog(@"Query Prepared to execute");
}
if(sqlite3_step(stmt) != SQLITE_DONE){
NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
}else
NSLog(@"Executed");
sqlite3_close(contactDB);
}
答案 1 :(得分:0)
sqlite3_step(statement);
这里发生了什么,你只是准备声明而不是执行它..
sqlite3_stmt *statement;
if(sqlite3_open(dbpath, &database_object) == SQLITE_OK)
{
NSString *sql = [NSString stringWithFormat:@"update table_name set column_name = \"%@\"", Your_value];
const char *sql_stmt = [sql UTF8String];
if(sqlite3_prepare_v2(database_object , sql_stmt, -1, &statement, NULL) != SQLITE_OK)
NSLog(@"Error while creating update statement. '%s'", sqlite3_errmsg(database_object));
if(SQLITE_DONE != sqlite3_step(statement))
NSLog(@"Error while updating. '%s'", sqlite3_errmsg(database_object));
sqlite3_finalize(statement);
}
在您的代码中进行这些更改并尝试,我认为它会起作用...