我在sqlite中手动创建了一个名为“dept”的表,它具有用户名(如Varchar)和密码(如Integer)。如何更新目标C中SQLite数据库中的表?
我用下面的代码更新表
NSString *database2=[[NSBundle mainBundle]pathForResource:@"deptDatabase" ofType:@"sqlite"];
NSString *databasePath2=[NSString stringWithFormat:@"%@",database2];
const char *dbPath=[databasePath2 UTF8String];
if (sqlite3_open(dbPath, &dbHandler)==SQLITE_OK) {
NSLog(@"database Opened");
const char* updateQuery="update dept set password=1234 where username='suren'";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(dbHandler, updateQuery, -1, &stmt, NULL)==SQLITE_OK) {
NSLog(@"Query Executed");
}
}
sqlite3_close(dbHandler);
但表似乎没有更新。 任何人都可以请告诉我如何通过更改上面的代码来更新表。 在此先感谢
谢谢...正如你告诉mainBundle中的文件是只读的,有什么替代方法来解决我的问题。 – surendher
我编辑了我的答案来提出一种方法。将文件复制到文档目录,不要使用主包。只需使用主包中的文件作为有效负载。 – rckoenes