Android Question B4Xtable.createview A Toddlers quide

rodmcm

Active Member
Licensed User
Could someone please assist in my general understanding of the above. I have searched these forums but still lack understanding of conditional (WHERE) sorts
.
I have a simple 100 row 5 record table with items in a column with the title "EQUIPMENT" One of the items is RP1 which could occur many times in that column
I want a general sort routine to display the records only from RP1 ( or any other item of my choosing) on the table

B4X:
    Dim Col1 As B4XTableColumn =  DBTable.GetColumn("EQUIPMENT")
    Dim SearchItem As String = "RP1"
    DBTable.CreateDataView($"${Col1.SQLID} = ?"$,Array As String(SearchItem))

This faults in the IDE with " Too Many Parameters" ( B4X Table is Ver 1.17)

So Questions
a) Why the fault above?
b) If it ran would the table show only those records with RP1 in EQUIPMENT. Is there any other statements I need to apply
b) Where can I find an explanation in the use of $ in the string statement.
c) If I have a compound search such as x${Col1.SQLID} =? AND ${Col2.SQLID} = ? I assume that the order the ? corresponds to the order in the array?
d) Will the above work on the single B4X table or do I have to do two separate createview sorts?

Sorry for the naive questions, I understand the intent of the SQL commands from the excellent w3school tutorial, its the application int B4X that I am having problems with
 

Mahares

Expert
Licensed User
Longtime User
Why the fault above?
Your code should be like this:
B4X:
Dim Col1 As B4XTableColumn =  DBTable.GetColumn("EQUIPMENT")
    DBTable.CreateDataView($"${Col1.SQLID} = 'RP1'"$)  'shows only where col1 is RP1
You can use it like this using a B4Xswitch button. Replace your variables with my variables I show:
B4X:
Sub B4XSwitch1_ValueChanged (Value As Boolean)
    If Value Then
        Dim Col1 As B4XTableColumn =  B4XTable1.GetColumn("State")
        B4XTable1.CreateDataView($"${Col1.SQLID} = 'PA'"$)   'shows only records where the state is PA
    Else
        B4XTable1.ClearDataView
    End If
End Sub

Where can I find an explanation in the use of $ in the string statement.
Smart String Literals, here:
 
Upvote 0

rodmcm

Active Member
Licensed User
Thanks for that, at the command the table seems to attempt to show just the rows with just RP1 in but then reverts back to the original list. Any idea why?

The other question is your solution is for a specific entry. How do I make it generalised?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Thanks for that, at the command the table seems to attempt to show just the rows with just RP1 in but then reverts back to the original list. Any idea why?
You should upload a small project that reproduces it.

he other question is your solution is for a specific entry. How do I make it generalised?
Why not use the built-in search field?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The other question is your solution is for a specific entry. How do I make it generalised?
Someone will check your project when you upload it to forum. You can use a variable of course like this:
B4X:
Dim Col1 As B4XTableColumn =  B4XTable1.GetColumn("State")
        Dim SearchItem As String = "PA"  'can be any variable  or edittext or label text inside or outside this sub, etc.
        B4XTable1.CreateDataView($"${Col1.SQLID} = '${SearchItem}'"$)
You can also combine more than one column in the search like this:
B4X:
Dim Col1 As B4XTableColumn =  B4XTable1.GetColumn("State")
        Dim SearchItem As String = "PA"
        Dim Col2 As B4XTableColumn =  B4XTable1.GetColumn("Name")
        B4XTable1.CreateDataView($"${Col2.SQLID} LIKE  'Be%'   AND ${Col1.SQLID} = '${SearchItem}'"$)    'search in 2 cols: State col =Pa and Name col starts with Be

You can use the built in search box as mentioned to you in post 4 . Also, you can exclude some column from search by issuing: Col1.Searchable=false,
 
Upvote 0
Top