Skip to content

Commit

Permalink
Fixed some issues with MySQL and SQL Server backends and improved the…
Browse files Browse the repository at this point in the history
… compiler method for IdentifierExpression.
  • Loading branch information
budu committed Apr 18, 2011
1 parent 42eb257 commit 2a84f86
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/lobos/backends/mysql.clj
Expand Up @@ -69,10 +69,12 @@

;; ## Compiler

(defmethod compile [::standard IdentifierExpression]
(defmethod compile [:mysql IdentifierExpression]
[identifier]
(let [{:keys [db-spec name qualifiers]} identifier]
(join* \. (map #(as-str \` % \`) (concat qualifiers name)))))
(join* \. (->> (concat qualifiers [name])
(filter identity)
(map #(when % (as-str \` % \`)))))))

(defvar- compiler-data-type-aliases
{:clob :text
Expand Down
16 changes: 10 additions & 6 deletions src/lobos/backends/sqlserver.clj
Expand Up @@ -66,10 +66,12 @@

;; ## Compiler

(defmethod compile [::standard IdentifierExpression]
(defmethod compile [:sqlserver IdentifierExpression]
[identifier]
(let [{:keys [db-spec name qualifiers]} identifier]
(join* \. (map #(as-str \[ % \]) (concat qualifiers name)))))
(join* \. (->> (concat qualifiers [name])
(filter identity)
(map #(when % (as-str \[ % \])))))))

(defmethod compile [:sqlserver FunctionExpression]
[function]
Expand Down Expand Up @@ -106,21 +108,23 @@
[_]
"IDENTITY")

(defn- drop-schema-cascade [db-spec oname]
(defn- drop-schema-cascade [db-spec sname]
(vec (for [element (with-db-meta db-spec
(-> (analyze-schema oname) :elements keys))]
(-> (analyze-schema sname) :elements keys))]
(compile (schema/build-drop-statement
(schema/table element)
:cascade
(assoc db-spec :schema oname))))))
(assoc db-spec :schema sname))))))

(defmethod compile [:sqlserver DropStatement]
[statement]
(let [{:keys [db-spec otype oname behavior options]} statement
sql-string (join \space
"DROP"
(as-sql-keyword otype)
(as-identifier db-spec oname (:schema db-spec)))]
(as-identifier db-spec oname
(when (not= otype :schema)
(:schema db-spec))))]
(if (= otype :index)
(join \space
"DROP INDEX"
Expand Down
5 changes: 3 additions & 2 deletions src/lobos/compiler.clj
Expand Up @@ -124,8 +124,9 @@
(defmethod compile [::standard IdentifierExpression]
[identifier]
(let [{:keys [db-spec name qualifiers]} identifier]
(join* \. (map #(when % (as-str \" % \"))
(concat qualifiers [name])))))
(join* \. (->> (concat qualifiers [name])
(filter identity)
(map #(when % (as-str \" % \")))))))

(defmethod compile [::standard FunctionExpression]
[function]
Expand Down

0 comments on commit 2a84f86

Please sign in to comment.