I try to store a array in SQLite with cordova 3.1.0 on my iPhone. The array that i try to store is encoded by json in a php file on my external server. When i get the encoded array on my phone then i try to store it in SQLite.
var JSONstring = data;
var db = window.openDatabase('DATABASE', "1.0", 'DATABASE', 1000000);
db.transaction(populateDB, errorCB, successCB);
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DATABASE');
tx.executeSql('CREATE TABLE IF NOT EXISTS DATABASE (id unique, data)');
tx.executeSql('INSERT INTO DATABASE (id, data) VALUES (1, '+JSONstring+')');
}
function errorCB(tx, err) {
alert("Error processing SQL: "+err);
}
function successCB() {
alert("success!");
}
The var JSONstring is the encoded array that i get from my server. But for some reason does my iphone say 'Error processing SQL: undefined'.
I guess you'll have to quote the string:
tx.executeSql('INSERT INTO DATABASE (id, data) VALUES (1, \''+JSONstring+'\')');
provided JSONstring
itself doesn't contain any quotes, otherwise you need to double them ( http://www.sqlite.org/faq.html#q14 ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.