From b538539fb31eb917716f4cb03ea18e6646583db9 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Fri, 25 Jul 2014 18:40:46 +0200 Subject: [PATCH] Handle errors when processing data from SQLite. Some errors could be related to encoding issues, as in #99. --- src/sources/sqlite.lisp | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/sources/sqlite.lisp b/src/sources/sqlite.lisp index 544f161..41f94c7 100644 --- a/src/sources/sqlite.lisp +++ b/src/sources/sqlite.lisp @@ -165,24 +165,29 @@ (string-equal "bytea" (cast (coldef-type field)))) (fields sqlite)) 'vector))) - (loop - with statement = (sqlite:prepare-statement (db sqlite) sql) - with len = (loop :for name :in (sqlite:statement-column-names statement) - :count name) - while (sqlite:step-statement statement) - for row = (let ((v (make-array len))) - (loop :for x :below len - :for raw := (sqlite:statement-column-value statement x) - :for val := (if (and (aref blobs-p x) (stringp raw)) - (base64:base64-string-to-usb8-array raw) - raw) - :do (setf (aref v x) val)) - v) - counting t into rows - do (funcall process-row-fn row) - finally - (sqlite:finalize-statement statement) - (return rows)))) + (handler-case + (loop + with statement = (sqlite:prepare-statement (db sqlite) sql) + with len = (loop :for name :in (sqlite:statement-column-names statement) + :count name) + while (sqlite:step-statement statement) + for row = (let ((v (make-array len))) + (loop :for x :below len + :for raw := (sqlite:statement-column-value statement x) + :for val := (if (and (aref blobs-p x) (stringp raw)) + (base64:base64-string-to-usb8-array raw) + raw) + :do (setf (aref v x) val)) + v) + counting t into rows + do (funcall process-row-fn row) + finally + (sqlite:finalize-statement statement) + (return rows)) + (condition (e) + (progn + (log-message :error "~a" e) + (pgstate-incf *state* (target sqlite) :errs 1)))))) (defmethod copy-to-queue ((sqlite copy-sqlite) queue)