Sub Test(Where1 As String, Where2 As String, Where3 As String)
Dim MyWhere As String = $"where MyField = '${Where1}' or MyField2 = '${Where2}' or MyField3 = '$Where3'"$
End Sub
with ALL where parameters
I haven't used JRDC but, if nobody else is going to give it a burl, then I will.
What do your current fixed-number-of-parameters commands look like? Samples with 0, 1, 2 and 3 parameters would be useful.
Dim cmd1 As DBCommand
cmd1.Initialize
cmd1.Name = "sql_test"
cmd1.Parameters = Array As Object("mark","john","alex")
reqManager.ExecuteQuery(cmd1, 0, "testSync")
My sugestion is that you use only one parameter which will be fullfilled from application with ALL where parameters... Like this
Select * from MyTable where ?
in code declare variable and send id to Rdc:
B4X:Sub Test(Where1 As String, Where2 As String, Where3 As String) Dim MyWhere As String = $"where MyField = '${Where1}' or MyField2 = '${Where2}' or MyField3 = '$Where3'"$ End Sub
and you need to send MyWhere as parameter to RDC...
Isn't this allow someone to have multiple brute force password attempts to crack the password? ?sql.test=SELECT * FROM `records` WHERE ((`Pwd` = ? OR `Pwd` = ? OR `Pwd` = ?)
Isn't this allow someone to have multiple brute force password attempts to crack the password? ?
And I call it from B4A with this code:
B4X:Dim cmd1 As DBCommand cmd1.Initialize cmd1.Name = "sql_test" cmd1.Parameters = Array As Object("mark","john","alex") reqManager.ExecuteQuery(cmd1, 0, "testSync")
Non I want to do the same thing using 4 or 5 'Pwd', not just 3, without creating another JRDC command
I have a feeling that you'll either have to:
b/ create another JRDC stored command with the required number of "?" parameter placeholders.
And I call it from B4A with this code:
JRDC Server = B4JI just realised probably why I'm more confused than usual.
Are we working with B4A or B4J here?
View attachment 137778
I haven't used JRDC but, if nobody else is going to give it a burl, then I will.
This does not bode well. It is starting to look like the commands are restricted to those specified at the server, presumably to keep a leash on what mischief clients can do to the database.
YesIt is starting to look like the commands are restricted to those specified at the server
Yespresumably to keep a leash on what mischief clients can do to the database
Type DBCommand2 (Name As String, Column1 As String, Parameters() As Object)
If method = "query2" Then
q = ExecuteQuery2(con, in, resp)
Else if method = "query3" Then
q = ExecuteQuery3(con, in, resp)
Else if method = "batch2" Then
q = ExecuteBatch2(con, in, resp)
Private Sub ExecuteQuery3 (con As SQL, in As InputStream, resp As ServletResponse) As String
Dim ser As B4XSerializator
Dim m As Map = ser.ConvertBytesToObject(Bit.InputStreamToBytes(in))
Dim cmd As DBCommand2 = m.Get("command")
Dim limit As Int = m.Get("limit")
Dim query As String = Main.rdcConnector1.GetCommand(cmd.Name)
If query.Contains("WHERE") = False Then query = query & " WHERE"
Dim words As List
words.Initialize
For Each param In cmd.Parameters
If words.Size > 0 Then query = query & " OR"
query = query & $" ${cmd.Column1} LIKE ?"$
words.Add("%" & param & "%") ' add % symbols
Next
Dim rs As ResultSet = con.ExecQuery2(query, words)
If limit <= 0 Then limit = 0x7fffffff 'max int
Dim jrs As JavaObject = rs
Dim rsmd As JavaObject = jrs.RunMethod("getMetaData", Null)
Dim cols As Int = rs.ColumnCount
Dim res As DBResult
res.Initialize
res.columns.Initialize
res.Tag = Null 'without this the Tag properly will not be serializable.
For i = 0 To cols - 1
res.columns.Put(rs.GetColumnName(i), i)
Next
res.Rows.Initialize
Do While rs.NextRow And limit > 0
Dim row(cols) As Object
For i = 0 To cols - 1
Dim ct As Int = rsmd.RunMethod("getColumnType", Array(i + 1))
'check whether it is a blob field
If ct = -2 Or ct = 2004 Or ct = -3 Or ct = -4 Then
row(i) = rs.GetBlob2(i)
Else if ct = 2 Or ct = 3 Then
row(i) = rs.GetDouble2(i)
Else If DateTimeMethods.ContainsKey(ct) Then
Dim SQLTime As JavaObject = jrs.RunMethodJO(DateTimeMethods.Get(ct), Array(i + 1))
If SQLTime.IsInitialized Then
row(i) = SQLTime.RunMethod("getTime", Null)
Else
row(i) = Null
End If
Else
row(i) = jrs.RunMethod("getObject", Array(i + 1))
End If
Next
res.Rows.Add(row)
Loop
rs.Close
Dim data() As Byte = ser.ConvertObjectToBytes(res)
resp.OutputStream.WriteBytes(data, 0, data.Length)
Return "query: " & cmd.Name
End Sub
sql.query_with_variable_parameters=SELECT Field1, Field2, Field3 FROM MyTable
Public Sub ExecuteQuery2(Command As DBCommand2, Limit As Int, Tag As Object) As HttpJob
Dim ser As B4XSerializator
Dim data() As Byte = ser.ConvertObjectToBytes(CreateMap("command": Command, "limit": Limit, "version": VERSION))
Return SendJob(CreateJob, data, Tag, "query3")
End Sub
Public Sub GetStudents (parameters() As Object)
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand2 = CreateCommand2("query_with_variable_parameters", "Field3", parameters)
Wait For (req.ExecuteQuery2(cmd, 0, Null)) JobDone(j As HttpJob)
If j.Success Then
req.HandleJobAsync(j, "req")
Wait For (req) req_Result(res As DBResult)
req.PrintTable(res)
Else
Log("ERROR: " & j.ErrorMessage)
End If
j.Release
End Sub
The source can be modified to handle special commands in RDCHandler