B4X:
Sub InitTableandSql(FirstTime As Boolean)
Try
If FirstTime Or blnFileAvailable = False Then
'check external first
If File.Exists(File.DirRootExternal, Starter.DiagReportDatabase & "diagreport.db") Then
sql.Initialize(File.DirRootExternal, Starter.DiagReportDatabase & "diagreport.db", False)
blnFileAvailable = True
Else If File.Exists(File.DirInternal, Starter.DiagReportDatabase & "diagreport.db") Then
sql.Initialize(File.DirInternal, Starter.DiagReportDatabase & "diagreport.db", False)
blnFileAvailable = True
Else
blnFileAvailable = False
End If
End If
Activity.LoadLayout("diagreporttable")
'this is for edit and delete button
editCol = B4XTable1.AddColumn("Edit", B4XTable1.COLUMN_TYPE_TEXT)
editCol.Sortable = False
editCol.Width = 82dip
B4XTable1.RowHeight = 50dip
' B4XTable1.NumberOfFrozenColumns = 1
B4XTable1.AddColumn("ID", B4XTable1.COLUMN_TYPE_NUMBERS)
B4XTable1.AddColumn("RO", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Date", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("VIN", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Year", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Make", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Model", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("File Name", B4XTable1.COLUMN_TYPE_TEXT)
Dim Data As List
Data.Initialize
If blnFileAvailable = True Then
Dim rs As ResultSet = sql.ExecQuery("SELECT ID, RO, Date, VIN, Year, Make, Model, FileName FROM diagnosticlog")
Dim startTime As Long = DateTime.Now
Do While rs.NextRow
Dim row(8) As Object
row(0) = rs.GetDouble("ID")
row(1) = rs.GetString("RO")
row(2) = rs.GetString("Date")
row(3) = rs.GetString("VIN")
row(4) = rs.GetString("Year")
row(5) = rs.GetString("Make")
row(6) = rs.GetString("Model")
row(7) = rs.GetString("FileName")
If row(0) = Null Then row(0) = ""
If row(1) = Null Then row(1) = ""
If row(2) = Null Then row(2) = ""
If row(3) = Null Then row(3) = ""
If row(4) = Null Then row(4) = ""
If row(5) = Null Then row(5) = ""
If row(6) = Null Then row(6) = ""
If row(7) = Null Then row(7) = ""
Data.Add(row)
Loop
Log("Index time: " & (DateTime.Now - startTime) & " ms")
rs.Close
Dim startTime As Long = DateTime.Now
B4XTable1.SetData(Data)
B4XTable1.MaximumRowsPerPage = 20
B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
For i = 1 To editCol.CellsLayouts.Size - 1
Dim p As B4XView = editCol.CellsLayouts.Get(i)
p.AddView(CreateButton("btnEdit", Chr(0xF044)), 1dip, 5dip, 40dip, 40dip)
p.AddView(CreateButton("btnDelete", Chr(0xF00D)), 41dip, 5dip, 40dip, 40dip)
' p.AddView(CreateButton("btnDuplicate",Chr(0xF0C5)), 85dip, 5dip, 40dip, 40dip)
Next
Log("Index time: " & (DateTime.Now - startTime) & " ms")
Else
'no file..do nothing but show the table
B4XTable1.SetData(Data)
End If
Catch
Log("Error InitTable and Sql" & LastException.Message)
End Try
End Sub