2007-04-10 10:36:18 +04:00
|
|
|
/* psycopg.h - definitions for the psycopg python module
|
2004-10-19 07:17:12 +04:00
|
|
|
*
|
2010-02-13 01:34:53 +03:00
|
|
|
* Copyright (C) 2003-2010 Federico Di Gregorio <fog@debian.org>
|
2004-10-19 07:17:12 +04:00
|
|
|
*
|
|
|
|
* This file is part of psycopg.
|
|
|
|
*
|
2010-02-13 01:34:53 +03:00
|
|
|
* psycopg2 is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2004-10-19 07:17:12 +04:00
|
|
|
*
|
2010-02-13 01:34:53 +03:00
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link this program with the OpenSSL library (or with
|
|
|
|
* modified versions of OpenSSL that use the same license as OpenSSL),
|
|
|
|
* and distribute linked combinations including the two.
|
2004-10-19 07:17:12 +04:00
|
|
|
*
|
2010-02-13 01:34:53 +03:00
|
|
|
* You must obey the GNU Lesser General Public License in all respects for
|
|
|
|
* all of the code used other than OpenSSL.
|
|
|
|
*
|
|
|
|
* psycopg2 is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
* License for more details.
|
2004-10-19 07:17:12 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PSYCOPG_H
|
|
|
|
#define PSYCOPG_H 1
|
|
|
|
|
2016-08-15 04:17:47 +03:00
|
|
|
#if PG_VERSION_NUM < 90100
|
|
|
|
#error "Psycopg requires PostgreSQL client library (libpq) >= 9.1"
|
|
|
|
#endif
|
|
|
|
|
2007-04-10 10:36:18 +04:00
|
|
|
#define PY_SSIZE_T_CLEAN
|
2004-10-19 07:17:12 +04:00
|
|
|
#include <Python.h>
|
2008-08-02 12:30:36 +04:00
|
|
|
#include <libpq-fe.h>
|
2004-10-19 07:17:12 +04:00
|
|
|
|
2008-01-21 08:54:01 +03:00
|
|
|
#include "psycopg/config.h"
|
2008-12-26 03:37:44 +03:00
|
|
|
#include "psycopg/python.h"
|
2008-01-21 08:54:01 +03:00
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* DBAPI compliance parameters */
|
|
|
|
#define APILEVEL "2.0"
|
|
|
|
#define THREADSAFETY 2
|
|
|
|
#define PARAMSTYLE "pyformat"
|
2007-04-10 10:36:18 +04:00
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
/* C API functions */
|
|
|
|
#define psyco_errors_fill_NUM 0
|
|
|
|
#define psyco_errors_fill_RETURN void
|
2007-04-10 10:36:18 +04:00
|
|
|
#define psyco_errors_fill_PROTO (PyObject *dict)
|
2004-10-19 07:17:12 +04:00
|
|
|
#define psyco_errors_set_NUM 1
|
|
|
|
#define psyco_errors_set_RETURN void
|
|
|
|
#define psyco_errors_set_PROTO (PyObject *type)
|
2007-04-10 10:36:18 +04:00
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
/* Total number of C API pointers */
|
|
|
|
#define PSYCOPG_API_pointers 2
|
2007-04-10 10:36:18 +04:00
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
#ifdef PSYCOPG_MODULE
|
2008-01-21 08:54:01 +03:00
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
/** This section is used when compiling psycopgmodule.c & co. **/
|
2008-01-21 08:54:01 +03:00
|
|
|
HIDDEN psyco_errors_fill_RETURN psyco_errors_fill psyco_errors_fill_PROTO;
|
|
|
|
HIDDEN psyco_errors_set_RETURN psyco_errors_set psyco_errors_set_PROTO;
|
2004-10-19 07:17:12 +04:00
|
|
|
|
2013-04-26 12:21:56 +04:00
|
|
|
/* global exceptions */
|
2008-01-21 08:54:01 +03:00
|
|
|
extern HIDDEN PyObject *Error, *Warning, *InterfaceError, *DatabaseError,
|
2004-10-19 07:17:12 +04:00
|
|
|
*InternalError, *OperationalError, *ProgrammingError,
|
|
|
|
*IntegrityError, *DataError, *NotSupportedError;
|
2008-01-22 00:41:17 +03:00
|
|
|
extern HIDDEN PyObject *QueryCanceledError, *TransactionRollbackError;
|
2004-10-19 07:17:12 +04:00
|
|
|
|
|
|
|
/* python versions and compatibility stuff */
|
|
|
|
#ifndef PyMODINIT_FUNC
|
|
|
|
#define PyMODINIT_FUNC void
|
|
|
|
#endif
|
2007-04-10 10:36:18 +04:00
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
#else
|
|
|
|
/** This section is used in modules that use psycopg's C API **/
|
|
|
|
|
|
|
|
static void **PSYCOPG_API;
|
|
|
|
|
|
|
|
#define psyco_errors_fill \
|
|
|
|
(*(psyco_errors_fill_RETURN (*)psyco_errors_fill_PROTO) \
|
|
|
|
PSYCOPG_API[psyco_errors_fill_NUM])
|
|
|
|
#define psyco_errors_set \
|
|
|
|
(*(psyco_errors_set_RETURN (*)psyco_errors_set_PROTO) \
|
|
|
|
PSYCOPG_API[psyco_errors_set_NUM])
|
2007-04-10 10:36:18 +04:00
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
/* Return -1 and set exception on error, 0 on success. */
|
|
|
|
static int
|
|
|
|
import_psycopg(void)
|
|
|
|
{
|
|
|
|
PyObject *module = PyImport_ImportModule("psycopg");
|
|
|
|
|
|
|
|
if (module != NULL) {
|
|
|
|
PyObject *c_api_object = PyObject_GetAttrString(module, "_C_API");
|
|
|
|
if (c_api_object == NULL) return -1;
|
|
|
|
if (PyCObject_Check(c_api_object))
|
|
|
|
PSYCOPG_API = (void **)PyCObject_AsVoidPtr(c_api_object);
|
|
|
|
Py_DECREF(c_api_object);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* postgresql<->python encoding map */
|
2008-01-21 08:54:01 +03:00
|
|
|
extern HIDDEN PyObject *psycoEncodings;
|
2007-04-10 10:36:18 +04:00
|
|
|
|
2011-02-17 23:08:04 +03:00
|
|
|
/* SQL NULL */
|
|
|
|
extern HIDDEN PyObject *psyco_null;
|
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
typedef struct {
|
|
|
|
char *pgenc;
|
|
|
|
char *pyenc;
|
|
|
|
} encodingPair;
|
|
|
|
|
2007-04-10 10:36:18 +04:00
|
|
|
/* the Decimal type, used by the DECIMAL typecaster */
|
2008-01-21 08:54:01 +03:00
|
|
|
HIDDEN PyObject *psyco_GetDecimalType(void);
|
2006-01-05 11:13:03 +03:00
|
|
|
|
2013-04-05 03:07:36 +04:00
|
|
|
/* forward declarations */
|
2011-02-21 02:43:25 +03:00
|
|
|
typedef struct cursorObject cursorObject;
|
2013-04-05 03:07:36 +04:00
|
|
|
typedef struct connectionObject connectionObject;
|
2015-06-05 18:44:09 +03:00
|
|
|
typedef struct replicationMessageObject replicationMessageObject;
|
2011-02-21 02:43:25 +03:00
|
|
|
|
2006-01-05 11:13:03 +03:00
|
|
|
/* some utility functions */
|
2013-03-19 20:07:47 +04:00
|
|
|
RAISES HIDDEN PyObject *psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg);
|
2007-04-10 10:36:18 +04:00
|
|
|
|
2013-04-05 03:07:36 +04:00
|
|
|
HIDDEN char *psycopg_escape_string(connectionObject *conn,
|
2008-11-25 21:18:17 +03:00
|
|
|
const char *from, Py_ssize_t len, char *to, Py_ssize_t *tolen);
|
2016-12-26 04:37:36 +03:00
|
|
|
HIDDEN char *psycopg_escape_identifier(connectionObject *conn,
|
2016-12-26 22:01:19 +03:00
|
|
|
const char *str, Py_ssize_t len);
|
2012-03-01 04:24:52 +04:00
|
|
|
HIDDEN int psycopg_strdup(char **to, const char *from, Py_ssize_t len);
|
2012-02-24 14:41:02 +04:00
|
|
|
HIDDEN int psycopg_is_text_file(PyObject *f);
|
2016-12-26 21:47:48 +03:00
|
|
|
HIDDEN PyObject *psycopg_text_from_chars_safe(
|
|
|
|
const char *str, Py_ssize_t len, PyObject *decoder);
|
2012-02-24 14:41:02 +04:00
|
|
|
|
2012-03-01 04:57:52 +04:00
|
|
|
STEALS(1) HIDDEN PyObject * psycopg_ensure_bytes(PyObject *obj);
|
2012-02-24 14:41:02 +04:00
|
|
|
|
2012-03-01 04:57:52 +04:00
|
|
|
STEALS(1) HIDDEN PyObject * psycopg_ensure_text(PyObject *obj);
|
2010-12-15 06:07:13 +03:00
|
|
|
|
2015-10-30 13:10:41 +03:00
|
|
|
HIDDEN PyObject *psycopg_dict_from_conninfo_options(PQconninfoOption *options,
|
|
|
|
int include_password);
|
|
|
|
|
2017-03-16 06:33:19 +03:00
|
|
|
HIDDEN PyObject *psycopg_make_dsn(PyObject *dsn, PyObject *kwargs);
|
|
|
|
|
2006-01-12 21:36:57 +03:00
|
|
|
/* Exceptions docstrings */
|
|
|
|
#define Error_doc \
|
|
|
|
"Base class for error exceptions."
|
|
|
|
|
|
|
|
#define Warning_doc \
|
|
|
|
"A database warning."
|
|
|
|
|
|
|
|
#define InterfaceError_doc \
|
|
|
|
"Error related to the database interface."
|
|
|
|
|
|
|
|
#define DatabaseError_doc \
|
|
|
|
"Error related to the database engine."
|
|
|
|
|
|
|
|
#define InternalError_doc \
|
|
|
|
"The database encountered an internal error."
|
|
|
|
|
|
|
|
#define OperationalError_doc \
|
|
|
|
"Error related to database operation (disconnect, memory allocation etc)."
|
|
|
|
|
|
|
|
#define ProgrammingError_doc \
|
|
|
|
"Error related to database programming (SQL error, table not found etc)."
|
|
|
|
|
|
|
|
#define IntegrityError_doc \
|
|
|
|
"Error related to database integrity."
|
|
|
|
|
|
|
|
#define DataError_doc \
|
|
|
|
"Error related to problems with the processed data."
|
|
|
|
|
|
|
|
#define NotSupportedError_doc \
|
2008-09-23 13:22:37 +04:00
|
|
|
"A method or database API was used which is not supported by the database."
|
2006-01-12 21:36:57 +03:00
|
|
|
|
2008-01-16 08:14:24 +03:00
|
|
|
#define QueryCanceledError_doc \
|
2010-07-18 14:14:46 +04:00
|
|
|
"Error related to SQL query cancellation."
|
2008-01-16 08:14:24 +03:00
|
|
|
|
|
|
|
#define TransactionRollbackError_doc \
|
2013-04-26 12:21:56 +04:00
|
|
|
"Error causing transaction rollback (deadlocks, serialization failures, etc)."
|
2008-01-16 08:14:24 +03:00
|
|
|
|
2004-10-19 07:17:12 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* !defined(PSYCOPG_H) */
|