<< Back to previous view

[JDBC-146] insert! params cannot contain keys of reserved words Created: 19/Oct/16  Updated: 20/Oct/16  Resolved: 20/Oct/16

Status: Resolved
Project: java.jdbc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Toshiki Takeuchi Assignee: Sean Corfield
Resolution: Declined Votes: 0
Labels: None

MySQL 5.7.16


A parameters map of insert! cannot contain keys of reserved words. For example, because "contain" is a reserved word of MySQL, the following code will cause MySQLSyntaxErrorException.

(jdbc/insert! db-spec :foo {:condition "a"})
=> 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 'condition ) VALUES ( 'a' )' at line 1  sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)

A workaround is using quoted string as a key of the map.

(jdbc/insert! db-spec :foo {"`condition`" "a"})
=> ({:generated_key 1})

However, I think that all keys of the params map should be quoted by default.

Comment by Sean Corfield [ 20/Oct/16 12:17 AM ]

Read the documentation for the :entities option which allows you to quote SQL column names.

Comment by Sean Corfield [ 20/Oct/16 12:18 AM ]

(note also that you can also specify :entities as a default in the db-spec as of the most recent version of java.jdbc)

Comment by Toshiki Takeuchi [ 20/Oct/16 12:25 AM ]

Oh, I didn't notice :entities option...
Thank you.

Generated at Sun Oct 23 07:10:22 CDT 2016 using JIRA 4.4#649-r158309.