1 /* cursor.h - definition for the psycopg cursor type
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.
22 #ifndef PSYCOPG_CURSOR_H
23 #define PSYCOPG_CURSOR_H 1
28 #include "psycopg/connection.h"
34 extern PyTypeObject cursorType;
39 connectionObject *conn; /* connection owning the cursor */
41 int closed:1; /* 1 if the cursor is closed */
42 int notuples:1; /* 1 if the command was not a SELECT query */
43 int needsfetch:1; /* 1 if a call to pq_fetch is pending */
45 long int rowcount; /* number of rows affected by last execute */
46 long int columns; /* number of columns fetched from the db */
47 long int arraysize; /* how many rows should fetchmany() return */
48 long int row; /* the row counter for fetch*() operations */
49 long int mark; /* transaction marker, copied from conn */
51 PyObject *description; /* read-only attribute: sequence of 7-item
54 /* postgres connection stuff */
55 PGresult *pgres; /* result of last query */
56 PyObject *pgstatus; /* last message from the server after an execute */
57 Oid lastoid; /* last oid from an insert or InvalidOid */
59 PyObject *casts; /* an array (tuple) of typecast functions */
60 PyObject *caster; /* the current typecaster object */
62 PyObject *copyfile; /* file-like used during COPY TO/FROM ops */
63 long int copysize; /* size of the copy buffer during COPY TO/FROM ops */
64 #define DEFAULT_COPYSIZE 16384
66 PyObject *tuple_factory; /* factory for result tuples */
67 PyObject *tzinfo_factory; /* factory for tzinfo objects */
69 PyObject *query; /* last query executed */
71 char *qattr; /* quoting attr, used when quoting strings */
72 char *notice; /* a notice from the backend */
73 char *name; /* this cursor name */
75 PyObject *string_types; /* a set of typecasters for string types */
76 PyObject *binary_types; /* a set of typecasters for binary types */
80 /* C-callable functions in cursor_int.c and cursor_ext.c */
81 extern void curs_reset(cursorObject *self);
83 /* exception-raising macros */
84 #define EXC_IF_CURS_CLOSED(self) \
85 if ((self)->closed || ((self)->conn && (self)->conn->closed)) { \
86 PyErr_SetString(InterfaceError, "cursor already closed"); \
89 #define EXC_IF_NO_TUPLES(self) \
90 if ((self)->notuples && (self)->name == NULL) { \
91 PyErr_SetString(ProgrammingError, "no results to fetch"); \
94 #define EXC_IF_NO_MARK(self) \
95 if ((self)->mark != (self)->conn->mark) { \
96 PyErr_SetString(ProgrammingError, "named cursor isn't valid anymore"); \
103 #endif /* !defined(PSYCOPG_CURSOR_H) */