On 14 July 2010 17:21, Tim McCormack <basalgang...@brainonfire.net> wrote: > It looks like all the clojure.contrib.sql functions that interact with > tables fail to wrap table names in backticks. As a result, any table > names that are reserved words (like "order") or contain non- > alphanumeric characters (like "foo-bar") will cause SQL errors: > > (require '[clojure.contrib.sql :as sql]) > (def db {:classname "com.mysql.jdbc.Driver" :subprotocol > "mysql" :subname "//localhost/db" :user "user" :password "secret"}) > (sql/with-connection db (sql/drop-table "foo-bar")) ; throws error [1] > (sql/with-connection db (sql/do-commands "DROP TABLE `foo-bar`")) ; > succeeds and returns (0)
What does the following do? (sql/with-connection db (sql/drop-table "`foo-bar`")) I'm not sure that's the proper solution even if it does work, though. > Here's the source code: > http://github.com/richhickey/clojure-contrib/blob/master/src/main/clojure/clojure/contrib/sql.clj > Example: #L124: (format "DROP TABLE %s" (as-str name)) should use > "DROP TABLE `%s`" > > Is there some kind of JDBC nonsense that I'm not aware of? Are > backticks a special feature of MySQL that can't be read by all JDBC- AFAIK backticks are MySQL-specific. PostgreSQL uses double quotes. I imagine there is a proper JDBC way of handing this, though. > compatible RDBMSs? I'm not a database person, but it seems to me that > either backticks should be placed around all table, database, and > column names, or a warning should be added to the docs about only > using non-reserved alphabetic table names. In PostgreSQL (and I think the SQL standard) table and column names are lowercased by default unless they are quoted, so you can: create table blah ... select * from Blah; and it will work. So just quoting everything might surprise some people, but I would not object to it. -- Michael Wood <esiot...@gmail.com> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en