Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Check Table Exist or not in Suger ORM Android

I am working on Android Application and i am using Suger ORM for my database operation. Now i have scenario where i have to check if "SomeTable" don't exist then create it and Insert the record and if table already exist and having some record i have to update the records. I have write this code to check if table don't exist then create the record and save it.

Total_Budget_List = Total_Budget.listAll(Total_Budget.class);
if (Total_Budget_List.size() == 0)
{
    for (int i=0;i<Total_Budget_List.size();i++)
    {
        totalbudget = new Total_Budget(Select_Members.get(i).getId()+"",CurrentDate,per_person_budget+"");
        totalbudget.save();
    }
}

But i am getting no such table exist in the database. Now how can i check that if table exist and is there any record in that table.

like image 360
user1722376 Avatar asked Sep 28 '22 23:09

user1722376


1 Answers

Surround your code with try / catch block. You can handle SQLiteException if your table not exists.

like image 62
Fiil Avatar answered Oct 10 '22 01:10

Fiil