From 460fe6cc77c2f15a791c4ab78f1323efa875ad8f Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 19 Sep 2017 11:29:53 +0200 Subject: [PATCH] Fix quoting of default values for MariaDB 10 support. The default values quoting changed in MariaDB 10, and we need to adjust in pgloader: extra '' chars could defeat the default matching logic: "'0000-00-00'" is different from "0000-00-00" --- src/sources/mysql/mysql-schema.lisp | 2 +- src/utils/quoting.lisp | 12 ++++++++---- test/mysql/my.sql | 13 +++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/sources/mysql/mysql-schema.lisp b/src/sources/mysql/mysql-schema.lisp index 8559ccd..f0ef665 100644 --- a/src/sources/mysql/mysql-schema.lisp +++ b/src/sources/mysql/mysql-schema.lisp @@ -70,7 +70,7 @@ (when default (babel:string-to-octets default))) - (t default))) + (t (ensure-unquoted default #\')))) (defun list-all-columns (schema &key diff --git a/src/utils/quoting.lisp b/src/utils/quoting.lisp index d52702d..1b63c0a 100644 --- a/src/utils/quoting.lisp +++ b/src/utils/quoting.lisp @@ -44,11 +44,15 @@ (defun quoted-p (s &optional (quote-char #\")) "Return true if s is a double-quoted string" - (and (eq (char s 0) quote-char) - (eq (char s (- (length s) 1)) quote-char))) + (or (null s) + (when (< 1 (length s)) + (and (eq (char s 0) quote-char) + (eq (char s (- (length s) 1)) quote-char))))) -(defun ensure-unquoted (identifier) - (cond ((quoted-p identifier) +(defun ensure-unquoted (identifier &optional (quote-char #\")) + (cond ((null identifier) nil) + ((< (length identifier) 2) identifier) + ((quoted-p identifier quote-char) ;; when the table name comes from the user (e.g. in the ;; load file) then we might have to unquote it: the ;; PostgreSQL catalogs does not store object names in diff --git a/test/mysql/my.sql b/test/mysql/my.sql index 13054cf..4401508 100644 --- a/test/mysql/my.sql +++ b/test/mysql/my.sql @@ -1,5 +1,18 @@ create table `empty`(id integer auto_increment primary key); +CREATE TABLE `races` ( + `raceId` int(11) NOT NULL AUTO_INCREMENT, + `year` int(11) NOT NULL DEFAULT 0, + `round` int(11) NOT NULL DEFAULT 0, + `circuitId` int(11) NOT NULL DEFAULT 0, + `name` varchar(255) NOT NULL DEFAULT '', + `date` date NOT NULL DEFAULT '0000-00-00', + `time` time DEFAULT NULL, + `url` varchar(255) DEFAULT NULL, + PRIMARY KEY (`raceId`), + UNIQUE KEY `url` (`url`) +) ENGINE=MyISAM AUTO_INCREMENT=989 DEFAULT CHARSET=utf8; + CREATE TABLE `utilisateurs__Yvelines2013-06-28` ( `statut` enum('administrateur','odis','pilote','bureau','relais','stagiaire','membre','participant','contact') COLLATE utf8_unicode_ci NOT NULL, `anciennete` year(4) DEFAULT NULL,