Fix MySQL ENUM and SET parsing, fixing #120.

MySQL ENUM syntax is more complex than it first looked, allowing for
escaping and spaces, so use a more complex parser here. Fortunately, the
syntax looks like a CSV row enough that cl-csv can be re-used for that.
This commit is contained in:
Dimitri Fontaine 2014-10-28 14:56:37 +01:00
parent 93990317f3
commit bb2c7e4e17

View File

@ -9,10 +9,9 @@
;;;
(defun explode-mysql-enum (ctype)
"Convert MySQL ENUM expression into a list of labels."
;; from: "ENUM('small', 'medium', 'large')"
;; to: ("small" "medium" "large")
(mapcar (lambda (x) (string-trim "' )" x))
(sq:split-sequence #\, ctype :start (position #\' ctype))))
(cl-ppcre:register-groups-bind (list)
("(?i)(?:ENUM|SET)\\s*\\((.*)\\)" ctype)
(first (cl-csv:read-csv list :separator #\, :quote #\' :escape "\\"))))
(defun get-enum-type-name (table-name column-name identifier-case)
"Return the Type Name we're going to use in PostgreSQL."