应用程序重启后,Sqlite插入会丢失 [英] Sqlite inserts get lost after app restart

查看:184
本文介绍了应用程序重启后,Sqlite插入会丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是插入代码。它工作正常,直到我关闭应用程序并再次启动它,然后所有更改都消失了。我没有看到任何错误,可能是某些特定于iPhone的问题吗?

This is the insert code. It works fine until i close the app and start it again, then all changes are gone. I don't see any error, could it be some iphone specific issue?

const char *sql = "INSERT INTO offers "
                  "(OfferId, AddressId, ShortDescription, LongDescription, TimeStart, TimeEnd, Created, LastEdit) "
                  " VALUES (?, ?, ?, ?, ?, ?, ?, ?)";


sqlite3_stmt *stmt;
int returnValue = sqlite3_prepare(db, sql, -1, &stmt, NULL);
if(returnValue == SQLITE_OK) {
    for(NSDictionary *offer in offers) {
        sqlite3_bind_int(stmt, 1, [[offer valueForKey:@"OfferId"] intValue]);
        sqlite3_bind_int(stmt, 2, [[offer valueForKey:@"AddressId"] intValue]);
        sqlite3_bind_text(stmt, 3, [[offer valueForKey:@"ShortDescription"] UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(stmt, 4, [[offer valueForKey:@"LongDescription"] UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_int(stmt, 5, [[offer valueForKey:@"TimeStart"] intValue]);
        sqlite3_bind_int(stmt, 6, [[offer valueForKey:@"TimeEnd"] intValue]);
        sqlite3_bind_int(stmt, 7, [[offer valueForKey:@"Created"] intValue]);
        sqlite3_bind_int(stmt, 8, [[offer valueForKey:@"LastEdit"] intValue]);

        if(sqlite3_step(stmt) != SQLITE_DONE)
            NSLog(@"instertOffers -> sql-error: %s", sqlite3_errmsg(db));
        else
            NSLog(@"added offer with id: %@", [offer valueForKey:@"OfferId"]);

        sqlite3_reset(stmt);
    }
} else {
    NSLog(@"instertOffers -> sql-error: %s", sqlite3_errmsg(db));
}

sqlite3_finalize(stmt);
sqlite3_close(db);


推荐答案

AppBundle中是否有SQLite数据库文件,如果是这样的话如果要进行更改,则需要将其复制到文档目录。
您无法写入应用包中的任何文件。

Is the SQLite database file in the AppBundle, if so you will need to copy it to the document directory if you want to make changes. You can't write to any files in your app bundle.

这篇关于应用程序重启后,Sqlite插入会丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆