From 5c1c4bf3ffcf2b92d42d3f361c7abd0514959c82 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 1 Aug 2017 18:40:27 +0200 Subject: [PATCH] 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. --- src/pgsql/pgsql-ddl.lisp | 4 +++- src/sources/mysql/mysql-cast-rules.lisp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pgsql/pgsql-ddl.lisp b/src/pgsql/pgsql-ddl.lisp index 3b3e59e..81323f1 100644 --- a/src/pgsql/pgsql-ddl.lisp +++ b/src/pgsql/pgsql-ddl.lisp @@ -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~];" diff --git a/src/sources/mysql/mysql-cast-rules.lisp b/src/sources/mysql/mysql-cast-rules.lisp index a2ec843..c9766c6 100644 --- a/src/sources/mysql/mysql-cast-rules.lisp +++ b/src/sources/mysql/mysql-cast-rules.lisp @@ -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."