From 1273c42393e18ec4326a770506ce3c83e6a07955 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Wed, 4 Jun 2014 11:11:50 +0200 Subject: [PATCH] Parse SQLite "unsigned" and "short" noise words, fix #72. In SQLite it's possible to define columns using type names such as "smallint unsigned" or "short integer", without any changes to the way those data types are handled, given its "dynamic typing" features. Improve the pgloader casting machinery for SQLite to handle those cases. --- src/sources/sqlite.lisp | 18 ++++++++++++------ test/sqlite/sqlite.db | Bin 40960 -> 45056 bytes 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/sources/sqlite.lisp b/src/sources/sqlite.lisp index d38593a..d4e7d7a 100644 --- a/src/sources/sqlite.lisp +++ b/src/sources/sqlite.lisp @@ -16,14 +16,20 @@ (defun cast (sqlite-type-name) "Return the PostgreSQL type name for a given SQLite type name." - (cond ((and (<= 8 (length sqlite-type-name)) - (string-equal sqlite-type-name "nvarchar" :end1 8)) "text") + (let* ((tokens (remove-if (lambda (token) + (member token '("unsigned" "short") + :test #'string-equal)) + (sq:split-sequence #\Space sqlite-type-name))) + (sqlite-type-name (first tokens))) + (assert (= 1 (length tokens))) + (cond ((and (<= 8 (length sqlite-type-name)) + (string-equal sqlite-type-name "nvarchar" :end1 8)) "text") - ((string-equal sqlite-type-name "datetime") "timestamptz") - ((string-equal sqlite-type-name "double") "double precision") - ((string-equal sqlite-type-name "blob") "bytea") + ((string-equal sqlite-type-name "datetime") "timestamptz") + ((string-equal sqlite-type-name "double") "double precision") + ((string-equal sqlite-type-name "blob") "bytea") - (t sqlite-type-name))) + (t sqlite-type-name)))) (defmethod format-pgsql-column ((col coldef) &key identifier-case) "Return a string representing the PostgreSQL column definition." diff --git a/test/sqlite/sqlite.db b/test/sqlite/sqlite.db index 53ebc3e5b9cde30a62b7c8e1bb420b442b9781dd..76b98bb1597e1ece57f217ec0ee82aea64ab0d1c 100644 GIT binary patch delta 226 zcmZoTz|`=7X@ayMCj$cmHxR=B%S0VxVNM3!N2 delta 57 zcmZp8z|?SnX@ayM8v_Fa7ZAe$(?lI(prGy}RbHSF6Mr59|8D-g&4L2|_%`S9PnrM# DB<2gV