[RDC] Server side query... I'm lost

Cableguy

Expert
Licensed User
Longtime User
Hi guys...

I'm pretty much using EREL's jRDC server unchanged as my RDC solution... All is going along pretty well, but now I face a situation in which, for security reasons, I need to query the database from the server side, and compare it with the app custom command variable...

So, basically, I want to send a "compare" command, passing a byte variable, from my B4J Desktop app, and in the server side, retrieve the value against which I want the comparison to take place...

BUT... I'm completely lost on the how to, since all this DataBase thing is very new to me, and the server mechanics, although I can understand what they're doing, I kind of can't figure out how to implement this one myself...

So PLEASE, can someone provide me an example on how I could add a "custom" handler call to the server, which will use the already in use connector, to retrieve a value from the DataBase, and compare it to passed value, and return a simple Boolean or string response.

How I see this working (plain English)
B4J Desktop app:
command="Compare (or any other non MySQL wording) ValueToCompare, ReferenceFromWhereToCompare"

B4J Server Side:
If command = "Compare" then
Value1 = get ReferenceFromWhereToCompare
If Value1 = ValueToCompare then
Return "Match"
Else
Return "Don't Match"
end if

But I just can't put my head into codding this!
 

OliverA

Expert
Licensed User
Longtime User
How about setting up something like the following in the config.properties file (in this example, I'm comparing name and id values from an employees table to see if they exists. Adjust to your needs):

sql.compare_name="select count(*) from employees where name=?"
sql.compare_id="select count(*) from employees where id=?"
and on and on

for the values that you want to compare

In your calling code you could then use the applicable compare method with the value to be compared. If the value does not match, 0 rows are returned, otherwise 1 or more rows are returned. If this would work, you would not need a separate handler.
 
Upvote 0

Harris

Expert
Licensed User
Longtime User

This is exactly what I do. It was all learned here many days ago. Use different methods where applicable.

The ABMaterial call selects and returns a list...

B4X:
        ActDetid = tblUsers.GetString(tblCellInfo.Row, 0)
        Dim cases As List = DBM.SQLSelect(SQL, "SELECT * FROM cmeeting WHERE CaseID =" & ActDetid, Null)
        If cases.Size > 0 Then
            Dim curmap As Map = cases.Get(0)

            Dim casesummary As ABMInput = inp.Content.Component("casesummary")
            casesummary.Text = curmap.Get("casesummary")

.......
        End If

If select returned a list size of zero (0), then you are done..

Otherwise, convert each list item to a map and process the field names for values...
Study the ABM Feedback code (all modules) example. You will be amazed at what you will learn - as I was.
At first glance, it may seem strange (well - unfamiliar). But then you uncover the sheer brilliance in this logic!
The DBM code module is packed with goodies.

Like this one - SQLInsertOrUpdate

B4X:
Sub SQLInsertOrUpdate(SQL As SQL, SelectQuery As String, InsertQuery As String, UpdateQuery As String) As Int
    Dim foundres As Int = SQLSelectSingleResult(SQL, SelectQuery)   
    If foundres = -99999999 Then       
        Return foundres
    End If
    Dim res As Int   
    If foundres = 0 Then
        res = SQLInsert(SQL, InsertQuery)
    Else
        res = SQLUpdate(SQL, UpdateQuery)
        If res = 0 Then
           res = foundres
        End If
    End If   
    Return res
End Sub

Logic is essentially the same in RDC (in the callback).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…