Android Question [Solved] How to use MySQL LIMIT clause in jRDC2?

Sergio Castellari

Active Member
Licensed User
Situation:
a) I need to make the following query:

B4X:
sql.select_articulos_precios=Select a.CODIGO, a.CODIFICADO, a.NOMBRE, a.PVENTA, a.PVENTA_2, a.PVENTA_3, a.PVENTA_4, a.PVENTA_5, a.DOLARIZADO From ARTICULO a \
                              Donde a.FECHAEGRE = "0000-00-00" y Substr (a.NOMBRE, 1,?) =? ordenar por un.NOMBRE Limite 0,?

But when using it, it throws the following error:
<pre> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &apos;&apos;300&apos;&apos; at line 1</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>

I use 300 as a limit.
If I do the same query from MySQL Query Browse, it works fine.

What can I be doing wrong in the query inside "config.properties"
Greetings[/CODE]
 
Last edited by a moderator:

TILogistic

Expert
Licensed User
Longtime User
looking at the java code (PreparedStatement) :

public ResultSetWrapper ExecQuery2

and this other:
con.ExecQuery2(Main.rdcConnector1.GetCommand(cmd.Name), cmd.Parameters)
B4X:
Public Sub GetCommand(Key As String) As String
    If commands.ContainsKey("sql." & Key) = False Then
        Log("*** Command not found: " & Key)
    End If
    Return commands.Get("sql." & Key)
End Sub

I think passing parameters as object type should work.

Change:
B4X:
Dim aCom() As Object = Array (nCar,cFiltro,MinPro,MaxPro,MinLin,MaxLin,MinRub,MaxRub, nLimit)
B4X:
GetRecord (Command As String, parameters() As Object) As ResumableSub

P.S: (nLimit)
Limit values must be integers.


I got excited studying the problem.

?????
 
Last edited:
Upvote 0

Sergio Castellari

Active Member
Licensed User
looking at the java code (PreparedStatement) :

public ResultSetWrapper ExecQuery2

and this other:
con.ExecQuery2(Main.rdcConnector1.GetCommand(cmd.Name), cmd.Parameters)
B4X:
Public Sub GetCommand(Key As String) As String
    If commands.ContainsKey("sql." & Key) = False Then
        Log("*** Command not found: " & Key)
    End If
    Return commands.Get("sql." & Key)
End Sub

I think passing parameters as object type should work.

Change:
B4X:
Dim aCom() As Object = Array (nCar,cFiltro,MinPro,MaxPro,MinLin,MaxLin,MinRub,MaxRub, nLimit)
B4X:
GetRecord (Command As String, parameters() As Object) As ResumableSub

P.S: (nLimit)
Limit values must be integers.


I got excited studying the problem.

?????
Hi @oparra, @OliverA

Thank you very much for your patience and detailed explanations. It finally WORKS by making those little changes.

NOTE: At first I thought that if I modified "GEtRecord" from String to Objet, I had to change ALL the calls (currently my APP has more than 100), but obviously B4X internally makes the passage from String to Objets automatically, since I did not have I had to modify none and the APP kept connecting correctly !!! .... a genius!
Basically when I need a variable "LIMIT" from the APP, I use this syntax, otherwise I keep sending a string array and it works.

A million thanks!!!??
 
Upvote 0
Top