1 /* psycopg.h - definitions for the psycopg python module
3 * Copyright (C) 2003 Federico Di Gregorio <fog@debian.org>
5 * This file is part of psycopg.
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.
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.
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.
31 /* DBAPI compliance parameters */
32 #define APILEVEL "2.0"
33 #define THREADSAFETY 2
34 #define PARAMSTYLE "pyformat"
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)
44 /* Total number of C API pointers */
45 #define PSYCOPG_API_pointers 2
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;
52 /* global excpetions */
53 extern PyObject *Error, *Warning, *InterfaceError, *DatabaseError,
54 *InternalError, *OperationalError, *ProgrammingError,
55 *IntegrityError, *DataError, *NotSupportedError;
57 /* python versions and compatibility stuff */
58 #ifndef PyMODINIT_FUNC
59 #define PyMODINIT_FUNC void
63 /** This section is used in modules that use psycopg's C API **/
65 static void **PSYCOPG_API;
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])
74 /* Return -1 and set exception on error, 0 on success. */
78 PyObject *module = PyImport_ImportModule("psycopg");
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);
92 /* postgresql<->python encoding map */
93 extern PyObject *psycoEncodings;
100 /* the Decimal type, used by the DECIMAL typecaster */
101 extern PyObject *decimalType;
103 /* some utility functions */
104 extern void psyco_set_error(PyObject *exc, PyObject *curs, char *msg,
105 char *pgerror, char *pgcode);
107 /* Exceptions docstrings */
109 "Base class for error exceptions."
111 #define Warning_doc \
112 "A database warning."
114 #define InterfaceError_doc \
115 "Error related to the database interface."
117 #define DatabaseError_doc \
118 "Error related to the database engine."
120 #define InternalError_doc \
121 "The database encountered an internal error."
123 #define OperationalError_doc \
124 "Error related to database operation (disconnect, memory allocation etc)."
126 #define ProgrammingError_doc \
127 "Error related to database programming (SQL error, table not found etc)."
129 #define IntegrityError_doc \
130 "Error related to database integrity."
132 #define DataError_doc \
133 "Error related to problems with the processed data."
135 #define NotSupportedError_doc \
136 "A not supported datbase API was called."
142 #endif /* !defined(PSYCOPG_H) */