diff --git a/src/sources/mysql-schema.lisp b/src/sources/mysql-schema.lisp index 6805e20..0eb8c02 100644 --- a/src/sources/mysql-schema.lisp +++ b/src/sources/mysql-schema.lisp @@ -310,8 +310,10 @@ GROUP BY table_name, index_name;" dbname)) (:point (format nil "astext(`~a`) as `~a`" name name)) (t (format nil "`~a`" name)))) -(defun get-column-list-with-is-nulls (dbname table-name) - "We can't just SELECT *, we need to cater for NULLs in text columns ourselves. +(defun get-column-list (dbname table-name) + "Some MySQL datatypes have a meaningless default output representation, we + need to process them on the SQL side (geometric data types). + This function assumes a valid connection to the MySQL server has been established already." (loop @@ -321,14 +323,7 @@ GROUP BY table_name, index_name;" dbname)) where table_schema = '~a' and table_name = '~a' order by ordinal_position" dbname table-name) :result-type 'list) - for is-null = (member type '("char" "varchar" "text" - "tinytext" "mediumtext" "longtext") - :test #'string-equal) - collect nil into nulls - collect (get-column-sql-expression name type) into cols - when is-null - collect (format nil "`~a` is null" name) into cols and collect t into nulls - finally (return (values cols nulls)))) + collect (get-column-sql-expression name type))) (declaim (inline fix-nulls)) diff --git a/src/sources/mysql.lisp b/src/sources/mysql.lisp index e16f476..71dfd39 100644 --- a/src/sources/mysql.lisp +++ b/src/sources/mysql.lisp @@ -54,19 +54,18 @@ (mysql-query "SET NAMES 'utf8'") (mysql-query "SET character_set_results = utf8;") - (multiple-value-bind (cols nulls) - (get-column-list-with-is-nulls dbname table-name) - (let* ((sql (format nil "SELECT ~{~a~^, ~} FROM ~a;" cols table-name)) - (row-fn - (lambda (row) - (pgstate-incf *state* (target mysql) :read 1) - (funcall process-row-fn (fix-nulls row nulls))))) - (handler-bind - ((babel-encodings:character-decoding-error - #'(lambda (e) - (pgstate-incf *state* (target mysql) :errs 1) - (log-message :error "~a" e)))) - (mysql-query sql :row-fn row-fn))))))) + (let* ((cols (get-column-list dbname table-name)) + (sql (format nil "SELECT ~{~a~^, ~} FROM ~a;" cols table-name)) + (row-fn + (lambda (row) + (pgstate-incf *state* (target mysql) :read 1) + (funcall process-row-fn row)))) + (handler-bind + ((babel-encodings:character-decoding-error + #'(lambda (e) + (pgstate-incf *state* (target mysql) :errs 1) + (log-message :error "~a" e)))) + (mysql-query sql :row-fn row-fn)))))) ;;; ;;; Use map-rows and pgsql-text-copy-format to fill in a CSV file on disk @@ -125,7 +124,10 @@ (loop for tasks below 2 do (lp:receive-result channel) finally (log-message :info "COPY ~a.~a done." dbname table-name) - (unless k-s-p (lp:end-kernel)))))) + (unless k-s-p (lp:end-kernel)))) + + ;; return the copy-mysql object we just did the COPY for + mysql)) ;;;