Force column ordering in SQLite support.

In the case of targetting an already existing PostgreSQL database,
columns might have been reordered. Add the column name list to the COPY
command we send so that we figure the mapping out automatically.

Fixes #509.
This commit is contained in:
Dimitri Fontaine 2017-01-28 17:45:33 +01:00
parent b54ca576cb
commit ddda2f92ca

View File

@ -57,8 +57,11 @@
(defmethod map-rows ((sqlite copy-sqlite) &key process-row-fn) (defmethod map-rows ((sqlite copy-sqlite) &key process-row-fn)
"Extract SQLite data and call PROCESS-ROW-FN function with a single "Extract SQLite data and call PROCESS-ROW-FN function with a single
argument (a list of column values) for each row" argument (a list of column values) for each row"
(let ((sql (format nil "SELECT * FROM ~a" (table-source-name (source sqlite)))) (let* ((table-name (table-source-name (source sqlite)))
(pgtypes (map 'vector #'column-type-name (columns sqlite)))) (cols (mapcar #'coldef-name (fields sqlite)))
(sql (format nil "SELECT ~{`~a`~^, ~} FROM `~a`;" cols table-name))
(pgtypes (map 'vector #'column-type-name (columns sqlite))))
(log-message :sql "SQLite: ~a" sql)
(with-connection (*sqlite-db* (source-db sqlite)) (with-connection (*sqlite-db* (source-db sqlite))
(let* ((db (conn-handle *sqlite-db*)) (let* ((db (conn-handle *sqlite-db*))
(encoding (sqlite-encoding db))) (encoding (sqlite-encoding db)))
@ -89,6 +92,10 @@
(log-message :error "~a" e) (log-message :error "~a" e)
(update-stats :data (target sqlite) :errs 1))))))) (update-stats :data (target sqlite) :errs 1)))))))
(defmethod copy-column-list ((sqlite copy-sqlite))
"Send the data in the SQLite column ordering."
(mapcar #'apply-identifier-case (mapcar #'coldef-name (fields sqlite))))
(defmethod fetch-metadata (sqlite catalog (defmethod fetch-metadata (sqlite catalog
&key &key
materialize-views materialize-views