From 3a55d804116324462743cae3a9541d55ea3b0dfd Mon Sep 17 00:00:00 2001 From: Aliaksei Urbanski Date: Mon, 13 Jul 2015 12:55:33 +0000 Subject: [PATCH] Default cast rules for MySQL's text types fixed, see #219 --- src/sources/mysql/mysql-cast-rules.lisp | 16 ++++++++++------ src/utils/transforms.lisp | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/sources/mysql/mysql-cast-rules.lisp b/src/sources/mysql/mysql-cast-rules.lisp index 1c552dc..e7a88a0 100644 --- a/src/sources/mysql/mysql-cast-rules.lisp +++ b/src/sources/mysql/mysql-cast-rules.lisp @@ -92,14 +92,18 @@ :target (:type "decimal" :drop-typemod nil)) ;; the text based types - (:source (:type "varchar") :target (:type "text")) - (:source (:type "tinytext") :target (:type "text")) - (:source (:type "text") :target (:type "text")) - (:source (:type "mediumtext") :target (:type "text")) - (:source (:type "longtext") :target (:type "text")) + (:source (:type "tinytext") :target (:type "text") :using pgloader.transforms::remove-null-characters) + (:source (:type "text") :target (:type "text") :using pgloader.transforms::remove-null-characters) + (:source (:type "mediumtext") :target (:type "text") :using pgloader.transforms::remove-null-characters) + (:source (:type "longtext") :target (:type "text") :using pgloader.transforms::remove-null-characters) + + (:source (:type "varchar") + :target (:type "varchar" :drop-typemod nil) + :using pgloader.transforms::remove-null-characters) (:source (:type "char") - :target (:type "varchar" :drop-typemod nil)) + :target (:type "char" :drop-typemod nil) + :using pgloader.transforms::remove-null-characters) ;; ;; cl-mysql returns binary values as a simple-array of bytes (as in diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index fd6ae9b..743a9fc 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -212,6 +212,11 @@ (when string (string-right-trim '(#\Space) string))) +(defun remove-null-characters (string) + "Remove NULL-characters (0x00) from STRING" + (when string + (remove #\Nul string))) + (defun byte-vector-to-bytea (vector) "Transform a simple array of unsigned bytes to the PostgreSQL bytea representation as documented at