简体   繁体   English

sqlova中的cordova存储数组

[英]Cordova store array in sqlite javascript

I try to store a array in SQLite with cordova 3.1.0 on my iPhone. 我尝试在iPhone上使用cordova 3.1.0在SQLite中存储数组。 The array that i try to store is encoded by json in a php file on my external server. 我尝试存储的数组由json编码在我的外部服务器上的php文件中。 When i get the encoded array on my phone then i try to store it in SQLite. 当我在手机上获取编码数组时,我尝试将其存储在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. var JSONstring是我从服务器获取的编码数组。 But for some reason does my iphone say 'Error processing SQL: undefined'. 但是由于某种原因,我的iPhone会说“错误处理SQL:未定义”。

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 ). 提供的JSONstring本身不包含任何引号,否则您需要将它们加倍( http://www.sqlite.org/faq.html#q14 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM