From 7ccbb45763d17a99a252e400f98d1a6dec3dcb89 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 3 Feb 2015 13:39:09 +0100 Subject: [PATCH] Be smarter about MS SQL bit to boolean conversion, should fix #162. This is a blind patch given that I couldn't CREATE TABLE as per the bug report to try and see by myself what's happening. Better have some tests going on though. --- src/sources/mssql/mssql-cast-rules.lisp | 3 ++- src/utils/transforms.lisp | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sources/mssql/mssql-cast-rules.lisp b/src/sources/mssql/mssql-cast-rules.lisp index 677aae2..ba73eee 100644 --- a/src/sources/mssql/mssql-cast-rules.lisp +++ b/src/sources/mssql/mssql-cast-rules.lisp @@ -11,7 +11,8 @@ (:source (:type "nvarchar") :target (:type "text" :drop-typemod t)) (:source (:type "xml") :target (:type "text" :drop-typemod t)) - (:source (:type "bit") :target (:type "boolean")) + (:source (:type "bit") :target (:type "boolean") + :using pgloader.transforms::sql-server-bit-to-boolean) (:source (:type "uniqueidentifier") :target (:type "uuid") :using pgloader.transforms::sql-server-uniqueidentifier-to-uuid) diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index 8e4abda..42b95ce 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -22,7 +22,8 @@ right-trim byte-vector-to-bytea sqlite-timestamp-to-timestamp - sql-server-uniqueidentifier-to-uuid)) + sql-server-uniqueidentifier-to-uuid + sql-server-bit-to-boolean)) ;;; @@ -252,3 +253,15 @@ (format nil "~d-~2,'0d-~2,'0d ~2,'0d:~2,'0d:~2,'0dZ" year month date hour minute second))))) + +(defun sql-server-bit-to-boolean (bit-string-or-integer) + "We might receive bits as '((0))'" + (typecase bit-string-or-integer + (integer (if (= 0 bit-string-or-integer) "f" "t")) + (string + (cond ((string= "0" bit-string-or-integer) "f") + ((string= "1" bit-string-or-integer) "t") + ((string= "((0))" bit-string-or-integer) "f") + ((string= "((1))" bit-string-or-integer) "t") + (t nil))))) +