Android Question JRDC queries

Spuds

Member
Licensed User
I am new to B4X and struggling. Any help would be appreciated.

Simplified code as much as possible. The below code produces a list of all table records using 'sql.get_badge=select * from badge' as I would expect.
My question is how do I add a parameter to only return record(s) matching the parameter? I am using 'sql.get_badge=select * from badge where key = ?' For example
select * from badge where key ='555'
Key field is a string.
Using MySQL

Is there a way to pass SQL statement to server without having it defined in properties.config?

Thank for your help!

B4A:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Type dbResult (Tag As Object,Columns As Map, Rows As List)
    Type DBCommand (Name As String, Parameters() As Object)
    Private const rdcLink As String = "http://192.168.0.200:17178/rdc"
    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    
    
    GetRecord(0)
End Sub

Sub CreateRequest As DBRequestManager
    Dim req As DBRequestManager
    req.Initialize(Me, rdcLink)
    Return req
End Sub

Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = Name
    If Parameters <> Null Then cmd.Parameters =Parameters

    Return cmd
End Sub
Sub GetRecord (id As Int)
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_badge", Array(id))

    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As dbResult)
        'work with result
        req.PrintTable(res)
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub
 

josejad

Expert
Licensed User
Longtime User
Hi Spuds:

Not in my computer now, but as far I remember, you sample is fine.
I mean, you could have in properties config a:
'sql.get_badge=select * from badge'
and then
'sql.get_badge_id=select * from badge where key = ?'
and use it as you say..
 
Upvote 0
Top