webSql选择查询错误

时间:2014-08-04 18:01:17

标签: android cordova

在使用PhoneGap for Android进行开发时,我试图将数据存储在数据库中并想要检索它,并且在选择查询期间我遇到错误:.code将为零,.message 1}}将是"the statement callback raised an exception or statement error callback did not return false"。有时messagecode都未定义。

在下面的代码中,我提到了我收到错误的地方。否则一切正常。我认为我的usy回调函数我解决了同步问题,所以请想一些语法错误。有时它会调用我的成功方法,并且显示长度不是未定义的。

$scope.data_for_net=function(check){
//var db = window.openDatabase("JiyoNatural", "1.0", "JiyoNatural", 200000);
    var today=new Date();

     var dd=today.getDate();

     var mm=today.getMonth()+1;

     var yyyy=today.getFullYear();

     if(dd<10) {

         dd='0'+dd;

     } 

    if(mm<10) {

        mm='0'+mm;

        } 

     today = yyyy+'-'+mm+'-'+dd;    

      todayDate=today.toString();


    db.transaction(function(tx){



            var query='SELECT * FROM Recipe WHERE Recipe_Date=?,Recipe_meal_Type=?';


            //var sql_query='select * from Recipe where Recipe_Date="'+todayDate+'" and Recipe_meal_Type="+Lunch"'

            // tx.executeSql('select * from Recipe where Recipe_Date=?,Recipe_meal_Type=?;', [todayDate]["Lunch"], $scope.query_data_fatch_for_lunch, $scope.transaction_error);//here i am getting error

             tx.executeSql(query, [todayDate],['Lunch'], $scope.query_data_fatch_for_lunch, $scope.transaction_error);

         });
   }

    }   

//this is my method

$scope.query_data_fatch_for_lunch=function(tx,result){

console.log("data_fatch_for_lunch is calling");

var RecipeInfo=[];

var recipe={};

var rowData=[];

for(var i=0;i<result.rows.length;i++){

    var meal_type=result.rows.item(i).Recipe_meal_Type;

    var recipe_item=result.rows.item(i).Recipe_Name;

    console.log(recipe_item);

    var energy=result.rows.item(i).Recipe_energy;

    var carbohydrate=result.rows.item(i).Recipe_corbohydrates;

    var protein=result.rows.item(i).Recipe_protein;

    var fat=result.rows.item(i).Recipe_fat;

    rowdata.push(recipe_item);

    rowdata.push(energy);

    rowdata.push(carbohydrate);

    rowdata.push(protein);

    rowdata.push(fat);

    console.log("data is successfull add");

}

recipe.itemInfo=rowdata;

recipe.itemType=meal_type;

RecipeInfo.push(recipe);

}   

1 个答案:

答案 0 :(得分:1)

我觉得你很接近,虽然我还没有彻底测试上面的代码...... 但是tx.executeSql(query, [todayDate],['Lunch'], $scope.query_data_fatch_for_lunch, $scope.transaction_error);线看起来有点奇怪。

您可以用 [todayDate,&#39; Lunch&#39;] 替换[todayDate],['Lunch']吗? 因为这是参数的工作方式。