iOS Table and SQLite

New to iOS development and struggling with the iOS Table datasource method of populating from an SQLite table. I tried disassembling a couple of the XOJO examples but found it confusing. I have a simple SQLite database with a table called BOOKS with two columns (fields are ID and TITLE). The table has about 1500 rows. I am looking for a simple example of an iOS app which will help me use the TITLE column as a direct datasource for a simple single-section iOS Table (no pre-loading of an array, but the iOS Table directly fed from the SQLite database source). No features beyond scrolling the list in the table. If there is already a good XOJO example I missed (not the BaseballTeam example, please) then please point me accordingly. I suspect this is quite simple once I see it in action. Thanks much.

Just remove the other extra stuff and do the direct SQL query in the RowData method.

Here’s a stripped-down version of the Baseball example that just shows the team names to give you an idea:

https://www.dropbox.com/s/6ezaahbpp6lq25c/TableDataSourceSimpleDatabase.xojo_binary_project?dl=0

Thanks Paul…greatly appreciated.

Hello friends!
I also have a problem with ios Table. I can not understand how I can populate a table through the data source. I looked the example but my table is always empty.
This is my code in view open


dim DB as iOSSQLiteDatabase = New iOSSQLiteDatabase
Dim sql As Text = "SELECT id FROM tb1"
Dim results As iOSSQLiteRecordSet
Dim dbFile As FolderItem = SpecialFolder.Documents.Child("fd.sqlite")
DB.DatabaseFile = dbFile
If DB.DatabaseFile.Exists Then
  If DB.connect Then
    results = DB.SQLSelect(sql)
    
    While Not results.EOF
      dim lsClienti as cClienti
      lsClienti = new cClienti()
      listaclienti.DataSource = lsClienti
      results.MoveNext
    Wend
    
  end if
end if

What’s wrong?

N.B. cClienti is a class with iOSTableDataSource Interface.

Ciao Renato,
you are building a new datasource for every record.
Probably your code should be:
If DB.connect Then
results = DB.SQLSelect(sql)
dim lsClienti() as cClienti
While Not results.EOF
lsClienti.append = new cClienti(rs)
results.MoveNext
Wend
dsClienti.clienti=lsClienti
listaclienti.DataSource = dsClienti
end if

where:
cClienti is you class with your customer information that you read from the recordset
lsClienti is an array of cClienti
dsClienti is a class that implements the iOSTableDataSource interface, with a clienti() as cClienti property and where for example you can have:
RowCount: return clienti.ubound+1
and so on

Thank you for your reply. I understand but maybe I miss some part of code. Can you make me an example in Xojo ? I only need this:

  • Connect to SQLite database
  • Run query
  • Show results in iOSTable

If you can’t, please show me a good tutorial. Xojo example isn’t good for me (I’m newbie with Xojo)

N.B. Alternatively, if you want, can continuing to talk, in Italian language, in other place (Fb, IRC, etc…)

OK guarda questo tutorial Iniziare ad usare la iOSTable su Xojo per iOS

Puoi anche fare le domande nella sezione del forum in italiano.

Grazie :slight_smile: