insert! params cannot contain keys of reserved words

Description

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.

Environment

MySQL 5.7.16

Activity

Show:

Sean CorfieldNovember 13, 2016 at 12:38 AM

Closed by 0.7.0-alpha1 release.

importOctober 20, 2016 at 6:25 AM

Comment made by: totakke

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

Sean CorfieldOctober 20, 2016 at 6: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)

Sean CorfieldOctober 20, 2016 at 6:17 AM

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

Declined

Details

Assignee

Reporter

Priority

Created October 20, 2016 at 5:39 AM
Updated November 13, 2016 at 12:38 AM
Resolved November 13, 2016 at 12:38 AM

Flag notifications