From 1bdc0ee5f4e6e0ad02e14be916713e660c5c2b79 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sat, 9 May 2020 23:55:59 +0200 Subject: [PATCH] Allow SQLite type names such as "double precision". The parsing of the type names from the SQLite catalogs needs to allow for names with spaces in them, because SQLite allows that too. Fixes #921. --- src/parsers/parse-sqlite-type-name.lisp | 21 ++++++++++++++------- src/sources/sqlite/sqlite-cast-rules.lisp | 3 +++ test/sqlite/sqlite.db | Bin 114688 -> 118784 bytes 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/parsers/parse-sqlite-type-name.lisp b/src/parsers/parse-sqlite-type-name.lisp index cfa9fb2..8143371 100644 --- a/src/parsers/parse-sqlite-type-name.lisp +++ b/src/parsers/parse-sqlite-type-name.lisp @@ -31,20 +31,27 @@ (defrule sqlite-typemod (or sqlite-double-typemod sqlite-single-typemod)) -(defrule sqlite-type-name (and (* extra-qualifiers) - (+ (or (alpha-char-p character) #\_)) +;; type names may be "double quoted", such as "double precision" +(defrule sqlite-type-name (or (+ (and (not extra-qualifiers) + (+ (or (alpha-char-p character) #\_)) + (? " ")))) + (:text t)) + +(defrule sqlite-type-expr (and (* extra-qualifiers) + sqlite-type-name (* extra-qualifiers) ignore-whitespace (? sqlite-typemod) ignore-whitespace (* extra-qualifiers)) - (:lambda (tn) (list (text (second tn)) - (fifth tn) - (remove-if #'null - (append (first tn) (third tn) (seventh tn)))))) + (:lambda (tn) + (list (text (second tn)) + (fifth tn) + (remove-if #'null + (append (first tn) (third tn) (seventh tn)))))) (defun parse-sqlite-type-name (type-name) (if (string= type-name "") ;; yes SQLite allows for empty type names "text" - (values-list (parse 'sqlite-type-name (string-downcase type-name))))) + (values-list (parse 'sqlite-type-expr (string-downcase type-name))))) diff --git a/src/sources/sqlite/sqlite-cast-rules.lisp b/src/sources/sqlite/sqlite-cast-rules.lisp index e162a5a..0192a66 100644 --- a/src/sources/sqlite/sqlite-cast-rules.lisp +++ b/src/sources/sqlite/sqlite-cast-rules.lisp @@ -35,6 +35,9 @@ (:source (:type "double") :target (:type "double precision") :using pgloader.transforms::float-to-string) + (:source (:type "double precision") :target (:type "double precision") + :using pgloader.transforms::float-to-string) + (:source (:type "numeric") :target (:type "numeric" :drop-typemod nil) :using pgloader.transforms::float-to-string) diff --git a/test/sqlite/sqlite.db b/test/sqlite/sqlite.db index bbe1f5fdb7d0bed865d271ae27567d4b6ee1cfa7..ff6df4ee1894be5aa142c01f68cd5055c2000c4a 100644 GIT binary patch delta 174 zcmZo@U~gE!K0#X0nt_2q7KmX$WulHTk2Qmyi2^V8KL$~b?1|Z$OdQ!87hYxe_7r6k zmy~48FG)vE