Phonegap在查询功能上传递参数。存储API

时间:2012-11-28 02:50:06

标签: android jquery cordova

我正在使用phonegap包装的android应用程序,我正在使用它的Storage API。如何在我的Sqlite Query上传递一个参数来获取特定的行?提前致谢。下面是我的脚本。你能举个例子吗?感谢

$(document).ready(function() {  

            code        = 1;

            var db = window.openDatabase("DEMO", "1.0", "DEMOX", 20000000 ); // 20MB in quuota storage size
                db.transaction(function(){ queryDB(code) }, errorCB, querySuccess);

             function querySuccess(tx, results) {
                 console.log("Returned rows = " + results.rows.length);
                 // this will be true since it was a select statement and so rowsAffected was 0
                 if (!resultSet.rowsAffected) {
                     alert('No rows affected!');
                   return false;
                 }
             }


            function queryDB(tx, code) {
                 tx.executeSql('SELECT * FROM table WHERE code = ?', [code], querySuccess, errorCB);
            }

            function errorCB(err) {
                 console.log("Error processing SQL: "+err.code);
            }
        });

1 个答案:

答案 0 :(得分:0)

我的解决方案:希望这会有所帮助。

$(document).ready(function() {  

        code        = 1;

        var db = window.openDatabase("DEMO", "1.0", "DEMOX", 20000000 ); // 20MB in quuota storage size
            db.transaction(queryDB, errorCB, querySuccess);

         function querySuccess(tx, results) {
             console.log("Returned rows = " + results.rows.length);
             // this will be true since it was a select statement and so rowsAffected was 0
             if (!resultSet.rowsAffected) {
                 alert('No rows affected!');
               return false;
             }
         }


        function queryDB(tx) {
             var sql = 'SELECT * FROM table WHERE code = :code'; 
             tx.executeSql(sql, [code], querySuccess, errorCB);
        }

        function errorCB(err) {
             console.log("Error processing SQL: "+err.code);
        }
    });