*
* Copyright (C) 2003-2019 Federico Di Gregorio <fog@debian.org>
* Copyright (C) 2020-2021 The Psycopg Team
*
* This file is part of psycopg.
*
* 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.
*
* 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.
*
* 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.
*/
#ifndef PSYCOPG_CURSOR_H
#define PSYCOPG_CURSOR_H 1
#include "psycopg/connection.h"
#ifdef __cplusplus
extern "C" {
#endif
extern HIDDEN PyTypeObject cursorType;
struct cursorObject {
PyObject_HEAD
connectionObject *conn;
int closed:1;
int notuples:1;
int withhold:1;
int scrollable;
0 if not scrollable
-1 if undefined (PG may decide scrollable or not)
*/
long int rowcount;
long int columns;
long int arraysize;
long int itersize;
long int row;
long int mark;
PyObject *description;
sequences.*/
PGresult *pgres;
PyObject *pgstatus;
Oid lastoid;
PyObject *casts;
PyObject *caster;
PyObject *copyfile;
Py_ssize_t copysize;
#define DEFAULT_COPYSIZE 16384
#define DEFAULT_COPYBUFF 8192
PyObject *tuple_factory;
PyObject *tzinfo_factory;
PyObject *query;
char *qattr;
char *notice;
char *name;
char *qname;
PyObject *string_types;
PyObject *binary_types;
PyObject *weakreflist;
};
BORROWED HIDDEN PyObject *curs_get_cast(cursorObject *self, PyObject *oid);
HIDDEN void curs_reset(cursorObject *self);
RAISES_NEG HIDDEN int curs_withhold_set(cursorObject *self, PyObject *pyvalue);
RAISES_NEG HIDDEN int curs_scrollable_set(cursorObject *self, PyObject *pyvalue);
HIDDEN PyObject *curs_validate_sql_basic(cursorObject *self, PyObject *sql);
HIDDEN void curs_set_result(cursorObject *self, PGresult *pgres);
#define EXC_IF_CURS_CLOSED(self) \
do { \
if (!(self)->conn) { \
PyErr_SetString(InterfaceError, "the cursor has no connection"); \
return NULL; } \
if ((self)->closed || (self)->conn->closed) { \
PyErr_SetString(InterfaceError, "cursor already closed"); \
return NULL; } \
} while (0)
#define EXC_IF_NO_TUPLES(self) \
do \
if ((self)->notuples && (self)->name == NULL) { \
PyErr_SetString(ProgrammingError, "no results to fetch"); \
return NULL; } \
while (0)
#define EXC_IF_NO_MARK(self) \
do \
if ((self)->mark != (self)->conn->mark && (self)->withhold == 0) { \
PyErr_SetString(ProgrammingError, "named cursor isn't valid anymore"); \
return NULL; } \
while (0)
#define EXC_IF_CURS_ASYNC(self, cmd) \
do \
if ((self)->conn->async == 1) { \
PyErr_SetString(ProgrammingError, \
#cmd " cannot be used in asynchronous mode"); \
return NULL; } \
while (0)
#define EXC_IF_ASYNC_IN_PROGRESS(self, cmd) \
do \
if ((self)->conn->async_cursor != NULL) { \
PyErr_SetString(ProgrammingError, \
#cmd " cannot be used while an asynchronous query is underway"); \
return NULL; } \
while (0)
#ifdef __cplusplus
}
#endif
#endif