This commit was manufactured by cvs2svn to create branch
[plcapi.git] / psycopg2 / psycopg / psycopg.h
1 /* psycopg.h - definitions for the psycopg python module 
2  *
3  * Copyright (C) 2003 Federico Di Gregorio <fog@debian.org>
4  *
5  * This file is part of psycopg.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2,
10  * or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef PSYCOPG_H
23 #define PSYCOPG_H 1
24
25 #include <Python.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /* DBAPI compliance parameters */
32 #define APILEVEL "2.0"
33 #define THREADSAFETY 2
34 #define PARAMSTYLE "pyformat"
35     
36 /* C API functions */
37 #define psyco_errors_fill_NUM 0
38 #define psyco_errors_fill_RETURN void
39 #define psyco_errors_fill_PROTO (PyObject *dict)   
40 #define psyco_errors_set_NUM 1
41 #define psyco_errors_set_RETURN void
42 #define psyco_errors_set_PROTO (PyObject *type)
43     
44 /* Total number of C API pointers */
45 #define PSYCOPG_API_pointers 2
46     
47 #ifdef PSYCOPG_MODULE
48     /** This section is used when compiling psycopgmodule.c & co. **/
49 extern psyco_errors_fill_RETURN psyco_errors_fill psyco_errors_fill_PROTO;
50 extern psyco_errors_set_RETURN psyco_errors_set psyco_errors_set_PROTO;
51
52 /* global excpetions */
53 extern PyObject *Error, *Warning, *InterfaceError, *DatabaseError,
54     *InternalError, *OperationalError, *ProgrammingError,
55     *IntegrityError, *DataError, *NotSupportedError;
56
57 /* python versions and compatibility stuff */
58 #ifndef PyMODINIT_FUNC
59 #define PyMODINIT_FUNC void
60 #endif
61     
62 #else
63     /** This section is used in modules that use psycopg's C API **/
64
65 static void **PSYCOPG_API;
66
67 #define psyco_errors_fill \
68  (*(psyco_errors_fill_RETURN (*)psyco_errors_fill_PROTO) \
69   PSYCOPG_API[psyco_errors_fill_NUM])
70 #define psyco_errors_set \
71  (*(psyco_errors_set_RETURN (*)psyco_errors_set_PROTO) \
72   PSYCOPG_API[psyco_errors_set_NUM])
73     
74 /* Return -1 and set exception on error, 0 on success. */
75 static int
76 import_psycopg(void)
77 {
78     PyObject *module = PyImport_ImportModule("psycopg");
79
80     if (module != NULL) {
81         PyObject *c_api_object = PyObject_GetAttrString(module, "_C_API");
82         if (c_api_object == NULL) return -1;
83         if (PyCObject_Check(c_api_object))
84             PSYCOPG_API = (void **)PyCObject_AsVoidPtr(c_api_object);
85         Py_DECREF(c_api_object);
86     }
87     return 0;
88 }
89
90 #endif
91
92 /* postgresql<->python encoding map */
93 extern PyObject *psycoEncodings;
94     
95 typedef struct {
96     char *pgenc;
97     char *pyenc;
98 } encodingPair;
99
100 /* the Decimal type, used by the DECIMAL typecaster */    
101 extern PyObject *decimalType;
102
103 /* some utility functions */
104 extern void psyco_set_error(PyObject *exc, PyObject *curs,  char *msg, 
105                              char *pgerror, char *pgcode);
106                                   
107 /* Exceptions docstrings */
108 #define Error_doc \
109 "Base class for error exceptions."
110
111 #define Warning_doc \
112 "A database warning."
113
114 #define InterfaceError_doc \
115 "Error related to the database interface."
116
117 #define DatabaseError_doc \
118 "Error related to the database engine."
119
120 #define InternalError_doc \
121 "The database encountered an internal error."
122
123 #define OperationalError_doc \
124 "Error related to database operation (disconnect, memory allocation etc)."
125
126 #define ProgrammingError_doc \
127 "Error related to database programming (SQL error, table not found etc)."
128
129 #define IntegrityError_doc \
130 "Error related to database integrity."
131
132 #define DataError_doc \
133 "Error related to problems with the processed data."
134
135 #define NotSupportedError_doc \
136 "A not supported datbase API was called."
137
138 #ifdef __cplusplus
139 }
140 #endif
141
142 #endif /* !defined(PSYCOPG_H) */