Hi, I got a problem. I want to get data from a variable table name. Example:
B4A:
("id" is the table name)
B4X:
Sub GetCuponCode(id As String)
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("selectCuponCodeTenti", Array(id))
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
End Sub
jRDC2 Config File:
B4X:
sql.selectCuponCodeTenti=SELECT * FROM ?
I hope you get the idea of what I need, and can help me to find the right solution. Thanks
A command is an object of type DBCommand: Type DBCommand (Name As String, Parameters() As Object) Name - The case sensitive command name as configured in the server configuration (without sql.). Parameters - An array of objects that will be sent to the server and will replace the question marks in the command.
Yes, that is exactly whay I want. But I get a syntax error when executing that command on the logs in B4A. The error is:
B4X:
ResponseError. Reason: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''tenti001' WHERE used = 0 LIMIT 1' at line 1, Response: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''tenti001' WHERE used = 0 LIMIT 1' at line 1</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /rdc. Reason:
<pre> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''tenti001' WHERE used = 0 LIMIT 1' at line 1</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>
ERROR: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 500 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''tenti001' WHERE used = 0 LIMIT 1' at line 1</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /rdc. Reason:
<pre> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''tenti001' WHERE used = 0 LIMIT 1' at line 1</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/>
</body>
</html>
** Activity (cuponelegido) Pause, UserClosed = false **
Thanks. I found that I should be using something like:
B4X:
declare @tablename varchar(50)
set @tablename = 'test'
EXEC('SELECT * FROM ' + @tablename)
However, I dont quite know how to set @tablename to be my parameter from my android App.
In the config file, I should somehow say that "@tablename = ?" right? so that tablename will be my parameter.
I dont know how to do it. Never programmed in sql.
I wrote in the config file:
B4X:
sql.selectCuponCodeTenti=
declare @tablename varchar(50)
set @tablename = ?
EXEC('SELECT * FROM ' + @tablename)
but clearly it does not work. Im getting parameter index out of bounds exception. Any idea? Thanks and sorry im just trying to understand sql.