我想知道为什么我只能在 iphone 上读取我的 Sqlite 数据库但不能写任何东西......在模拟器上一切正常......
是否有任何配置来设置权限或什么?
PS:当我更新或插入sqlite(从设备)时没有错误。
这是我的代码(打开 sqlite):
- (id)init {
if ((self = [super init])) {
NSString *sqLiteDb = [[NSBundle mainBundle] pathForResource:@"test"
ofType:@"sqlite"];
if (sqlite3_open([sqLiteDb UTF8String], &_database) != SQLITE_OK) {
NSLog(@"Failed to open database!");
}
}
return self;
}
@end
和我的“更新”代码:
-(void)addCoin:(int)score
{
NSString *query = @"select coin_user from user where id_user = '1'";
//query = @"SELECT id_soal FROM soal where jawaban_soal = 'romin'";
sqlite3_stmt *statement;
int total;
if (sqlite3_prepare(_database, [query UTF8String], -1, &statement, nil)
== SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
total = sqlite3_column_int(statement, 0);
}
sqlite3_finalize(statement);
}
query = [NSString stringWithFormat:@"update user set coin_user = '%i' where id_user = '1'",total + score];
if (sqlite3_prepare(_database, [query UTF8String], -1, &statement, nil)
== SQLITE_OK) {
sqlite3_step(statement);
sqlite3_finalize(statement);
}
}