Improve error handling for MS SQL.

In particular, implement more solid handling of poorly encoded data or
badly setup connections, by reporting the error and continuing the load.
This commit is contained in:
Dimitri Fontaine 2017-01-28 17:47:44 +01:00
parent ddda2f92ca
commit a799cd5f5f

View File

@ -34,19 +34,33 @@
(schema-source-name (table-schema (source mssql)))
(table-source-name (source mssql)))))
(log-message :debug "~a" sql)
(handler-case
(handler-bind
((condition
#'(lambda (c)
(log-message :error "~a" c)
(update-stats :data (target mssql) :errs 1))))
(mssql::map-query-results sql
:row-fn process-row-fn
:connection (conn-handle *mssql-db*)))
(condition (e)
(progn
(log-message :error "~a" e)
(update-stats :data (target mssql) :errs 1)))))))
(handler-bind
((babel-encodings:end-of-input-in-character
#'(lambda (c)
(update-stats :data (target mssql) :errs 1)
(log-message :error "~a" c)
(invoke-restart 'mssql::use-nil)))
(babel-encodings:character-decoding-error
#'(lambda (c)
(update-stats :data (target mssql) :errs 1)
(let ((encoding
(babel-encodings:character-coding-error-encoding c))
(position
(babel-encodings:character-coding-error-position c))
(character
(aref (babel-encodings:character-coding-error-buffer c)
(babel-encodings:character-coding-error-position c))))
(log-message :error
"~a: Illegal ~a character starting at position ~a: ~a."
(table-schema (source mssql))
encoding
position
character))
(invoke-restart 'mssql::use-nil))))
(mssql::map-query-results sql
:row-fn process-row-fn
:connection (conn-handle *mssql-db*))))))
(defmethod fetch-metadata ((mssql copy-mssql)
(catalog catalog)