I have a simple program that updates table records
table is "person" Two columns "Name" and "Age"; Some records are inserted as follows:
name age 20 andy 30 han 25 Now I write a program to update a line Table:
NSString * database = [[NSBundle main bundle] PathfureResource: @ "mytable" type: @ "sqlite"]; Sqlite3_open ([database UTF8String], and contact DB); NSString * text = @ "Andy"; NSString * query = [NSString stringWithFormat: @ "Updated person SET age =% d WHERE name = '% @'", 30, lesson]; Sqlite3_stmt * statement; Sqlite3_prepare_v2 (contact db, [query utf 8 string], - 1, and statement, zero); Sqlite3_finalize (statement); Sqlite3_close (contactDB); This program works fine, but the database is not updated (I am using the SQLite manager for the database browser)
When I read from the database I try, it works well:
NSString * database = [[NSBundle main bundle] Pathfoser resource: @ "mytable" type: @ "sqlite"]; Sqlite3_open ([database UTF8String], and contact DB); NSString * query1 = [NSString stringWithFormat: @ "Select * from person to age =% d;", 30]; Sqlite3_stmt * statement; Sqlite3_prepare_v2 (Contact DB, [query 1 UTF 8 string], - 1, and statement, null); Sqlite3_step (statement); NSString * Result = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text (statement, 0)]; Label.text = results; Sqlite3_finalize (statement); Sqlite3_close (contactDB);
- (zero) updateSetting: (NSArray *) arr {if ( Sqlite3_open ([databasePath UTF8String], and myDatabase) == SQLITE_OK) {sqlite3_stmt * compiledStmt; NSString * sqlStmt = [NSString stringWithFormat: @ "Set up settings SET flow = '% @' formate = '% @' where primary key =% i;", [arr ObjectEntindexX: 0], [arr ObjectAntindexX: 1], 1 ]; If (sqlite3_prepare_v2 (myDatabase, [sqlStmt UTF8String], - 1, and compiled Stmt, NULL) == SQLITE_OK) {NSLog (@ "Successful Update"); } Sqlite3_step (compiled Stmt); Sqlite3_close (myDatabase); }}
Comments
Post a Comment