mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-06-01 03:33:10 +03:00
Use the do-while 0 idiom for cursor guards macro
This commit is contained in:
parent
a13c72cf32
commit
69b2fa282c
|
@ -97,30 +97,41 @@ HIDDEN int psyco_curs_scrollable_set(cursorObject *self, PyObject *pyvalue);
|
||||||
|
|
||||||
/* exception-raising macros */
|
/* exception-raising macros */
|
||||||
#define EXC_IF_CURS_CLOSED(self) \
|
#define EXC_IF_CURS_CLOSED(self) \
|
||||||
|
do \
|
||||||
if ((self)->closed || ((self)->conn && (self)->conn->closed)) { \
|
if ((self)->closed || ((self)->conn && (self)->conn->closed)) { \
|
||||||
PyErr_SetString(InterfaceError, "cursor already closed"); \
|
PyErr_SetString(InterfaceError, "cursor already closed"); \
|
||||||
return NULL; }
|
return NULL; } \
|
||||||
|
while (0)
|
||||||
|
|
||||||
#define EXC_IF_NO_TUPLES(self) \
|
#define EXC_IF_NO_TUPLES(self) \
|
||||||
|
do \
|
||||||
if ((self)->notuples && (self)->name == NULL) { \
|
if ((self)->notuples && (self)->name == NULL) { \
|
||||||
PyErr_SetString(ProgrammingError, "no results to fetch"); \
|
PyErr_SetString(ProgrammingError, "no results to fetch"); \
|
||||||
return NULL; }
|
return NULL; } \
|
||||||
|
while (0)
|
||||||
|
|
||||||
#define EXC_IF_NO_MARK(self) \
|
#define EXC_IF_NO_MARK(self) \
|
||||||
|
do \
|
||||||
if ((self)->mark != (self)->conn->mark && (self)->withhold == 0) { \
|
if ((self)->mark != (self)->conn->mark && (self)->withhold == 0) { \
|
||||||
PyErr_SetString(ProgrammingError, "named cursor isn't valid anymore"); \
|
PyErr_SetString(ProgrammingError, "named cursor isn't valid anymore"); \
|
||||||
return NULL; }
|
return NULL; } \
|
||||||
|
while (0)
|
||||||
|
|
||||||
#define EXC_IF_CURS_ASYNC(self, cmd) if ((self)->conn->async == 1) { \
|
#define EXC_IF_CURS_ASYNC(self, cmd) \
|
||||||
PyErr_SetString(ProgrammingError, #cmd " cannot be used " \
|
do \
|
||||||
"in asynchronous mode"); \
|
if ((self)->conn->async == 1) { \
|
||||||
return NULL; }
|
PyErr_SetString(ProgrammingError, \
|
||||||
|
#cmd " cannot be used in asynchronous mode"); \
|
||||||
|
return NULL; } \
|
||||||
|
while (0)
|
||||||
|
|
||||||
#define EXC_IF_ASYNC_IN_PROGRESS(self, cmd) \
|
#define EXC_IF_ASYNC_IN_PROGRESS(self, cmd) \
|
||||||
|
do \
|
||||||
if ((self)->conn->async_cursor != NULL) { \
|
if ((self)->conn->async_cursor != NULL) { \
|
||||||
PyErr_SetString(ProgrammingError, #cmd " cannot be used " \
|
PyErr_SetString(ProgrammingError, \
|
||||||
"while an asynchronous query is underway"); \
|
#cmd " cannot be used while an asynchronous query is underway"); \
|
||||||
return NULL; }
|
return NULL; } \
|
||||||
|
while (0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1169,7 +1169,7 @@ psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
|
|
||||||
EXC_IF_NO_MARK(self);
|
EXC_IF_NO_MARK(self);
|
||||||
EXC_IF_ASYNC_IN_PROGRESS(self, scroll)
|
EXC_IF_ASYNC_IN_PROGRESS(self, scroll);
|
||||||
EXC_IF_TPC_PREPARED(self->conn, scroll);
|
EXC_IF_TPC_PREPARED(self->conn, scroll);
|
||||||
|
|
||||||
if (strcmp(mode, "absolute") == 0) {
|
if (strcmp(mode, "absolute") == 0) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user