X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=db-postgresql%2Fpostgresql-api.lisp;h=c0b8a000edd9e2ac75eb61b579cab6758426d5f9;hp=f7ca3610a66770d8998df805b077f8b6493b8d1f;hb=d2d49ab13c98bc7a1819a0fd3968268a5567bdc3;hpb=7d50938ba2db52a713498e49aa1679deae6f0b6b diff --git a/db-postgresql/postgresql-api.lisp b/db-postgresql/postgresql-api.lisp index f7ca361..c0b8a00 100644 --- a/db-postgresql/postgresql-api.lisp +++ b/db-postgresql/postgresql-api.lisp @@ -4,12 +4,10 @@ ;;;; ;;;; Name: postgresql.cl ;;;; Purpose: Low-level PostgreSQL interface using UFFI -;;;; Programmers: Kevin M. Rosenberg based on -;;;; Original code by Pierre R. Mai +;;;; Programmers: Kevin M. Rosenberg based on +;;;; Original code by Pierre R. Mai ;;;; Date Started: Feb 2002 ;;;; -;;;; $Id: postgresql-api.lisp,v 1.1 2002/09/30 10:19:23 kevin Exp $ -;;;; ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai ;;;; @@ -18,8 +16,7 @@ ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL. ;;;; ************************************************************************* -(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0))) -(in-package :postgresql) +(in-package #:pgsql) ;;;; This file implements as little of the FFI bindings to the @@ -36,7 +33,7 @@ (uffi:def-foreign-type pgsql-oid :unsigned-int) -(uffi:def-enum pgsql-conn-status-type +(uffi:def-enum pgsql-conn-status-type (:connection-ok :connection-bad)) @@ -53,6 +50,8 @@ (uffi:def-foreign-type pgsql-conn :pointer-void) (uffi:def-foreign-type pgsql-result :pointer-void) +(uffi:def-type pgsql-conn-ptr :pointer-void) + (uffi:def-enum pgsql-ftype ((:bytea 17) (:int2 21) @@ -60,7 +59,7 @@ (:int8 20) (:float4 700) (:float8 701))) - + ;;(declaim (inline PQsetdbLogin)) ;; causes compile error in LW 4.2.0 (uffi:def-function ("PQsetdbLogin" PQsetdbLogin) ((pghost :cstring) @@ -70,6 +69,7 @@ (dbName :cstring) (login :cstring) (pwd :cstring)) + :module "postgresql" :returning pgsql-conn) (declaim (inline PQfinish)) @@ -103,6 +103,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 :cstring) + (declaim (inline PQresultErrorMessage)) (uffi:def-function ("PQresultErrorMessage" PQresultErrorMessage) ((res pgsql-result)) @@ -110,7 +145,7 @@ :returning :cstring) (declaim (inline PQntuples)) -(uffi:def-function ("PQntuples" PQntuples) +(uffi:def-function ("PQntuples" PQntuples) ((res pgsql-result)) :module "postgresql" :returning :int)