From eb52183ddb786552d5abf6fdfaaca657e0c56ea0 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Mon, 16 Oct 2006 19:07:38 +0000 Subject: [PATCH] r11228: * db-postgresql/postgresql-{package,api,sql}.lisp: Apply changes from Andew Golding to use a more-specific error code from PostgreSQL than the generic fatal error code of the result set. --- ChangeLog | 4 +++ db-postgresql/postgresql-api.lisp | 35 +++++++++++++++++++++++++++ db-postgresql/postgresql-package.lisp | 5 ++++ db-postgresql/postgresql-sql.lisp | 2 +- debian/changelog | 6 +++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 685df98..1ea6770 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 16 Oct 2006 Kevin Rosenberg + * Version 3.7.5 * doc/intro.xml: Update supported platforms. + * db-postgresql/postgresql-{package,api,sql}.lisp: Apply + changes from Andew Golding to use a more-specific error code + from PostgreSQL than the generic fatal error code of the result set. 03 Oct 2006 Kevin Rosenberg * sql/syntax.lisp: Commit patch from Marcus Pearce to improve diff --git a/db-postgresql/postgresql-api.lisp b/db-postgresql/postgresql-api.lisp index 6f4908f..b006bf6 100644 --- a/db-postgresql/postgresql-api.lisp +++ b/db-postgresql/postgresql-api.lisp @@ -105,6 +105,41 @@ :module "postgresql" :returning pgsql-exec-status-type) +; From postgres_ext.h + +; #define PG_DIAG_SEVERITY 'S' +; #define PG_DIAG_SQLSTATE 'C' +; #define PG_DIAG_MESSAGE_PRIMARY 'M' +; #define PG_DIAG_MESSAGE_DETAIL 'D' +; #define PG_DIAG_MESSAGE_HINT 'H' +; #define PG_DIAG_STATEMENT_POSITION 'P' +; #define PG_DIAG_INTERNAL_POSITION 'p' +; #define PG_DIAG_INTERNAL_QUERY 'q' +; #define PG_DIAG_CONTEXT 'W' +; #define PG_DIAG_SOURCE_FILE 'F' +; #define PG_DIAG_SOURCE_LINE 'L' +; #define PG_DIAG_SOURCE_FUNCTION 'R' +(defconstant +PG-DIAG-SEVERITY+ (char-code #\S)) +(defconstant +PG-DIAG-SQLSTATE+ (char-code #\C)) +(defconstant +PG-DIAG-MESSAGE-PRIMARY+ (char-code #\M)) +(defconstant +PG-DIAG-MESSAGE-DETAIL+ (char-code #\D)) +(defconstant +PG-DIAG-MESSAGE-HINT+ (char-code #\H)) +(defconstant +PG-DIAG-STATEMENT-POSITION+ (char-code #\P)) +(defconstant +PG-DIAG-INTERNAL-POSITION+ (char-code #\p)) +(defconstant +PG-DIAG-INTERNAL-QUERY+ (char-code #\q)) +(defconstant +PG-DIAG-CONTEXT+ (char-code #\W)) +(defconstant +PG-DIAG-SOURCE-FILE+ (char-code #\F)) +(defconstant +PG-DIAG-SOURCE-LINE+ (char-code #\L)) +(defconstant +PG-DIAG-SOURCE-FUNCTION+ (char-code #\R)) + +; PQresultErrorField can return diagnostic information about an error +(declaim (inline PQresultErrorField)) +(uffi:def-function ("PQresultErrorField" PQresultErrorField) + ((res pgsql-result) + (field-code :int)) + :module "postgresql" + :returning (* char)) + (declaim (inline PQresultErrorMessage)) (uffi:def-function ("PQresultErrorMessage" PQresultErrorMessage) ((res pgsql-result)) diff --git a/db-postgresql/postgresql-package.lisp b/db-postgresql/postgresql-package.lisp index 32ea77d..080eaf9 100644 --- a/db-postgresql/postgresql-package.lisp +++ b/db-postgresql/postgresql-package.lisp @@ -44,6 +44,10 @@ #:pgsql-ftype#int8 #:pgsql-ftype#float4 #:pgsql-ftype#float8 + + ;; Used by PQresultErrorField to get the sql error code + #:+PG-DIAG-SQLSTATE+ + ;; Functions #:PQsetdbLogin @@ -53,6 +57,7 @@ #:PQerrorMessage #:PQexec #:PQresultStatus + #:PQresultErrorField ; used to grab the SQLSTATE code from an error #:PQresultErrorMessage #:PQntuples #:PQnfields diff --git a/db-postgresql/postgresql-sql.lisp b/db-postgresql/postgresql-sql.lisp index d5a13f2..2d74fc1 100644 --- a/db-postgresql/postgresql-sql.lisp +++ b/db-postgresql/postgresql-sql.lisp @@ -222,7 +222,7 @@ (error 'sql-database-data-error :database database :expression sql-expression - :error-id (PQresultStatus result) + :error-id (uffi:convert-from-foreign-string (PQresultErrorField result +PG-DIAG-SQLSTATE+)) :message (tidy-error-message (PQresultErrorMessage result))))) (PQclear result)))))) diff --git a/debian/changelog b/debian/changelog index 6b59a0a..f519bf4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cl-sql (3.7.5-1) unstable; urgency=low + + * New upstream + + -- Kevin M. Rosenberg Mon, 16 Oct 2006 13:05:53 -0600 + cl-sql (3.7.4-1) unstable; urgency=low * New upstream -- 2.34.1