开发者

Gsql not executing while constructing query

开发者 https://www.devze.com 2023-04-13 07:20 出处:网络
I want to fire an update query , normally using groovy we do something like : sql.executeUpdate(\"update MYTABLE l set field1where l.id = ${someobj.id}\")

I want to fire an update query , normally using groovy we do something like :

sql.executeUpdate("update MYTABLE l set field1  where l.id = ${someobj.id}")

The above works perfectly but my problem is that i dont 开发者_如何学编程know ahead how many parameters i need to update. So i made a function which returns the properttoudate1 = value1 , propertytoupdate2 = value2 .. and so on.. Then i modified the above query to

sql.executeUpdate("update MYTABLE l set ${makeQueryString(propertiesToUpdate)} where l.id = ${someobj.id}")

Now it gives me the error::

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 ''PROPERTY1 = 1' where l.id = 'PROPERTVALUE1'' at line 1

ANY IDEAS ??


You need to tell Groovy that the fieldname is a static, and shouldnt be replaced with ? by using Sql.expand:

sql.executeUpdate("update MYTABLE l set ${Sql.expand(makeQueryString(propertiesToUpdate))} where l.id = ${someobj.id}")
0

精彩评论

暂无评论...
验证码 换一张
取 消