1

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

$(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);
            }
        });
4

1 回答 1

0

My solution : hope this will help others.

$(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);
        }
    });
于 2012-11-28T04:05:23.653 回答