I think i have everything working except getting the data to display. I get rows to return, but instead of displaying data I get “undefined” for every row of data. So if I run a query that returns 25 rows of data I get 25 rows but the actual data is not showing instead I get “undefined” in every column and every row. I get the right amount of rows returned but I must have missed something to get the data to display properly.
Look in the example code that I used before in my comment
db.transaction(function(tx) {
// running a sql querie
tx.executeSql("SELECT name, lastname FROM your_table_name ORDER BY name ASC", [], function(tx, res) {
var len = res.rows.length;
for (var i = 0; i < len; i++) { // loop as many times as there are row results
alert( res.rows.item(i).name +' '+ res.rows.item(i).lastname ); // showing the results
}
}, function(e) {
alert("ERROR: " + e.message);
});
});
- You do a sql querie, in the example to get the
"name"
and"lastname"
columns of the"your_table_name"
table and order by"name"
in ascendent
tx.executeSql("SELECT name, lastname FROM your_table_name ORDER BY name ASC", [], function(tx, res) {..............................})
- To show the data in the
"name"
and"lastname"
columns of each row you should use the reference of each column in a cycle
for (var i = 0; i < len; i++) {
alert( res.rows.item(i).name +' '+ res.rows.item(i).lastname );
}
Where "i"
is the iterator to reference the specific row as a result and the ".name"
and ".lastname"
are the data that you want to get.
I hope this can help.
Thanks
Hi @shubs,
If you’re still having trouble with pre-filled databases, you can check out a tutorial I did on the subject.
Hopefully that helps you out.
Regards,
Nevermind I fixed it. Wasn’t working because the column name I was querying had the name is all uppercase. Once I changed that in my query all is well. Thanks!
If you are having issues submitting to the App store with regards the policies surrounding what data you are allowed where please refer to my post in the link posted above by @nicraboy.
How I can sync data from my sqlite mobile with remote json?
Hi,
I had the same problem, and been looking for answers and almost all answers points out to use copy and stuff like that.
finally I got it working, I debugged the $cordovasqlite plugin, and found that it doesn’t support createFromLocation params.
So, here is the solution: use window.sqlitePlugin.opendatabase instead of window.openDB! simple
Check this article: http://redwanhilali.com/ionic-sqlite/
Is very easy with SQLite (Tested with pre-filled databases with 25000 records) https://github.com/jdnichollsc/Ionic-Starter-Template
Regards, Nicholls
You plagiarized a significant amount of your article from my article. If you’re going to copy chunks of my article you need to link back to mine and give the appropriate credit.
Regards,