From ae63c9b85cc2ff0bb9de6b5f781f3f17b5a32097 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Wed, 28 May 2014 17:23:08 +0200 Subject: [PATCH] Improve COPY CONTEXT message parsing, fix #67. When adding the CONTEXT message parsing I totally forgot that PostgreSQL provides a nice error message translation capability. The code now copes better with the situation, using a more advanced regular expression. We could inline the known translations in the matching, but that would be tedious to maintain, so we just use loose matching rules here. --- src/pgsql/pgsql.lisp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pgsql/pgsql.lisp b/src/pgsql/pgsql.lisp index 781b6ba..cbf0bec 100644 --- a/src/pgsql/pgsql.lisp +++ b/src/pgsql/pgsql.lisp @@ -130,11 +130,17 @@ ;;; CONTEXT: COPY errors, line 1, column b: "2006-13-11" ;;; CONTEXT: COPY byte, line 1: "hello\0world" ;;; +;;; Those error messages are a translation target, tho, so we can only +;;; assume to recognize the command tag (COPY), the comma, and a numer after +;;; a world that might be Zeile (de), línea (es), ligne (fr), riga (it), +;;; linia (pl), linha (pt), строка (ru), 行 (zh), or something else +;;; entirely. +;;; (defun parse-copy-error-context (context) "Given a COPY command CONTEXT error message, return the batch position where the error comes from." (cl-ppcre:register-groups-bind ((#'parse-integer n)) - ("line (\\d+)" context :sharedp t) + ("COPY [^,]+, [^ ]+ (\\d+)" context :sharedp t) (1- n))) ;;; @@ -192,7 +198,8 @@ ;; the batch didn't make it, prepare error handling for next turn ((or CL-POSTGRES-ERROR:INTEGRITY-VIOLATION - CL-POSTGRES-ERROR:DATA-EXCEPTION) (next-error-in-batch) + CL-POSTGRES-ERROR:DATA-EXCEPTION) + (next-error-in-batch) (setf condition next-error-in-batch