Allow for empty-string SQLite column types, fix #220 again.

This commit is contained in:
Dimitri Fontaine 2015-04-30 17:18:14 +02:00
parent 95a5eb3184
commit ebc0dcda4f

View File

@ -51,16 +51,19 @@
(defun normalize (sqlite-type-name) (defun normalize (sqlite-type-name)
"SQLite only has a notion of what MySQL calls column_type, or ctype in the "SQLite only has a notion of what MySQL calls column_type, or ctype in the
CAST machinery. Transform it to the data_type, or dtype." CAST machinery. Transform it to the data_type, or dtype."
(let* ((sqlite-type-name (string-downcase sqlite-type-name)) (if (string= sqlite-type-name "")
(tokens (remove-if (lambda (token) ;; yes SQLite allows for empty type names
(or (member token '("unsigned" "short" "text"
"varying" "native") (let* ((sqlite-type-name (string-downcase sqlite-type-name))
:test #'string-equal) (tokens (remove-if (lambda (token)
;; remove typemod too, as in "integer (8)" (or (member token '("unsigned" "short"
(char= #\( (aref token 0)))) "varying" "native")
(sq:split-sequence #\Space sqlite-type-name)))) :test #'string-equal)
(assert (= 1 (length tokens))) ;; remove typemod too, as in "integer (8)"
(first tokens))) (char= #\( (aref token 0))))
(sq:split-sequence #\Space sqlite-type-name))))
(assert (= 1 (length tokens)))
(first tokens))))
(defun ctype-to-dtype (sqlite-type-name) (defun ctype-to-dtype (sqlite-type-name)
"In SQLite we only get the ctype, e.g. int(7), but here we want the base "In SQLite we only get the ctype, e.g. int(7), but here we want the base