SQLite insert works in simulator but not on device

三世轮回 提交于 2019-12-31 04:03:16

问题


Here is SQLite code which I call and pass one variable. Where is problem?

-(IBAction)insertPet:(NSString *) name{

NSString *query = [NSString stringWithFormat:@"Insert into pet (name) values ('%@');", name];
sqlite3_stmt *statement;

NSLog(@"1 - %@",query);

if(sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil)==SQLITE_OK)
{

    NSLog(@"2 - %@",query);

    if(SQLITE_DONE == sqlite3_step(statement)){

        NSLog(@"Query - %@",query);
    }
    sqlite3_finalize(statement);
}
}

回答1:


My guess is that your database is placed in the application bundle. If that's the case, you will have to create a writable copy of your database to be able to perform queries that change the database (like INSERT or UPDATE). The most popular way of doing so is to copy the database from the bundle to the Documents folder.




回答2:


What worked for me was deleting the app from your device,restart the device,clean the app in Xcode then load it again,also check that Target Membership is selected on the database.



来源:https://stackoverflow.com/questions/9261601/sqlite-insert-works-in-simulator-but-not-on-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!