From bb2c7e4e176fa8814f363ad7329fa2c2ce1abf5f Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 28 Oct 2014 14:56:37 +0100 Subject: [PATCH] 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. --- src/sources/mysql/mysql-cast-rules.lisp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sources/mysql/mysql-cast-rules.lisp b/src/sources/mysql/mysql-cast-rules.lisp index e60ed99..4e254e0 100644 --- a/src/sources/mysql/mysql-cast-rules.lisp +++ b/src/sources/mysql/mysql-cast-rules.lisp @@ -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."