Search code examples
titaniumappceleratortitanium-mobileappcelerator-mobile

Titanium: How to check Table is exists or not in Database?


How can I check weather specific table does exists or not in my database before execute query ?

Example : I want to check weather Detail table exists or not in InfoDB

I want to do some thing like :-

var createDB = Titanium.Database.open('InfoDB');
if(Detail exists in InfoDB)
  then
    var rs = createDB.execute('SELECT * FROM Detail');

Thanks...


Solution

  • Try this:

    var createDB = Titanium.Database.open('InfoDB');
    
    var result = createDB.execute('SELECT name FROM sqlite_master WHERE type="table" AND name="your table name"');
    
    if(result.isValidRow()) {
        //table found
       var rs = createDB.execute('SELECT * FROM Detail');
     }
     result.close();