From b7d87a9eb13ca79e890a832f5f9af35854e19bfa Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sun, 3 Dec 2017 23:06:54 +0100 Subject: [PATCH] Fix MySQL bit(1) casting function. When this function was written, pgloader would get an array of numbers over the wire, nowadays it looks like it's receiving an array of characters instead (in other words, a string). Improve the `bits-to-boolean` function to accept either input, and raise an error in another case. My theory is that something changed either in MySQL (with version 10) or in the Qmynd driver somehow... but tonight we just go easy and fix the bug locally rather than try and understand where it might be coming from. Fixes #684. --- src/utils/transforms.lisp | 8 +++++++- test/mysql/my.sql | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index dff12d1..7dfa473 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -145,7 +145,13 @@ "When using MySQL, strange things will happen, like encoding booleans into bit(1). Of course PostgreSQL wants 'f' and 't'." (when (and bit-vector (= 1 (length bit-vector))) - (if (= 0 (aref bit-vector 0)) "f" "t"))) + (let ((bit (aref bit-vector 0))) + ;; we might have either a char or a number here, see issue #684. + ;; current guess when writing the code is that it depends on MySQL + ;; version, but this has not been checked. + (etypecase bit + (fixnum (if (= 0 bit) "f" "t")) + (character (if (= 0 (char-code bit)) "f" "t")))))) (defun int-to-ip (int) "Transform an IP as integer into its dotted notation, optimised code from diff --git a/test/mysql/my.sql b/test/mysql/my.sql index ab12fc3..44234f1 100644 --- a/test/mysql/my.sql +++ b/test/mysql/my.sql @@ -89,6 +89,17 @@ CREATE TABLE pgloader_test_unsigned ); INSERT INTO pgloader_test_unsigned(id) VALUES (65535); +/* + * https://github.com/dimitri/pgloader/issues/684 + */ +create table bits + ( + id integer not null AUTO_INCREMENT primary key, + bool bit(1) + ); + +insert into bits(bool) values(0b00), (0b01); + CREATE TABLE `fcm_batches` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `raw_payload` mediumtext COLLATE utf8_unicode_ci,