Fix MySQL Enum parsing.

We use a CSV parser for the MySQL enum values, but the quote escaping wasn't
properly setup: MySQL quotes ENUM values with a single-quote (') and uses
two of them ('') for escaping single-quotes when found in the ENUM value
itself.

Fixes #597.
This commit is contained in:
Dimitri Fontaine 2017-08-01 18:40:27 +02:00
parent 3103b0dc72
commit 5c1c4bf3ff
2 changed files with 4 additions and 2 deletions

View File

@ -26,7 +26,9 @@
((:enum :set)
(format stream "CREATE TYPE ~a AS ENUM (~{'~a'~^, ~});"
(sqltype-name sqltype)
(sqltype-extra sqltype)))))
(mapcar (lambda (value)
(cl-ppcre:regex-replace-all "'" value "''"))
(sqltype-extra sqltype))))))
(defmethod format-drop-sql ((sqltype sqltype) &key (stream nil) cascade if-exists)
(format stream "DROP TYPE~:[~; IF EXISTS~] ~a~@[ CASCADE~];"

View File

@ -157,7 +157,7 @@
"Convert MySQL ENUM expression into a list of labels."
(cl-ppcre:register-groups-bind (list)
("(?i)(?:ENUM|SET)\\s*\\((.*)\\)" ctype)
(first (cl-csv:read-csv list :separator #\, :quote #\' :escape "\\"))))
(first (cl-csv:read-csv list :separator #\, :quote #\' :escape "''"))))
(defmethod cast ((col mysql-column))
"Return the PostgreSQL type definition from given MySQL column definition."