Johan Schoeman Expert Licensed User Longtime User Dec 16, 2020 #1 How do one cycle through all rows in a B4XTable? This does not work as it seems to only rely on the size of the "visible table" and not the complete table (visible and not visible) B4X: For i = 1 To B4XTable1.Size - 2 Dim m As Map = B4XTable1.GetRow(i) It gives this error: B4X: java.lang.IndexOutOfBoundsException: Index: 11, Size: 11 ....that seems to be related to this line of code: B4X: B4XTable1.MaximumRowsPerPage = 10 I have searched the forum but don't get a solution to the error. Anyone that can shed some light on this problem? Thanks JS
How do one cycle through all rows in a B4XTable? This does not work as it seems to only rely on the size of the "visible table" and not the complete table (visible and not visible) B4X: For i = 1 To B4XTable1.Size - 2 Dim m As Map = B4XTable1.GetRow(i) It gives this error: B4X: java.lang.IndexOutOfBoundsException: Index: 11, Size: 11 ....that seems to be related to this line of code: B4X: B4XTable1.MaximumRowsPerPage = 10 I have searched the forum but don't get a solution to the error. Anyone that can shed some light on this problem? Thanks JS
LucaMs Expert Licensed User Longtime User Dec 16, 2020 #2 I think that for this it will need to add a getData function to the B4XTable library. Upvote 0
Johan Schoeman Expert Licensed User Longtime User Dec 16, 2020 #3 I have a table with 200 odd records/rows and need to cycle through the whole table - not just the visible rows. I guess there must be some way to accomplish this...? Upvote 0
I have a table with 200 odd records/rows and need to cycle through the whole table - not just the visible rows. I guess there must be some way to accomplish this...?
LucaMs Expert Licensed User Longtime User Dec 16, 2020 #4 Looking at the properties and methods of B4XTable I would say that it is currently not possible, but it shouldn't be difficult to add a function (GetData) to get all the data so you can iterate through it. Upvote 0
Looking at the properties and methods of B4XTable I would say that it is currently not possible, but it shouldn't be difficult to add a function (GetData) to get all the data so you can iterate through it.
Erel B4X founder Staff member Licensed User Longtime User Dec 16, 2020 #5 It is of course possible. The data is stored in the internal SQLite db and you can access it with table.sql1: https://www.b4x.com/android/forum/t...or-next-loop-on-a-b4xtable.110216/post-687985 Upvote 0
It is of course possible. The data is stored in the internal SQLite db and you can access it with table.sql1: https://www.b4x.com/android/forum/t...or-next-loop-on-a-b4xtable.110216/post-687985
elsanto Member Licensed User Longtime User Dec 16, 2020 #6 I am working with B4xTable and it is a solution to work with the internal sqlite that it generates, and directly working with it is very easy Upvote 0
I am working with B4xTable and it is a solution to work with the internal sqlite that it generates, and directly working with it is very easy
Johan Schoeman Expert Licensed User Longtime User Dec 16, 2020 #7 I am trying to "log" the data of each row with.... B4X: Sub Button1_Click For Each column As B4XTableColumn In B4XTable1.columns Log(column.Id) Next Dim numOfPages As Int = B4XTable1.Size / B4XTable1.RowsPerPage If B4XTable1.Size Mod B4XTable1.RowsPerPage > 0 Then numOfPages = numOfPages + 1 End If Log("numOfPages = " & numOfPages) For j = 1 To numOfPages For i = 1 To B4XTable1.RowsPerPage Dim m As Map = B4XTable1.GetRow(i) Dim pnl As B4XView = FlagsColumn.CellsLayouts.Get(i) '+1 because the first cell is the header Dim iv As B4XView = pnl.GetView(1) 'ImageView will be the 2nd child of the panel. The built-in label is the first. Dim mbm As Bitmap = iv.GetBitmap ImageView1.Bitmap = mbm Log("m = " & m.Get("Flags")) Log("m = " & m.Get("Id")) Log("m = " & m.Get("Name")) Log("m = " & m.Get("Alpha2")) Log("m = " & m.Get("Alpha3")) Log("table size = " & B4XTable1.Size) Next B4XTable1.CurrentPage = j 'change the page to the next page Next End Sub ......but it just logs the data of the first 10 rows in the table (B4XTable1.MaximumRowsPerPage = 10) B4XTable1.CurrentPage = j -> it does not get the new page data in the above code. Any other way to do it other than having do dig into SQLite? Upvote 0
I am trying to "log" the data of each row with.... B4X: Sub Button1_Click For Each column As B4XTableColumn In B4XTable1.columns Log(column.Id) Next Dim numOfPages As Int = B4XTable1.Size / B4XTable1.RowsPerPage If B4XTable1.Size Mod B4XTable1.RowsPerPage > 0 Then numOfPages = numOfPages + 1 End If Log("numOfPages = " & numOfPages) For j = 1 To numOfPages For i = 1 To B4XTable1.RowsPerPage Dim m As Map = B4XTable1.GetRow(i) Dim pnl As B4XView = FlagsColumn.CellsLayouts.Get(i) '+1 because the first cell is the header Dim iv As B4XView = pnl.GetView(1) 'ImageView will be the 2nd child of the panel. The built-in label is the first. Dim mbm As Bitmap = iv.GetBitmap ImageView1.Bitmap = mbm Log("m = " & m.Get("Flags")) Log("m = " & m.Get("Id")) Log("m = " & m.Get("Name")) Log("m = " & m.Get("Alpha2")) Log("m = " & m.Get("Alpha3")) Log("table size = " & B4XTable1.Size) Next B4XTable1.CurrentPage = j 'change the page to the next page Next End Sub ......but it just logs the data of the first 10 rows in the table (B4XTable1.MaximumRowsPerPage = 10) B4XTable1.CurrentPage = j -> it does not get the new page data in the above code. Any other way to do it other than having do dig into SQLite?
LucaMs Expert Licensed User Longtime User Dec 16, 2020 #8 Your have to access the B4XTable internal SQLite DB, provided by the property: B4X: B4XTable1.sql1 and work on it to retrieve records as you normally do. Upvote 0
Your have to access the B4XTable internal SQLite DB, provided by the property: B4X: B4XTable1.sql1 and work on it to retrieve records as you normally do.
Erel B4X founder Staff member Licensed User Longtime User Dec 16, 2020 #9 No need to "dig into SQLite". You do need to get the data, without digging, from the database: Code: Dim o() As Object = B4XTable1.BuildQuery(False) Dim rs As ResultSet = B4XTable1.sql1.ExecQuery2(o(0), o(1)) Do While rs.NextRow Dim Name As String = rs.GetString(NameColumn.SQLID) Log(Name) Loop rs.Close Upvote 0
No need to "dig into SQLite". You do need to get the data, without digging, from the database: Code: Dim o() As Object = B4XTable1.BuildQuery(False) Dim rs As ResultSet = B4XTable1.sql1.ExecQuery2(o(0), o(1)) Do While rs.NextRow Dim Name As String = rs.GetString(NameColumn.SQLID) Log(Name) Loop rs.Close
Erel B4X founder Staff member Licensed User Longtime User Dec 16, 2020 #10 Another option if you prefer working with Table.GetRow: Code: For Each rowid As Long In GetRowIds Dim m As Map = B4XTable1.GetRow(rowid) Log(m) Next GetRowIds: Code: Private Sub GetRowIds As List Dim res As List res.Initialize Dim rs As ResultSet = B4XTable1.sql1.ExecQuery2("SELECT rowid FROM data", Null) Do While rs.NextRow res.Add(rs.GetLong("rowid")) Loop rs.Close Return res End Sub If the data set is large then the previous code will probably be faster. Upvote 0
Another option if you prefer working with Table.GetRow: Code: For Each rowid As Long In GetRowIds Dim m As Map = B4XTable1.GetRow(rowid) Log(m) Next GetRowIds: Code: Private Sub GetRowIds As List Dim res As List res.Initialize Dim rs As ResultSet = B4XTable1.sql1.ExecQuery2("SELECT rowid FROM data", Null) Do While rs.NextRow res.Add(rs.GetLong("rowid")) Loop rs.Close Return res End Sub If the data set is large then the previous code will probably be faster.
LucaMs Expert Licensed User Longtime User Dec 16, 2020 #11 Erel said: Dim Name As String = rs.GetString(NameColumn.SQLID) Click to expand... Had to use: B4X: Dim FieldValue As String = rs.GetString("c0") Upvote 0
Erel said: Dim Name As String = rs.GetString(NameColumn.SQLID) Click to expand... Had to use: B4X: Dim FieldValue As String = rs.GetString("c0")
Erel B4X founder Staff member Licensed User Longtime User Dec 16, 2020 #12 Better to keep a global variable with the column object: Code: NameColumn = B4XTable1.AddColumn(...) Upvote 0
LucaMs Expert Licensed User Longtime User Dec 16, 2020 #13 B4X: For Each Column As B4XTableColumn In B4XTable1.Columns Log(Column.Id & tab & Column.SQLID) Next Upvote 0