Using "action":"prepared" to affect multiple rows.
spoko22 opened this issue · 2 comments
Hello, I think there would be a slight improvement of README value if you told us whether modifying multiple rows with a prepared statement is possible and if so - how to do it.
I tried passing an array of arrays, with no luck though.
query:
{
"action":"prepared",
"statement":"UPDATE a SET a.b = a.b + ? WHERE a.c LIKE ?",
"values":[[2,"two"],[3,"three"]]
}
result:
{"status":"error","message":"scala.MatchError: [2, two] (of class java.util.ArrayList)","error":"MODULE_EXCEPTION"}
So, is there any purpose for prepared statements other than preventing SQL injection?
Modyfing only one row works fine. Do I have to loop through the JsonArray
and each time call mod-mysql-postgresql
to modify my entries?
Sorry to say that, but this case isn't covered in the current implementation.
AFAIK prepared statements will be prepared on the connection and may save you some time if you use them multiple times. Currently you need to use transactions to use the same connection (or only have the pool size set to 1 to be sure to always get the same connection). Then you could send two messages like this:
{
"action" : "prepared",
"statement" : "UPDATE a SET a.b = a.b + ? WHERE a.c LIKE ?",
"values" : [2, "two"]
}
We mostly used them to avoid SQL injections, so we didn't really see a fit for this, actually. The Vert.x 3 async sql service will let you use connections directly, so you should be able to send multiple prepared commands on it without resorting to transactions or a pool size of 1 to work around this...
I'm closing this as this will be covered in the Vert.x 3 MySQL/PostgreSQL client and not easy to implement here.