last day (14 days later) » 

3:37 PM
0
A: Phonegap: insert query sqlite when login success

ankit gargWhere are u calling this piece of code from? function insertDB(tx,val){ for (var i = kode.length - 1; i >= 0; i--) { tx.executeSql('INSERT INTO konfirmasi VALUES ('+a[i]+');',querySuccess,errorCB); }; } If you are calling it from a transaction, t...

 
thanks for the advise. I heve changed my code. Can you take a look at it again? Because when it's running function insertDB(), dropDB(), and selectData(), it's always logging error result.
 
What is the error message? You can capture the error message by calling error.message in the failure callback
Moreover, code is still wrong. insertDB function will be called with only tx argument and not with the two arguments that you have put inside the function
 
i already change function insertDB(tx,kode) to function insertDB(tx). is that right? And the error message when i login is >I/Web Console(16766): Error processing SQL: 0 at file:///android_asset/www/js/database.js:18". Btw i run it with cordova cli, so i track it with adb logcat. It is log from errorCB().
 
can u please post the updated code here
 
i just change function insertDB(tx, kode) in database.js to function insertDB(tx);. should i change the call function insertDB(); in main,js too?
 
3:37 PM
i am assuming that you are calling insertDB function from this statement: function queryDB(){ db.transaction(insertDB,errorCB,querySuccess); } The second argument of db.transaction is a success function and third argument is a failure function. Make the following change to this query: function queryDB(){ db.transaction(insertDB,querySuccess,errorCB); }. It would be fine after this change I guess
Sorry my bad! please change the query to following: function queryDB(){ db.transaction(insertDB,errorCB); }. db.transaction takes only two arguments, not three.
 
if i do so, what about the success statement? actually i wanna try this db.transaction(insertDB,selectData,errorCB); in queryDB() to check if it is success.
 
DB transaction has two arguments and tx statements have three arguments. if a transaction hasn't failed, it's a success by default.
can you get into the chat mode?
 
great
did u make the changes i proposed?
 
yeah, but if i look at this api: cordova.apache.org/docs/en/3.0.0/…, i can use success statement in db transaction.
 
3:49 PM
ohh, you are right, but success is not required
we primarily use ng-cordova api in our cordova application for sqlite plugin
anyways, are u calling this function from the main.js too?
 
what function?
 
are u calling queryDB() or insertDB() function from main.js?
 
yeah, i call queryDB() in main.js.
 
okkie
change errorCB function to :function errorCB(err) {
console.log("Error processing SQL: "+err.message);
}
err.code to err.message
letr me know what exactly u get in this case
 
this is the result when the app is starting.
 
3:57 PM
Ohh..
 
actually there are too many issues in our code
 
i cant copy it from cmd
 
on mac or windows?
 
what is that?
windows
 
3:58 PM
okkie.. just select the message on cmd and press enter
it gets copied
 
I/Web Console(31011): Error processing SQL: a statement with no error handler fa
iled: [1] DB[1] prepare() CREATE TABLE IF NOT EXISTS data_konfirmasi (kode_trans
aksi text, status text) UNIQUE(kode_transaksi) [near "UNIQUE": syntax error] at
file:///android_asset/www/js/database.js:19
 
okkie
gimme a min
this ql is wrong
CREATE TABLE IF NOT EXISTS data_konfirmasi (kode_transaksi text, status text) UNIQUE(kode_transaksi)
 
change it to
CREATE TABLE IF NOT EXISTS data_konfirmasi (kode_transaksi text UNIQUE, status text)
and re-run the code
 
what is wrong?
 
4:03 PM
i think the sqlite syntax issue is there
try the query i sent you and re-run
 
yes. it's work.
 
great
 
now i get this when login: I/Web Console( 1399): Error processing SQL: Cannot read property 'length' of undefined at file:///android_asset/www/js/database.js:19
 
please accept my answer :)
lemme see
 
in chat?
i did it in question window.
 
4:09 PM
got the issue
var kode = JSON.parse(window.localStorage['konfirmasi']);
this statement is also getting failed
 
why?
it's work at main.js
 
where are u setting this variable?
window.localStorage['konfirmasi']
 
i set it in database.js like this: var kode = JSON.parse(window.localStorage['konfirmasi']);
 
you are settting "Kode" in database.js file
where are u setting "window.localStorage['konfirmasi']" variable value?
 
in main.js
 
4:14 PM
send me the piece of code through which u r setting it.
and are u doing it before making the database call or after making the database call?
 
window.localStorage.setItem('konfirmasi', JSON.stringify(result.data));
you can see the detail in question window
 
try window.localStorage.getItem('konfirmasi') in database.js file
and are u sure that result.data value is not null or undefined?
and are u doing it before making the database call or after making the database call?
 
when i try it in browser the log is like this
Kode: ["52bsw", "uvo9b", "hte3r"]
Array length: 3
 
alert it in database.js just above the var kode = JSON.parse(window.localStorage['konfirmasi']); line
do this:
alert()
alert(window.localStorage['konfirmasi']); just above "var kode = JSON.parse(window.localStorage['konfirmasi'])" line
 
alert or console.log?
 
4:27 PM
anything would be ok
do both
 
the result is array
but i code like this: alert(json.parse(window.localStorage.getItem('konfirmasi')));
 
okki
do this:
before the for loop, and inside the function.. do this alert: alert(kode.length);
function insertDB(tx){
for (var i = kode.length - 1; i >= 0; i--) {
tx.executeSql("INSERT INTO data_konfirmasi VALUES ("+kode[i]+", 'Belum Terkirim');");
};
}
 
i see.
i think it's because of logout button.
i clear localstorage when i logout.
so when the app closed after logout it alerts null
because the localstorage is null
 

last day (14 days later) »