Android Question [SOLVED] DButils - Doub about it

killiak

Member
Licensed User
Longtime User
Hi there!

Createtable on starter, everytime that the program loads create a Table? Or if the table is allready create, nothing will happen? I mean, data remains the same. I mean, i will not droptable each load.

Is there any option to see what tables are inside my database?

Thanks
 

Mahares

Expert
Licensed User
Longtime User
Is there any option to see what tables are inside my database?
Use this code to display all your tables:
B4X:
Cursor1 = SQL1.ExecQuery("SELECT name FROM sqlite_master WHERE type='table'")
For i=0 To Cursor1.RowCount-1
        Cursor1.Position=i
        Log($"Table: ${i}  ${Cursor1.GetString("name")}"$)  'displays all tables in database
Next
 
Last edited:
Upvote 0

killiak

Member
Licensed User
Longtime User
Use this code to display all your tables:
B4X:
Cursor1 = SQL1.ExecQuery("SELECT name FROM sqlite_master WHERE type='table'")
For i=0 To Cursor1.RowCount-1
        Cursor1.Position=i
        Log($"Table: ${i}  ${Cursor1.GetString("name")}"$)  'displays all tables in database
Next

Great! Thanks...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Or:
B4X:
Dim rs As ResultSet = SQL1.ExecQuery("SELECT name FROM sqlite_master WHERE type='table'")
Do While rs.NextRow
        Log($"Table: ${Cursor1.GetString("name")}"$)  'displays all tables in database
Loop
rs.Close
The advantage of using ResultSet is that it is compatible with B4A, B4i and B4J.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Dim rs As ResultSet = SQL1.ExecQuery("SELECT name FROM sqlite_master WHERE type='table'")
Do While rs.NextRow
Log($"Table: ${Cursor1.GetString("name")}"$) 'displays all tables in database
Next
rs.Close

@Erel is so excited about publishing the latest B4A 7.80 that he uncharacteristically stumbled through his answer which should be;
B4X:
Dim i As Int
    Dim rs As ResultSet = SQL1.ExecQuery("SELECT name FROM sqlite_master WHERE type='table'")
    Do While rs.NextRow
        Log($"Table:${i}    ${rs.GetString("name")}"$)  'displays all tables in database 
        i=i+1
    Loop
    rs.Close
It is even more advantageous to use the parameterized query as @Erel often advocates:
B4X:
 Dim rs As ResultSet = SQL1.ExecQuery2("SELECT name FROM sqlite_master WHERE type=?", _
   Array As String("table"))
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Only half true :)
I didn't miss the index. It makes the solution less elegant and I don't think that the index adds anything useful here.
Actually I am not referring to the index. I am referring to the 'Next' in your code which should have been 'Loop'.
 
Upvote 0
Top