Android Question SQL syntax to check if a table has any data (SOLVED)

Colin Evans

Active Member
Licensed User
Longtime User
Hi, sorry for this basic question, I have a settings table held in my database, with a Primary Key ( ID ), all I want to do is check if the settings screen as been filled in previously, so basically ID will equal 1 if it as, if not it won't exists

If it doesn't exists take me to the settings screen, i.e. Start.Activity(Settings), if it does just read in the values held in the tabel

I've looked for simple examples but can't find any, thanks in advance
 

Alex_197

Well-Known Member
Licensed User
Longtime User
B4X:
Dim Cursor1 as Cursor
Dim MySQL as String
Dim Qty as Int
Dim SQL1 As SQL
SQL1.Initialize(MyPath, "test1.db", True)

MySQL="select count(ID) as Qty from MyTableName"

Cursor1=SQL1.ExecQuery(MySQL)
Cursor1.Position=0
Qty=Cursor1.getInt("Qty")

Cursor1.close

If Qty=0 then
    TotastMessage("Table Is Empty")
Else
    TotastMessage("Table has data")
End if
 
Upvote 0
Top