Cast MySQL default values in some cases, fixing #124.

When querying the default values of MySQL tables against MySQL catalogs,
the default value is always returned as a string. When the column having
the default actually is a "binary" column, we want the transformation
functions to receive a proper vector of bytes.

This patch adds some hard-coded rules to be smarted about the situation
for columns of type "binary".
This commit is contained in:
Dimitri Fontaine 2014-11-22 00:04:34 +01:00
parent 5b87b1a85e
commit 5ce92492ce
2 changed files with 15 additions and 6 deletions

View File

@ -431,8 +431,8 @@
"Returns suitably quoted default value for CREATE TABLE command."
(cond
((null default) "NULL")
((string= "NULL" default) default)
((string= "CURRENT_TIMESTAMP" default) default)
((and (stringp default) (string= "NULL" default)) default)
((and (stringp default) (string= "CURRENT_TIMESTAMP" default)) default)
(t
;; apply the transformation function to the default value
(if using-cast-fn (format-pgsql-default-value

View File

@ -159,6 +159,15 @@ order by table_name" dbname only-tables))))
(cons (format nil "~:[~;NOT ~]REGEXP '~a'" not (cadr filter)))))
filter-list))
(defun cleanup-default-value (dtype default)
"MySQL catalog query always returns the default value as a string, but in
the case of a binary data type we actually want a byte vector."
(cond ((string= "binary" dtype)
(when default
(babel:string-to-octets default)))
(t default)))
(defun list-all-columns (&key
(dbname *my-dbname*)
(table-type :table)
@ -192,10 +201,10 @@ order by table_name, ordinal_position"
excluding ; do we print the clause?
(filter-list-to-where-clause excluding t)))
do
(let ((entry (assoc table-name schema :test 'equal))
(column
(make-mysql-column
table-name name dtype ctype default nullable extra)))
(let* ((entry (assoc table-name schema :test 'equal))
(def-val (cleanup-default-value dtype default))
(column (make-mysql-column
table-name name dtype ctype def-val nullable extra)))
(if entry
(push column (cdr entry))
(push (cons table-name (list column)) schema)))