B4J Question DButils list db contents

ThRuST

Well-Known Member
Licensed User
Longtime User
I've managed to create an SQLite database file from scratch with DButils and added a SQL library, nothing fancy just id, firstname, lastname and added some values now I want to list the contents in the database into a tableview.

Table 'Students'
id
firstname
lastname

1. How do I initialize a pre-made SQLite database with DButils? (I allready have one)
2. How can I view contents in first column, and multiple columns in a tableview by using DButils? Some advice what I can do with this DButils module? Thanks
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
1) Initialize the database using the SQL Library then pass the SQL object to the DBUtils calls.
2) Erel has provided the ExecuteMemoryTable method to return a list of arrays that contains the values of all columns in selected records. If you don't want them all or the database is particularly large, then it would be more efficient to use the standard SQL methods to get the data for just the columns you require as you wouldn't have the intermediate list.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Sorry, just realized this is a B4J question, in B4j there is also an ExecuteTableView method, that will populate a passed TableView.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Steve05, do you have an example? :) I forgot to update my post about that there's a difference in DButils for B4J than those examples for B4A..
so a few more examples on DButils for B4J wouldn't hurt. I guess DButils works with a LIST that you just pass into the DButils. I'd like to see the differences.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I can't create an example without creating SQL tables etc. Best thing to do is try it and ask if you run into a problem.

Check the Method parameter list for the required data.

B4X:
ExecuteTableView(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, _
    TableView1 As TableView)

So you need to pass the SQL Object, the Query i.e. :
B4X:
Query = "SELECT * From TABLENAME WHERE ID = ?"

Any required arguments:
B4X:
Array As String(ID)

The limit of the number of items you want returned (0 for all)

and an initialized Tableview.

Give it a go.
 
Upvote 0
Top