退出App后的Phonegap drop database

时间:2011-12-16 12:28:07

标签: sqlite cordova

我在我的应用程序上使用来自phonegap(1.2)的SQLite函数,在退出应用程序并重新启动它之后,我之前存储到数据库的所有数据都消失了。如何防止丢失数据以及应用程序存储在设备(Android,iPhone)上的位置。

创建表:

function favouritesInit(transaction){
    transaction.executeSql('CREATE TABLE IF NOT EXISTS FAVOURITES (id INTEGER PRIMARY KEY, lat, ln, title, cont)');
}

插入:

var statement = 'INSERT INTO FAVOURITES (lat, ln, title, cont) values('+the_fav.getPosition().lat()+', '+the_fav.getPosition().lng()+', '+the_fav.getTitle()+', '+content+')';
    transaction.executeSql(statement);

感谢

2 个答案:

答案 0 :(得分:1)

您应确保问题是关闭应用程序后数据库已被删除。在我看来,只是数据没有插入数据库。使用你传递的代码,我只能猜测,但如果我是你,我会运行一个事务,在插入数据后立即从数据库中读取数据,以确保它真正进入数据库。

答案 1 :(得分:0)

The problem is that your not passing a value for the primary key. Your table has an id as primary key, and because of that it can't be null. The only exception is when you declare the id as 'AUTOINCREMENT': in that case, if you don't pass a primary key value, the database will assign the next available value from a sequence table created for that purpose. Hope this helps: https://www.sqlite.org/autoinc.html Cheers!