HimanshuBhatt
HimanshuBhatt

Reputation: 1

webSql select query error

In developing in PhoneGap for Android, I'm trying to store data in database and want to retrieve it, and during the select query I am getting errors: the .code will be zero and the .message will be "the statement callback raised an exception or statement error callback did not return false". Sometimes both message and code are undefined.

In my code below I am mentioning where I am getting error. Otherwise all is working fine. I think my usy call back function I solved the synchronous problem so please I think some syntax error. Sometimes it calls my success method and there it shows length is not undefined.

$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);

}   

Upvotes: 0

Views: 139

Answers (1)

Dick van den Brink
Dick van den Brink

Reputation: 14499

I think you are pretty close although I haven't tested the above code very thoroughly... But tx.executeSql(query, [todayDate],['Lunch'], $scope.query_data_fatch_for_lunch, $scope.transaction_error); line seems a bit weird.

Can you replace [todayDate],['Lunch'] with [todayDate, 'Lunch']? Because that is the way the parameters work.

Upvotes: 1

Related Questions