mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-11 11:36:37 +03:00
Use the newly provided attributes to validate exceptions raising
Be more consistent in using 0 for success, <0 for failure, and to check for values < 0 instead of specific -1.
This commit is contained in:
parent
67712e4226
commit
a167822e26
|
@ -162,17 +162,31 @@ static double round(double num)
|
||||||
|
|
||||||
/* decorators for the gcc cpychecker plugin */
|
/* decorators for the gcc cpychecker plugin */
|
||||||
#if defined(WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE)
|
#if defined(WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE)
|
||||||
#define CPYCHECKER_RETURNS_BORROWED_REF \
|
#define CPYCHECKER_RETURNS_BORROWED_REF \
|
||||||
__attribute__((cpychecker_returns_borrowed_ref))
|
__attribute__((cpychecker_returns_borrowed_ref))
|
||||||
#else
|
#else
|
||||||
#define CPYCHECKER_RETURNS_BORROWED_REF
|
#define CPYCHECKER_RETURNS_BORROWED_REF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)
|
#if defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)
|
||||||
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
|
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
|
||||||
__attribute__((cpychecker_steals_reference_to_arg(n)))
|
__attribute__((cpychecker_steals_reference_to_arg(n)))
|
||||||
#else
|
#else
|
||||||
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
|
#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE)
|
||||||
|
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION \
|
||||||
|
__attribute__((cpychecker_negative_result_sets_exception))
|
||||||
|
#else
|
||||||
|
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE)
|
||||||
|
#define CPYCHECKER_SETS_EXCEPTION \
|
||||||
|
__attribute__((cpychecker_sets_exception))
|
||||||
|
#else
|
||||||
|
#define CPYCHECKER_SETS_EXCEPTION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* !defined(PSYCOPG_CONFIG_H) */
|
#endif /* !defined(PSYCOPG_CONFIG_H) */
|
||||||
|
|
|
@ -131,6 +131,7 @@ typedef struct {
|
||||||
/* C-callable functions in connection_int.c and connection_ext.c */
|
/* C-callable functions in connection_int.c and connection_ext.c */
|
||||||
HIDDEN PyObject *conn_text_from_chars(connectionObject *pgconn, const char *str);
|
HIDDEN PyObject *conn_text_from_chars(connectionObject *pgconn, const char *str);
|
||||||
HIDDEN int conn_get_standard_conforming_strings(PGconn *pgconn);
|
HIDDEN int conn_get_standard_conforming_strings(PGconn *pgconn);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int conn_get_isolation_level(connectionObject *self);
|
HIDDEN int conn_get_isolation_level(connectionObject *self);
|
||||||
HIDDEN int conn_get_protocol_version(PGconn *pgconn);
|
HIDDEN int conn_get_protocol_version(PGconn *pgconn);
|
||||||
HIDDEN int conn_get_server_version(PGconn *pgconn);
|
HIDDEN int conn_get_server_version(PGconn *pgconn);
|
||||||
|
@ -141,16 +142,22 @@ HIDDEN void conn_notifies_process(connectionObject *self);
|
||||||
HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
|
HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
|
||||||
HIDDEN int conn_connect(connectionObject *self, long int async);
|
HIDDEN int conn_connect(connectionObject *self, long int async);
|
||||||
HIDDEN void conn_close(connectionObject *self);
|
HIDDEN void conn_close(connectionObject *self);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int conn_commit(connectionObject *self);
|
HIDDEN int conn_commit(connectionObject *self);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int conn_rollback(connectionObject *self);
|
HIDDEN int conn_rollback(connectionObject *self);
|
||||||
HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
|
HIDDEN int conn_set_session(connectionObject *self, const char *isolevel,
|
||||||
const char *readonly, const char *deferrable,
|
const char *readonly, const char *deferrable,
|
||||||
int autocommit);
|
int autocommit);
|
||||||
HIDDEN int conn_set_autocommit(connectionObject *self, int value);
|
HIDDEN int conn_set_autocommit(connectionObject *self, int value);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int conn_switch_isolation_level(connectionObject *self, int level);
|
HIDDEN int conn_switch_isolation_level(connectionObject *self, int level);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc);
|
HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc);
|
||||||
HIDDEN int conn_poll(connectionObject *self);
|
HIDDEN int conn_poll(connectionObject *self);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int conn_tpc_begin(connectionObject *self, XidObject *xid);
|
HIDDEN int conn_tpc_begin(connectionObject *self, XidObject *xid);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int conn_tpc_command(connectionObject *self,
|
HIDDEN int conn_tpc_command(connectionObject *self,
|
||||||
const char *cmd, XidObject *xid);
|
const char *cmd, XidObject *xid);
|
||||||
HIDDEN PyObject *conn_tpc_recover(connectionObject *self);
|
HIDDEN PyObject *conn_tpc_recover(connectionObject *self);
|
||||||
|
|
|
@ -370,6 +370,7 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
conn_get_isolation_level(connectionObject *self)
|
conn_get_isolation_level(connectionObject *self)
|
||||||
{
|
{
|
||||||
|
@ -947,6 +948,7 @@ conn_close(connectionObject *self)
|
||||||
|
|
||||||
/* conn_commit - commit on a connection */
|
/* conn_commit - commit on a connection */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
conn_commit(connectionObject *self)
|
conn_commit(connectionObject *self)
|
||||||
{
|
{
|
||||||
|
@ -958,6 +960,7 @@ conn_commit(connectionObject *self)
|
||||||
|
|
||||||
/* conn_rollback - rollback a connection */
|
/* conn_rollback - rollback a connection */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
conn_rollback(connectionObject *self)
|
conn_rollback(connectionObject *self)
|
||||||
{
|
{
|
||||||
|
@ -1040,6 +1043,7 @@ conn_set_autocommit(connectionObject *self, int value)
|
||||||
|
|
||||||
/* conn_switch_isolation_level - switch isolation level on the connection */
|
/* conn_switch_isolation_level - switch isolation level on the connection */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
conn_switch_isolation_level(connectionObject *self, int level)
|
conn_switch_isolation_level(connectionObject *self, int level)
|
||||||
{
|
{
|
||||||
|
@ -1122,12 +1126,13 @@ endlock:
|
||||||
|
|
||||||
/* conn_set_client_encoding - switch client encoding on connection */
|
/* conn_set_client_encoding - switch client encoding on connection */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
conn_set_client_encoding(connectionObject *self, const char *enc)
|
conn_set_client_encoding(connectionObject *self, const char *enc)
|
||||||
{
|
{
|
||||||
PGresult *pgres = NULL;
|
PGresult *pgres = NULL;
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
int res = 1;
|
int res = -1;
|
||||||
char *codec = NULL;
|
char *codec = NULL;
|
||||||
char *clean_enc = NULL;
|
char *clean_enc = NULL;
|
||||||
|
|
||||||
|
@ -1195,6 +1200,7 @@ exit:
|
||||||
* in regular transactions, as PostgreSQL won't even know we are in a TPC
|
* in regular transactions, as PostgreSQL won't even know we are in a TPC
|
||||||
* until PREPARE. */
|
* until PREPARE. */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
conn_tpc_begin(connectionObject *self, XidObject *xid)
|
conn_tpc_begin(connectionObject *self, XidObject *xid)
|
||||||
{
|
{
|
||||||
|
@ -1229,6 +1235,7 @@ conn_tpc_begin(connectionObject *self, XidObject *xid)
|
||||||
* The function doesn't change the connection state as it can be used
|
* The function doesn't change the connection state as it can be used
|
||||||
* for many commands and for recovered transactions. */
|
* for many commands and for recovered transactions. */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
conn_tpc_command(connectionObject *self, const char *cmd, XidObject *xid)
|
conn_tpc_command(connectionObject *self, const char *cmd, XidObject *xid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -638,7 +638,7 @@ psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &enc)) return NULL;
|
if (!PyArg_ParseTuple(args, "s", &enc)) return NULL;
|
||||||
|
|
||||||
if (conn_set_client_encoding(self, enc) == 0) {
|
if (conn_set_client_encoding(self, enc) >= 0) {
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
rv = Py_None;
|
rv = Py_None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ psyco_curs_close(cursorObject *self, PyObject *args)
|
||||||
|
|
||||||
/* mogrify a query string and build argument array or dict */
|
/* mogrify a query string and build argument array or dict */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
static int
|
static int
|
||||||
_mogrify(PyObject *var, PyObject *fmt, cursorObject *curs, PyObject **new)
|
_mogrify(PyObject *var, PyObject *fmt, cursorObject *curs, PyObject **new)
|
||||||
{
|
{
|
||||||
|
@ -359,11 +360,13 @@ _psyco_curs_merge_query_args(cursorObject *self,
|
||||||
#define psyco_curs_execute_doc \
|
#define psyco_curs_execute_doc \
|
||||||
"execute(query, vars=None) -- Execute query with bound vars."
|
"execute(query, vars=None) -- Execute query with bound vars."
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
static int
|
static int
|
||||||
_psyco_curs_execute(cursorObject *self,
|
_psyco_curs_execute(cursorObject *self,
|
||||||
PyObject *operation, PyObject *vars, long int async)
|
PyObject *operation, PyObject *vars, long int async)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = -1;
|
||||||
|
int tmp;
|
||||||
PyObject *fquery, *cvt = NULL;
|
PyObject *fquery, *cvt = NULL;
|
||||||
|
|
||||||
operation = _psyco_curs_validate_sql_basic(self, operation);
|
operation = _psyco_curs_validate_sql_basic(self, operation);
|
||||||
|
@ -371,7 +374,7 @@ _psyco_curs_execute(cursorObject *self,
|
||||||
/* Any failure from here forward should 'goto fail' rather than 'return 0'
|
/* Any failure from here forward should 'goto fail' rather than 'return 0'
|
||||||
directly. */
|
directly. */
|
||||||
|
|
||||||
if (operation == NULL) { goto fail; }
|
if (operation == NULL) { goto exit; }
|
||||||
|
|
||||||
IFCLEARPGRES(self->pgres);
|
IFCLEARPGRES(self->pgres);
|
||||||
|
|
||||||
|
@ -388,12 +391,12 @@ _psyco_curs_execute(cursorObject *self,
|
||||||
|
|
||||||
if (vars && vars != Py_None)
|
if (vars && vars != Py_None)
|
||||||
{
|
{
|
||||||
if(_mogrify(vars, operation, self, &cvt) == -1) { goto fail; }
|
if (0 > _mogrify(vars, operation, self, &cvt)) { goto exit; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vars && cvt) {
|
if (vars && cvt) {
|
||||||
if (!(fquery = _psyco_curs_merge_query_args(self, operation, cvt))) {
|
if (!(fquery = _psyco_curs_merge_query_args(self, operation, cvt))) {
|
||||||
goto fail;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->name != NULL) {
|
if (self->name != NULL) {
|
||||||
|
@ -427,25 +430,20 @@ _psyco_curs_execute(cursorObject *self,
|
||||||
|
|
||||||
/* At this point, the SQL statement must be str, not unicode */
|
/* At this point, the SQL statement must be str, not unicode */
|
||||||
|
|
||||||
res = pq_execute(self, Bytes_AS_STRING(self->query), async);
|
tmp = pq_execute(self, Bytes_AS_STRING(self->query), async);
|
||||||
Dprintf("psyco_curs_execute: res = %d, pgres = %p", res, self->pgres);
|
Dprintf("psyco_curs_execute: res = %d, pgres = %p", tmp, self->pgres);
|
||||||
if (res == -1) { goto fail; }
|
if (tmp < 0) { goto exit; }
|
||||||
|
|
||||||
res = 1; /* Success */
|
res = 0; /* Success */
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
fail:
|
exit:
|
||||||
res = 0;
|
/* Py_XDECREF(operation) is safe because the original reference passed
|
||||||
/* Fall through to cleanup */
|
by the caller was overwritten with either NULL or a new
|
||||||
cleanup:
|
reference */
|
||||||
/* Py_XDECREF(operation) is safe because the original reference passed
|
Py_XDECREF(operation);
|
||||||
by the caller was overwritten with either NULL or a new
|
Py_XDECREF(cvt);
|
||||||
reference */
|
|
||||||
Py_XDECREF(operation);
|
|
||||||
|
|
||||||
Py_XDECREF(cvt);
|
return res;
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -479,13 +477,13 @@ psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
EXC_IF_ASYNC_IN_PROGRESS(self, execute);
|
EXC_IF_ASYNC_IN_PROGRESS(self, execute);
|
||||||
EXC_IF_TPC_PREPARED(self->conn, execute);
|
EXC_IF_TPC_PREPARED(self->conn, execute);
|
||||||
|
|
||||||
if (_psyco_curs_execute(self, operation, vars, self->conn->async)) {
|
if (0 > _psyco_curs_execute(self, operation, vars, self->conn->async)) {
|
||||||
Py_INCREF(Py_None);
|
|
||||||
return Py_None;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* success */
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define psyco_curs_executemany_doc \
|
#define psyco_curs_executemany_doc \
|
||||||
|
@ -524,7 +522,7 @@ psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((v = PyIter_Next(vars)) != NULL) {
|
while ((v = PyIter_Next(vars)) != NULL) {
|
||||||
if (_psyco_curs_execute(self, operation, v, 0) == 0) {
|
if (0 > _psyco_curs_execute(self, operation, v, 0)) {
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
Py_XDECREF(iter);
|
Py_XDECREF(iter);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -571,7 +569,7 @@ _psyco_curs_mogrify(cursorObject *self,
|
||||||
|
|
||||||
if (vars && vars != Py_None)
|
if (vars && vars != Py_None)
|
||||||
{
|
{
|
||||||
if (_mogrify(vars, operation, self, &cvt) == -1) {
|
if (0 > _mogrify(vars, operation, self, &cvt)) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -647,6 +645,7 @@ psyco_curs_cast(cursorObject *self, PyObject *args)
|
||||||
"default) or using the sequence factory previously set in the\n" \
|
"default) or using the sequence factory previously set in the\n" \
|
||||||
"`row_factory` attribute. Return `!None` when no more data is available.\n"
|
"`row_factory` attribute. Return `!None` when no more data is available.\n"
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
static int
|
static int
|
||||||
_psyco_curs_prefetch(cursorObject *self)
|
_psyco_curs_prefetch(cursorObject *self)
|
||||||
{
|
{
|
||||||
|
@ -664,6 +663,7 @@ _psyco_curs_prefetch(cursorObject *self)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
static int
|
static int
|
||||||
_psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
|
_psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
|
||||||
int row, int n, int istuple)
|
int row, int n, int istuple)
|
||||||
|
@ -1045,7 +1045,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
if (!(operation = Bytes_FromString(sql))) { goto exit; }
|
if (!(operation = Bytes_FromString(sql))) { goto exit; }
|
||||||
|
|
||||||
if (_psyco_curs_execute(self, operation, parameters, self->conn->async)) {
|
if (0 <= _psyco_curs_execute(self, operation, parameters, self->conn->async)) {
|
||||||
Py_INCREF(parameters);
|
Py_INCREF(parameters);
|
||||||
res = parameters;
|
res = parameters;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ strip_severity(const char *msg)
|
||||||
code. A list of error codes can be found at:
|
code. A list of error codes can be found at:
|
||||||
|
|
||||||
http://www.postgresql.org/docs/current/static/errcodes-appendix.html */
|
http://www.postgresql.org/docs/current/static/errcodes-appendix.html */
|
||||||
|
CPYCHECKER_RETURNS_BORROWED_REF
|
||||||
static PyObject *
|
static PyObject *
|
||||||
exception_from_sqlstate(const char *sqlstate)
|
exception_from_sqlstate(const char *sqlstate)
|
||||||
{
|
{
|
||||||
|
@ -151,6 +152,7 @@ exception_from_sqlstate(const char *sqlstate)
|
||||||
|
|
||||||
This function should be called while holding the GIL. */
|
This function should be called while holding the GIL. */
|
||||||
|
|
||||||
|
CPYCHECKER_SETS_EXCEPTION
|
||||||
static void
|
static void
|
||||||
pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres)
|
pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres)
|
||||||
{
|
{
|
||||||
|
@ -164,7 +166,7 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres)
|
||||||
"psycopg went psycotic and raised a null error");
|
"psycopg went psycotic and raised a null error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the connection has somehow beed broken, we mark the connection
|
/* if the connection has somehow beed broken, we mark the connection
|
||||||
object as closed but requiring cleanup */
|
object as closed but requiring cleanup */
|
||||||
if (conn->pgconn != NULL && PQstatus(conn->pgconn) == CONNECTION_BAD)
|
if (conn->pgconn != NULL && PQstatus(conn->pgconn) == CONNECTION_BAD)
|
||||||
|
@ -249,7 +251,10 @@ pq_clear_critical(connectionObject *conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
/* return -1 if the exception is set (i.e. if conn->critical is set),
|
||||||
|
* else 0 */
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
|
static int
|
||||||
pq_resolve_critical(connectionObject *conn, int close)
|
pq_resolve_critical(connectionObject *conn, int close)
|
||||||
{
|
{
|
||||||
Dprintf("pq_resolve_critical: resolving %s", conn->critical);
|
Dprintf("pq_resolve_critical: resolving %s", conn->critical);
|
||||||
|
@ -267,7 +272,10 @@ pq_resolve_critical(connectionObject *conn, int close)
|
||||||
|
|
||||||
/* remember to clear the critical! */
|
/* remember to clear the critical! */
|
||||||
pq_clear_critical(conn);
|
pq_clear_critical(conn);
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pq_clear_async - clear the effects of a previous async query
|
/* pq_clear_async - clear the effects of a previous async query
|
||||||
|
@ -381,6 +389,7 @@ cleanup:
|
||||||
This function should be called while holding the global interpreter
|
This function should be called while holding the global interpreter
|
||||||
lock.
|
lock.
|
||||||
*/
|
*/
|
||||||
|
CPYCHECKER_SETS_EXCEPTION
|
||||||
void
|
void
|
||||||
pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
|
pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
|
||||||
{
|
{
|
||||||
|
@ -474,6 +483,7 @@ pq_commit(connectionObject *conn)
|
||||||
return retvalue;
|
return retvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
pq_abort_locked(connectionObject *conn, PGresult **pgres, char **error,
|
pq_abort_locked(connectionObject *conn, PGresult **pgres, char **error,
|
||||||
PyThreadState **tstate)
|
PyThreadState **tstate)
|
||||||
|
@ -501,6 +511,7 @@ pq_abort_locked(connectionObject *conn, PGresult **pgres, char **error,
|
||||||
This function should be called while holding the global interpreter
|
This function should be called while holding the global interpreter
|
||||||
lock. */
|
lock. */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
pq_abort(connectionObject *conn)
|
pq_abort(connectionObject *conn)
|
||||||
{
|
{
|
||||||
|
@ -543,6 +554,7 @@ pq_abort(connectionObject *conn)
|
||||||
connection without holding the global interpreter lock.
|
connection without holding the global interpreter lock.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
pq_reset_locked(connectionObject *conn, PGresult **pgres, char **error,
|
pq_reset_locked(connectionObject *conn, PGresult **pgres, char **error,
|
||||||
PyThreadState **tstate)
|
PyThreadState **tstate)
|
||||||
|
@ -835,6 +847,7 @@ pq_flush(connectionObject *conn)
|
||||||
this fucntion locks the connection object
|
this fucntion locks the connection object
|
||||||
this function call Py_*_ALLOW_THREADS macros */
|
this function call Py_*_ALLOW_THREADS macros */
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
int
|
int
|
||||||
pq_execute(cursorObject *curs, const char *query, int async)
|
pq_execute(cursorObject *curs, const char *query, int async)
|
||||||
{
|
{
|
||||||
|
@ -845,8 +858,7 @@ pq_execute(cursorObject *curs, const char *query, int async)
|
||||||
/* if the status of the connection is critical raise an exception and
|
/* if the status of the connection is critical raise an exception and
|
||||||
definitely close the connection */
|
definitely close the connection */
|
||||||
if (curs->conn->critical) {
|
if (curs->conn->critical) {
|
||||||
pq_resolve_critical(curs->conn, 1);
|
return pq_resolve_critical(curs->conn, 1);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check status of connection, raise error if not OK */
|
/* check status of connection, raise error if not OK */
|
||||||
|
@ -941,7 +953,7 @@ pq_execute(cursorObject *curs, const char *query, int async)
|
||||||
to respect the old DBAPI-2.0 compatible behaviour */
|
to respect the old DBAPI-2.0 compatible behaviour */
|
||||||
if (async == 0) {
|
if (async == 0) {
|
||||||
Dprintf("pq_execute: entering syncronous DBAPI compatibility mode");
|
Dprintf("pq_execute: entering syncronous DBAPI compatibility mode");
|
||||||
if (pq_fetch(curs) == -1) return -1;
|
if (pq_fetch(curs) < 0) return -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
curs->conn->async_status = async_status;
|
curs->conn->async_status = async_status;
|
||||||
|
@ -1015,6 +1027,7 @@ pq_get_last_result(connectionObject *conn)
|
||||||
1 - result from backend (possibly data is ready)
|
1 - result from backend (possibly data is ready)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
static int
|
static int
|
||||||
_pq_fetch_tuples(cursorObject *curs)
|
_pq_fetch_tuples(cursorObject *curs)
|
||||||
{
|
{
|
||||||
|
@ -1415,8 +1428,7 @@ pq_fetch(cursorObject *curs)
|
||||||
Dprintf("pq_fetch: got a NULL pgres, checking for critical");
|
Dprintf("pq_fetch: got a NULL pgres, checking for critical");
|
||||||
pq_set_critical(curs->conn);
|
pq_set_critical(curs->conn);
|
||||||
if (curs->conn->critical) {
|
if (curs->conn->critical) {
|
||||||
pq_resolve_critical(curs->conn);
|
return pq_resolve_critical(curs->conn);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1492,13 +1504,7 @@ pq_fetch(cursorObject *curs)
|
||||||
raise the exception but we avoid to close the connection) */
|
raise the exception but we avoid to close the connection) */
|
||||||
Dprintf("pq_fetch: fetching done; check for critical errors");
|
Dprintf("pq_fetch: fetching done; check for critical errors");
|
||||||
if (curs->conn->critical) {
|
if (curs->conn->critical) {
|
||||||
if (ex == -1) {
|
return pq_resolve_critical(curs->conn, ex == -1 ? 1 : 0);
|
||||||
pq_resolve_critical(curs->conn, 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pq_resolve_critical(curs->conn, 0);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ex;
|
return ex;
|
||||||
|
|
|
@ -35,17 +35,22 @@
|
||||||
|
|
||||||
/* exported functions */
|
/* exported functions */
|
||||||
HIDDEN PGresult *pq_get_last_result(connectionObject *conn);
|
HIDDEN PGresult *pq_get_last_result(connectionObject *conn);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int pq_fetch(cursorObject *curs);
|
HIDDEN int pq_fetch(cursorObject *curs);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int pq_execute(cursorObject *curs, const char *query, int async);
|
HIDDEN int pq_execute(cursorObject *curs, const char *query, int async);
|
||||||
HIDDEN int pq_send_query(connectionObject *conn, const char *query);
|
HIDDEN int pq_send_query(connectionObject *conn, const char *query);
|
||||||
HIDDEN int pq_begin_locked(connectionObject *conn, PGresult **pgres,
|
HIDDEN int pq_begin_locked(connectionObject *conn, PGresult **pgres,
|
||||||
char **error, PyThreadState **tstate);
|
char **error, PyThreadState **tstate);
|
||||||
HIDDEN int pq_commit(connectionObject *conn);
|
HIDDEN int pq_commit(connectionObject *conn);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
|
HIDDEN int pq_abort_locked(connectionObject *conn, PGresult **pgres,
|
||||||
char **error, PyThreadState **tstate);
|
char **error, PyThreadState **tstate);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int pq_abort(connectionObject *conn);
|
HIDDEN int pq_abort(connectionObject *conn);
|
||||||
HIDDEN int pq_reset_locked(connectionObject *conn, PGresult **pgres,
|
HIDDEN int pq_reset_locked(connectionObject *conn, PGresult **pgres,
|
||||||
char **error, PyThreadState **tstate);
|
char **error, PyThreadState **tstate);
|
||||||
|
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
|
||||||
HIDDEN int pq_reset(connectionObject *conn);
|
HIDDEN int pq_reset(connectionObject *conn);
|
||||||
HIDDEN char *pq_get_guc_locked(connectionObject *conn, const char *param,
|
HIDDEN char *pq_get_guc_locked(connectionObject *conn, const char *param,
|
||||||
PGresult **pgres,
|
PGresult **pgres,
|
||||||
|
@ -69,6 +74,7 @@ HIDDEN int pq_execute_command_locked(connectionObject *conn,
|
||||||
const char *query,
|
const char *query,
|
||||||
PGresult **pgres, char **error,
|
PGresult **pgres, char **error,
|
||||||
PyThreadState **tstate);
|
PyThreadState **tstate);
|
||||||
|
CPYCHECKER_SETS_EXCEPTION
|
||||||
HIDDEN void pq_complete_error(connectionObject *conn, PGresult **pgres,
|
HIDDEN void pq_complete_error(connectionObject *conn, PGresult **pgres,
|
||||||
char **error);
|
char **error);
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ HIDDEN PyObject *psyco_GetDecimalType(void);
|
||||||
typedef struct cursorObject cursorObject;
|
typedef struct cursorObject cursorObject;
|
||||||
|
|
||||||
/* some utility functions */
|
/* some utility functions */
|
||||||
|
CPYCHECKER_SETS_EXCEPTION
|
||||||
HIDDEN void psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg,
|
HIDDEN void psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg,
|
||||||
const char *pgerror, const char *pgcode);
|
const char *pgerror, const char *pgcode);
|
||||||
|
|
||||||
|
|
|
@ -596,10 +596,11 @@ psyco_errors_set(PyObject *type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* psyco_error_new
|
/* psyco_set_error
|
||||||
|
|
||||||
Create a new error of the given type with extra attributes. */
|
Create a new error of the given type with extra attributes. */
|
||||||
|
|
||||||
|
CPYCHECKER_SETS_EXCEPTION
|
||||||
void
|
void
|
||||||
psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg,
|
psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg,
|
||||||
const char *pgerror, const char *pgcode)
|
const char *pgerror, const char *pgcode)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user