Konobi
Konobi

Reputation: 401

Phonegap drop database after quitting the App

i'm using the SQLite function from phonegap(1.2) on my app, and after quitting the application and restarting it, all data that i previously stored to the database is gone. how can i prevent loosing the data and where is the application stored on the device(Android, iPhone).

Create Table:

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

Insert:

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);

thanks

Upvotes: 0

Views: 556

Answers (2)

Johnz
Johnz

Reputation: 114

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!

Upvotes: 0

user1173719
user1173719

Reputation: 11

You should make sure the problem is that the database is dropped once you close your application. It seems to me that it is just that the data is not getting into the database with your insert. With that code you passed, I can only guess, but if I were you I would run a transaction to read the data from the database right after inserting it just to make sure it actually makes its way to the database.

Upvotes: 1

Related Questions