2

I am using cordova + angular js for developing the mobile app. For creating this POC I am using this SQL tutorial. Now I want to fetch tables name from sqllite db. for this I write below code.

        vm.tableName = function(){
        var query = "SELECT * FROM sqlite_master WHERE type=?";
        $cordovaSQLite.execute(db, query, ['table']).then(function(res) {
            alert("res "+JSON.stringify(res));
        }, function (err) {
            alert("err "+JSON.stringify(err));
        });
    }

I can successfully read and write data in db, but I can't fetch the table names. I think, I miss something, but I get related answer but it not work for me link. And I don't understand how to attach db. I get some response from db when I run the above code.

enter image description here

Community
  • 1
  • 1
RahulSalvikar
  • 658
  • 1
  • 10
  • 31

2 Answers2

2

I use this query for fetch all the tables from database. SELECT tbl_name FROM sqlite_master WHERE type = 'table';. It works for both android and ios but in android it gives one extra table "android_metadata". for this I use below code

for (var i = 0; i < res.rows.length; i++) {
    if (res.rows.item(i).tbl_name !== "android_metadata") 
       ARRAYNAME.push(res.rows.item(i).tbl_name);}
RahulSalvikar
  • 658
  • 1
  • 10
  • 31
0

Try this query

SELECT * FROM sqlite_master WHERE type='table'

Above Query should return following columns

Mox Shah
  • 2,967
  • 2
  • 26
  • 42