From 1461cda1c09762755be4c286dd877986a0827d58 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sun, 2 Mar 2014 22:44:06 +0100 Subject: [PATCH] Improve MySQL encoding errors handling. When it's not possible to decode a MySQL value in the proper given encoding, automatically replace the value with nil and be quite verbose about it by logging an error. --- src/sources/mysql.lisp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/sources/mysql.lisp b/src/sources/mysql.lisp index 1a76afd..690df21 100644 --- a/src/sources/mysql.lisp +++ b/src/sources/mysql.lisp @@ -72,9 +72,17 @@ (funcall process-row-fn row)))) (handler-bind ((babel-encodings:character-decoding-error - #'(lambda (e) + #'(lambda (c) (pgstate-incf *state* (target mysql) :errs 1) - (log-message :error "~a" e)))) + (let ((encoding (babel-encodings:character-coding-error-encoding c)) + (position (babel-encodings:character-coding-error-position c)) + (character + (aref (babel-encodings:character-decoding-error-octets c) + (babel-encodings:character-coding-error-position c)))) + (log-message :error + "~a: Illegal ~a character starting at position ~a: ~a." + table-name encoding position character)) + (invoke-restart 'qmynd-impl::use-nil)))) (mysql-query sql :row-fn row-fn :result-type 'vector)))))) ;;;