Hi,
I'm still very new to Basic4Android and now I'm playing around with dSQL Databases
I've manged to create a very simple database with two tables. PlayerNames and and Games. I've succesfully created the tables and some queries to enter data.
What I would like now is to somehow execute a query against the database and display the result in a table.
From reading the tutorials I think I need to use a Cursor object? But I can't quite get my head around Cursor and how I can use this to display my query result in a list/table on screen.
Is this a simple code or is it more complicated that I think?
The query I want to run is simply SELECT * FROM PlayerNames
I'm still very new to Basic4Android and now I'm playing around with dSQL Databases
I've manged to create a very simple database with two tables. PlayerNames and and Games. I've succesfully created the tables and some queries to enter data.
What I would like now is to somehow execute a query against the database and display the result in a table.
From reading the tutorials I think I need to use a Cursor object? But I can't quite get my head around Cursor and how I can use this to display my query result in a list/table on screen.
Is this a simple code or is it more complicated that I think?
The query I want to run is simply SELECT * FROM PlayerNames
B4X:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
SQLDb.Initialize(File.DirDefaultExternal, "vbstats.db", True)
End If
CreateTables
Insertdata
Result=SQLDb.ExecQuerySingleResult("SELECT count()* FROM PlayerNames")
Msgbox("Number of players: ", Result)
End Sub
B4X:
Sub CreateTables
SQLDb.ExecNonQuery("CREATE TABLE IF NOT EXISTS PlayerNames (id INTEGER PRIMARY KEY , First TEXT, Last TEXT, Serves INTEGER, Game INTEGER)")
SQLDb.ExecNonQuery("CREATE TABLE IF NOT EXISTS Games (id INTEGER PRIMARY KEY, Hometeam TEXT, Awayteam TEXT)")
End Sub
B4X:
Sub Insertdata
SQLDb.ExecNonQuery("INSERT INTO PlayerNames VALUES(NULL, 'Mario', 'Bros', 1, 1)")
SQLDb.ExecNonQuery("INSERT INTO PlayerNames VALUES(NULL, 'Donkey', 'Kong', 1, 1)")
SQLDb.ExecNonQuery("INSERT INTO Games VALUES(NULL, 'Team A', 'Team B')")
End Sub