aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/python/pgmodule.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2001-03-22 04:01:46 +0000
committerBruce Momjian <bruce@momjian.us>2001-03-22 04:01:46 +0000
commit9e1552607a9dc6bc23e43d46770a9063ade4f3f0 (patch)
tree6a230d81917ebc004e40cd46c48f2aa27eec153e /src/interfaces/python/pgmodule.c
parent6cf8707b828b14b5c2336076ce358b18b67829d6 (diff)
downloadpostgresql-9e1552607a9dc6bc23e43d46770a9063ade4f3f0.tar.gz
postgresql-9e1552607a9dc6bc23e43d46770a9063ade4f3f0.zip
pgindent run. Make it all clean.
Diffstat (limited to 'src/interfaces/python/pgmodule.c')
-rw-r--r--src/interfaces/python/pgmodule.c1138
1 files changed, 598 insertions, 540 deletions
diff --git a/src/interfaces/python/pgmodule.c b/src/interfaces/python/pgmodule.c
index 70f8c02f10e..bae459a1724 100644
--- a/src/interfaces/python/pgmodule.c
+++ b/src/interfaces/python/pgmodule.c
@@ -37,22 +37,22 @@
/* really bad stuff here - I'm so naughty */
/* If you need to you can run mkdefines to get */
/* current defines but it should not have changed */
-#define INT2OID 21
-#define INT4OID 23
-#define OIDOID 26
-#define FLOAT4OID 700
-#define FLOAT8OID 701
-#define CASHOID 790
+#define INT2OID 21
+#define INT4OID 23
+#define OIDOID 26
+#define FLOAT4OID 700
+#define FLOAT8OID 701
+#define CASHOID 790
-static PyObject *PGError;
-static const char *PyPgVersion = "3.1";
+static PyObject *PGError;
+static const char *PyPgVersion = "3.1";
/* taken from fileobject.c */
#define BUF(v) PyString_AS_STRING((PyStringObject *)(v))
/* default values */
-#define MODULE_NAME "pgsql"
-#define ARRAYSIZE 1
+#define MODULE_NAME "pgsql"
+#define ARRAYSIZE 1
/* flags for object validity checks */
#define CHECK_OPEN 1
@@ -75,21 +75,21 @@ static const char *PyPgVersion = "3.1";
/* moves names for errors */
const char *__movename[5] =
- { "", "movefirst", "movelast", "movenext", "moveprev" };
+{"", "movefirst", "movelast", "movenext", "moveprev"};
-#define MAX_BUFFER_SIZE 8192 /* maximum transaction size */
+#define MAX_BUFFER_SIZE 8192 /* maximum transaction size */
#ifndef NO_DIRECT
#define DIRECT_ACCESS 1 /* enables direct access functions */
-#endif /* NO_DIRECT */
+#endif /* NO_DIRECT */
#ifndef NO_LARGE
#define LARGE_OBJECTS 1 /* enables large objects support */
-#endif /* NO_LARGE */
+#endif /* NO_LARGE */
#ifndef NO_DEF_VAR
#define DEFAULT_VARS 1 /* enables default variables use */
-#endif /* NO_DEF_VAR */
+#endif /* NO_DEF_VAR */
#ifdef MS_WIN32
#define NO_SNPRINTF 1
@@ -101,15 +101,15 @@ const char *__movename[5] =
#ifdef DEFAULT_VARS
-static PyObject *pg_default_host; /* default database host */
-static PyObject *pg_default_base; /* default database name */
-static PyObject *pg_default_opt; /* default connection options */
-static PyObject *pg_default_tty; /* default debug tty */
-static PyObject *pg_default_port; /* default connection port */
-static PyObject *pg_default_user; /* default username */
-static PyObject *pg_default_passwd; /* default password */
+static PyObject *pg_default_host; /* default database host */
+static PyObject *pg_default_base; /* default database name */
+static PyObject *pg_default_opt;/* default connection options */
+static PyObject *pg_default_tty;/* default debug tty */
+static PyObject *pg_default_port; /* default connection port */
+static PyObject *pg_default_user; /* default username */
+static PyObject *pg_default_passwd; /* default password */
-#endif /* DEFAULT_VARS */
+#endif /* DEFAULT_VARS */
/* --------------------------------------------------------------------- */
/* OBJECTS DECLARATION */
@@ -120,9 +120,9 @@ typedef struct
{
PyObject_HEAD
int valid; /* validity flag */
- PGconn *cnx; /* PostGres connection handle */
- PGresult *last_result; /* last result content */
-} pgobject;
+ PGconn *cnx; /* PostGres connection handle */
+ PGresult *last_result; /* last result content */
+} pgobject;
staticforward PyTypeObject PgType;
@@ -131,7 +131,7 @@ staticforward PyTypeObject PgType;
static PyObject *
pgobject_New(void)
{
- pgobject *pgobj;
+ pgobject *pgobj;
if ((pgobj = PyObject_NEW(pgobject, &PgType)) == NULL)
return NULL;
@@ -139,7 +139,7 @@ pgobject_New(void)
pgobj->valid = 1;
pgobj->last_result = NULL;
pgobj->cnx = NULL;
- return (PyObject*)pgobj;
+ return (PyObject *) pgobj;
}
/* pg query object */
@@ -147,11 +147,11 @@ pgobject_New(void)
typedef struct
{
PyObject_HEAD
- PGresult *last_result; /* last result content */
+ PGresult *last_result; /* last result content */
int result_type; /* type of previous result */
long current_pos; /* current position in last result */
long num_rows; /* number of (affected) rows */
-} pgqueryobject;
+} pgqueryobject;
staticforward PyTypeObject PgQueryType;
@@ -162,15 +162,15 @@ staticforward PyTypeObject PgQueryType;
typedef struct
{
PyObject_HEAD
- int valid; /* validity flag */
- pgobject *pgcnx; /* parent connection object */
- PGresult *last_result; /* last result content */
- int result_type; /* result type (DDL/DML/DQL) */
- long arraysize; /* array size for fetch method */
- int current_row; /* current selected row */
- int max_row; /* number of rows in the result */
- int num_fields; /* number of fields in each row */
-} pgsourceobject;
+ int valid; /* validity flag */
+ pgobject *pgcnx; /* parent connection object */
+ PGresult *last_result; /* last result content */
+ int result_type; /* result type (DDL/DML/DQL) */
+ long arraysize; /* array size for fetch method */
+ int current_row; /* current selected row */
+ int max_row; /* number of rows in the result */
+ int num_fields; /* number of fields in each row */
+} pgsourceobject;
staticforward PyTypeObject PgSourceType;
@@ -183,15 +183,15 @@ staticforward PyTypeObject PgSourceType;
typedef struct
{
PyObject_HEAD
- pgobject *pgcnx; /* parent connection object */
- Oid lo_oid; /* large object oid */
- int lo_fd; /* large object fd */
-} pglargeobject;
+ pgobject * pgcnx; /* parent connection object */
+ Oid lo_oid; /* large object oid */
+ int lo_fd; /* large object fd */
+} pglargeobject;
staticforward PyTypeObject PglargeType;
#define is_pglargeobject(v) ((v)->ob_type == &PglargeType)
-#endif /* LARGE_OBJECTS */
+#endif /* LARGE_OBJECTS */
/* --------------------------------------------------------------------- */
/* INTERNAL FUNCTIONS */
@@ -200,7 +200,8 @@ staticforward PyTypeObject PglargeType;
static int
check_cnx_obj(pgobject * self)
{
- if (!self->valid) {
+ if (!self->valid)
+ {
PyErr_SetString(PGError, "connection has been closed");
return 0;
}
@@ -242,7 +243,7 @@ check_lo_obj(pglargeobject * self, int level)
return 1;
}
-#endif /* LARGE_OBJECTS */
+#endif /* LARGE_OBJECTS */
/* checks source object validity */
static int
@@ -276,8 +277,8 @@ check_source_obj(pgsourceobject * self, int level)
int *
get_type_array(PGresult *result, int nfields)
{
- int *typ;
- int j;
+ int *typ;
+ int j;
if ((typ = malloc(sizeof(int) * nfields)) == NULL)
{
@@ -315,7 +316,7 @@ get_type_array(PGresult *result, int nfields)
/* prototypes for constructors */
-static pgsourceobject * pgsource_new(pgobject * pgcnx);
+static pgsourceobject *pgsource_new(pgobject * pgcnx);
/* --------------------------------------------------------------------- */
/* PG SOURCE OBJECT IMPLEMENTATION */
@@ -324,7 +325,7 @@ static pgsourceobject * pgsource_new(pgobject * pgcnx);
static pgsourceobject *
pgsource_new(pgobject * pgcnx)
{
- pgsourceobject * npgobj;
+ pgsourceobject *npgobj;
/* allocates new query object */
if ((npgobj = PyObject_NEW(pgsourceobject, &PgSourceType)) == NULL)
@@ -392,9 +393,9 @@ static char pgsource_execute__doc__[] =
static PyObject *
pgsource_execute(pgsourceobject * self, PyObject * args)
{
- char *query;
- const char *temp;
- long num_rows;
+ char *query;
+ const char *temp;
+ long num_rows;
/* checks validity */
if (!check_source_obj(self, CHECK_CNX))
@@ -419,11 +420,11 @@ pgsource_execute(pgsourceobject * self, PyObject * args)
/* gets result */
Py_BEGIN_ALLOW_THREADS
- self->last_result = PQexec(self->pgcnx->cnx, query);
+ self->last_result = PQexec(self->pgcnx->cnx, query);
Py_END_ALLOW_THREADS
/* checks result validity */
- if (!self->last_result)
+ if (!self->last_result)
{
PyErr_SetString(PyExc_ValueError, PQerrorMessage(self->pgcnx->cnx));
return NULL;
@@ -433,38 +434,39 @@ pgsource_execute(pgsourceobject * self, PyObject * args)
switch (PQresultStatus(self->last_result))
{
- /* query succeeded */
- case PGRES_TUPLES_OK: /* DQL: returns None (DB-SIG compliant) */
- self->result_type = RESULT_DQL;
- self->max_row = PQntuples(self->last_result);
- self->num_fields = PQnfields(self->last_result);
- Py_INCREF(Py_None);
- return Py_None;
- case PGRES_COMMAND_OK: /* other requests */
- case PGRES_COPY_OUT:
- case PGRES_COPY_IN:
- self->result_type = RESULT_DDL;
- temp = PQcmdTuples(self->last_result);
- num_rows = 1;
- if (temp[0] != 0) {
- self->result_type = RESULT_DML;
- num_rows = atol(temp);
- }
- return PyInt_FromLong(num_rows);
-
- /* query failed */
- case PGRES_EMPTY_QUERY:
- PyErr_SetString(PyExc_ValueError, "empty query.");
- break;
- case PGRES_BAD_RESPONSE:
- case PGRES_FATAL_ERROR:
- case PGRES_NONFATAL_ERROR:
- PyErr_SetString(PGError, PQerrorMessage(self->pgcnx->cnx));
- break;
- default:
- PyErr_SetString(PGError, "internal error: "
- "unknown result status.");
- break;
+ /* query succeeded */
+ case PGRES_TUPLES_OK: /* DQL: returns None (DB-SIG compliant) */
+ self->result_type = RESULT_DQL;
+ self->max_row = PQntuples(self->last_result);
+ self->num_fields = PQnfields(self->last_result);
+ Py_INCREF(Py_None);
+ return Py_None;
+ case PGRES_COMMAND_OK: /* other requests */
+ case PGRES_COPY_OUT:
+ case PGRES_COPY_IN:
+ self->result_type = RESULT_DDL;
+ temp = PQcmdTuples(self->last_result);
+ num_rows = 1;
+ if (temp[0] != 0)
+ {
+ self->result_type = RESULT_DML;
+ num_rows = atol(temp);
+ }
+ return PyInt_FromLong(num_rows);
+
+ /* query failed */
+ case PGRES_EMPTY_QUERY:
+ PyErr_SetString(PyExc_ValueError, "empty query.");
+ break;
+ case PGRES_BAD_RESPONSE:
+ case PGRES_FATAL_ERROR:
+ case PGRES_NONFATAL_ERROR:
+ PyErr_SetString(PGError, PQerrorMessage(self->pgcnx->cnx));
+ break;
+ default:
+ PyErr_SetString(PGError, "internal error: "
+ "unknown result status.");
+ break;
}
/* frees result and returns error */
@@ -492,7 +494,7 @@ pgsource_oidstatus(pgsourceobject * self, PyObject * args)
if ((args != NULL) && (!PyArg_ParseTuple(args, "")))
{
PyErr_SetString(PyExc_SyntaxError,
- "method oidstatus() takes no parameters.");
+ "method oidstatus() takes no parameters.");
return NULL;
}
@@ -512,9 +514,12 @@ static char pgsource_fetch__doc__[] =
static PyObject *
pgsource_fetch(pgsourceobject * self, PyObject * args)
{
- PyObject *rowtuple, *reslist, *str;
- int i, j;
- long size;
+ PyObject *rowtuple,
+ *reslist,
+ *str;
+ int i,
+ j;
+ long size;
/* checks validity */
if (!check_source_obj(self, CHECK_RESULT | CHECK_DQL))
@@ -525,7 +530,7 @@ pgsource_fetch(pgsourceobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "|l", &size))
{
PyErr_SetString(PyExc_SyntaxError,
- "fetch(num), with num (integer, optional).");
+ "fetch(num), with num (integer, optional).");
return NULL;
}
@@ -578,13 +583,13 @@ pgsource_move(pgsourceobject * self, PyObject * args, int move)
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
- char errbuf[256];
+ char errbuf[256];
#ifdef NO_SNPRINTF
sprintf(errbuf, "method %s() takes no parameter.", __movename[move]);
#else
snprintf(errbuf, sizeof(errbuf),
- "method %s() takes no parameter.", __movename[move]);
+ "method %s() takes no parameter.", __movename[move]);
#endif
PyErr_SetString(PyExc_SyntaxError, errbuf);
@@ -592,19 +597,22 @@ pgsource_move(pgsourceobject * self, PyObject * args, int move)
}
/* changes the current row */
- switch(move) {
- case QUERY_MOVEFIRST:
- self->current_row = 0;
- break;
- case QUERY_MOVELAST:
- self->current_row = self->max_row - 1;
- break;
- case QUERY_MOVENEXT:
- if (self->current_row != self->max_row) self->current_row++;
- break;
- case QUERY_MOVEPREV:
- if (self->current_row > 0) self->current_row--;
- break;
+ switch (move)
+ {
+ case QUERY_MOVEFIRST:
+ self->current_row = 0;
+ break;
+ case QUERY_MOVELAST:
+ self->current_row = self->max_row - 1;
+ break;
+ case QUERY_MOVENEXT:
+ if (self->current_row != self->max_row)
+ self->current_row++;
+ break;
+ case QUERY_MOVEPREV:
+ if (self->current_row > 0)
+ self->current_row--;
+ break;
}
Py_INCREF(Py_None);
@@ -653,9 +661,9 @@ pgsource_moveprev(pgsourceobject * self, PyObject * args)
/* finds field number from string/integer (internal use only) */
static int
-pgsource_fieldindex(pgsourceobject * self, PyObject * param, const char * usage)
+pgsource_fieldindex(pgsourceobject * self, PyObject * param, const char *usage)
{
- int num;
+ int num;
/* checks validity */
if (!check_source_obj(self, CHECK_RESULT | CHECK_DQL))
@@ -663,13 +671,9 @@ pgsource_fieldindex(pgsourceobject * self, PyObject * param, const char * usage)
/* gets field number */
if (PyString_Check(param))
- {
num = PQfnumber(self->last_result, PyString_AsString(param));
- }
else if (PyInt_Check(param))
- {
num = PyInt_AsLong(param);
- }
else
{
PyErr_SetString(PyExc_TypeError, usage);
@@ -677,7 +681,7 @@ pgsource_fieldindex(pgsourceobject * self, PyObject * param, const char * usage)
}
/* checks field validity */
- if (num<0 || num>=self->num_fields)
+ if (num < 0 || num >= self->num_fields)
{
PyErr_SetString(PyExc_ValueError, "Unknown field.");
return -1;
@@ -690,7 +694,7 @@ pgsource_fieldindex(pgsourceobject * self, PyObject * param, const char * usage)
static PyObject *
pgsource_buildinfo(pgsourceobject * self, int num)
{
- PyObject * result;
+ PyObject *result;
/* allocates tuple */
result = PyTuple_New(3);
@@ -700,9 +704,9 @@ pgsource_buildinfo(pgsourceobject * self, int num)
/* affects field information */
PyTuple_SET_ITEM(result, 0, PyInt_FromLong(num));
PyTuple_SET_ITEM(result, 1,
- PyString_FromString(PQfname(self->last_result, num)));
+ PyString_FromString(PQfname(self->last_result, num)));
PyTuple_SET_ITEM(result, 2,
- PyInt_FromLong(PQftype(self->last_result, num)));
+ PyInt_FromLong(PQftype(self->last_result, num)));
return result;
}
@@ -715,8 +719,9 @@ static char pgsource_listinfo__doc__[] =
static PyObject *
pgsource_listinfo(pgsourceobject * self, PyObject * args)
{
- int i;
- PyObject * result, * info;
+ int i;
+ PyObject *result,
+ *info;
/* checks validity */
if (!check_source_obj(self, CHECK_RESULT | CHECK_DQL))
@@ -726,7 +731,7 @@ pgsource_listinfo(pgsourceobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_TypeError,
- "method listinfo() takes no parameter.");
+ "method listinfo() takes no parameter.");
return NULL;
}
@@ -734,7 +739,7 @@ pgsource_listinfo(pgsourceobject * self, PyObject * args)
if ((result = PyTuple_New(self->num_fields)) == NULL)
return NULL;
- for (i=0; i<self->num_fields; i++)
+ for (i = 0; i < self->num_fields; i++)
{
info = pgsource_buildinfo(self, i);
if (!info)
@@ -758,9 +763,9 @@ static PyObject *
pgsource_fieldinfo(pgsourceobject * self, PyObject * args)
{
static const char short_usage[] =
- "fieldinfo(desc), with desc (string|integer).";
- int num;
- PyObject * param;
+ "fieldinfo(desc), with desc (string|integer).";
+ int num;
+ PyObject *param;
/* gets args */
if (!PyArg_ParseTuple(args, "O", &param))
@@ -785,9 +790,9 @@ static PyObject *
pgsource_field(pgsourceobject * self, PyObject * args)
{
static const char short_usage[] =
- "field(desc), with desc (string|integer).";
- int num;
- PyObject * param;
+ "field(desc), with desc (string|integer).";
+ int num;
+ PyObject *param;
/* gets args */
if (!PyArg_ParseTuple(args, "O", &param))
@@ -801,34 +806,34 @@ pgsource_field(pgsourceobject * self, PyObject * args)
return NULL;
return PyString_FromString(PQgetvalue(self->last_result,
- self->current_row, num));
+ self->current_row, num));
}
/* query object methods */
static PyMethodDef pgsource_methods[] = {
- { "close", (PyCFunction) pgsource_close, 1,
- pgsource_close__doc__ },
- { "execute", (PyCFunction) pgsource_execute, 1,
- pgsource_execute__doc__ },
- { "oidstatus", (PyCFunction) pgsource_oidstatus, 1,
- pgsource_oidstatus__doc__ },
- { "fetch", (PyCFunction) pgsource_fetch, 1,
- pgsource_fetch__doc__ },
- { "movefirst", (PyCFunction) pgsource_movefirst, 1,
- pgsource_movefirst__doc__ },
- { "movelast", (PyCFunction) pgsource_movelast, 1,
- pgsource_movelast__doc__ },
- { "movenext", (PyCFunction) pgsource_movenext, 1,
- pgsource_movenext__doc__ },
- { "moveprev", (PyCFunction) pgsource_moveprev, 1,
- pgsource_moveprev__doc__ },
- { "field", (PyCFunction) pgsource_field, 1,
- pgsource_field__doc__ },
- { "fieldinfo", (PyCFunction) pgsource_fieldinfo, 1,
- pgsource_fieldinfo__doc__ },
- { "listinfo", (PyCFunction) pgsource_listinfo, 1,
- pgsource_listinfo__doc__ },
- { NULL, NULL }
+ {"close", (PyCFunction) pgsource_close, 1,
+ pgsource_close__doc__},
+ {"execute", (PyCFunction) pgsource_execute, 1,
+ pgsource_execute__doc__},
+ {"oidstatus", (PyCFunction) pgsource_oidstatus, 1,
+ pgsource_oidstatus__doc__},
+ {"fetch", (PyCFunction) pgsource_fetch, 1,
+ pgsource_fetch__doc__},
+ {"movefirst", (PyCFunction) pgsource_movefirst, 1,
+ pgsource_movefirst__doc__},
+ {"movelast", (PyCFunction) pgsource_movelast, 1,
+ pgsource_movelast__doc__},
+ {"movenext", (PyCFunction) pgsource_movenext, 1,
+ pgsource_movenext__doc__},
+ {"moveprev", (PyCFunction) pgsource_moveprev, 1,
+ pgsource_moveprev__doc__},
+ {"field", (PyCFunction) pgsource_field, 1,
+ pgsource_field__doc__},
+ {"fieldinfo", (PyCFunction) pgsource_fieldinfo, 1,
+ pgsource_fieldinfo__doc__},
+ {"listinfo", (PyCFunction) pgsource_listinfo, 1,
+ pgsource_listinfo__doc__},
+ {NULL, NULL}
};
/* gets query object attributes */
@@ -864,8 +869,9 @@ pgsource_getattr(pgsourceobject * self, char *name)
return PyInt_FromLong(self->num_fields);
/* attributes list */
- if (!strcmp(name, "__members__")) {
- PyObject *list = PyList_New(5);
+ if (!strcmp(name, "__members__"))
+ {
+ PyObject *list = PyList_New(5);
PyList_SET_ITEM(list, 0, PyString_FromString("pgcnx"));
PyList_SET_ITEM(list, 1, PyString_FromString("arraysize"));
@@ -890,7 +896,7 @@ pgsource_getattr(pgsourceobject * self, char *name)
/* sets query object attributes */
static int
-pgsource_setattr(pgsourceobject * self, char * name, PyObject * v)
+pgsource_setattr(pgsourceobject * self, char *name, PyObject * v)
{
/* arraysize */
if (!strcmp(name, "arraysize"))
@@ -914,26 +920,26 @@ pgsource_setattr(pgsourceobject * self, char * name, PyObject * v)
static int
pgsource_print(pgsourceobject * self, FILE *fp, int flags)
{
- PQprintOpt op;
+ PQprintOpt op;
switch (self->result_type)
{
- case RESULT_DQL:
- memset(&op, 0, sizeof(op));
- op.align = 1;
- op.header = 1;
- op.fieldSep = "|";
- op.pager = 1;
- PQprint(fp, self->last_result, &op);
- break;
- case RESULT_DDL:
- case RESULT_DML:
- fputs(PQcmdStatus(self->last_result), fp);
- break;
- case RESULT_EMPTY:
- default:
- fputs("Empty PostgreSQL source object.", fp);
- break;
+ case RESULT_DQL:
+ memset(&op, 0, sizeof(op));
+ op.align = 1;
+ op.header = 1;
+ op.fieldSep = "|";
+ op.pager = 1;
+ PQprint(fp, self->last_result, &op);
+ break;
+ case RESULT_DDL:
+ case RESULT_DML:
+ fputs(PQcmdStatus(self->last_result), fp);
+ break;
+ case RESULT_EMPTY:
+ default:
+ fputs("Empty PostgreSQL source object.", fp);
+ break;
}
return 0;
@@ -947,21 +953,21 @@ staticforward PyTypeObject PgSourceType = {
PyObject_HEAD_INIT(NULL)
#endif
- 0, /* ob_size */
- "pgsourceobject", /* tp_name */
- sizeof(pgsourceobject), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* ob_size */
+ "pgsourceobject", /* tp_name */
+ sizeof(pgsourceobject), /* tp_basicsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor) pgsource_dealloc, /* tp_dealloc */
- (printfunc) pgsource_print, /* tp_print */
- (getattrfunc) pgsource_getattr, /* tp_getattr */
- (setattrfunc) pgsource_setattr, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
+ (destructor) pgsource_dealloc, /* tp_dealloc */
+ (printfunc) pgsource_print, /* tp_print */
+ (getattrfunc) pgsource_getattr, /* tp_getattr */
+ (setattrfunc) pgsource_setattr, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
};
/* --------------------------------------------------------------------- */
@@ -973,7 +979,7 @@ staticforward PyTypeObject PgSourceType = {
static pglargeobject *
pglarge_new(pgobject * pgcnx, Oid oid)
{
- pglargeobject * npglo;
+ pglargeobject *npglo;
if ((npglo = PyObject_NEW(pglargeobject, &PglargeType)) == NULL)
return NULL;
@@ -999,13 +1005,14 @@ pglarge_dealloc(pglargeobject * self)
/* opens large object */
static char pglarge_open__doc__[] =
- "open(mode) -- open access to large object with specified mode "
- "(INV_READ, INV_WRITE constants defined by module).";
+"open(mode) -- open access to large object with specified mode "
+"(INV_READ, INV_WRITE constants defined by module).";
static PyObject *
pglarge_open(pglargeobject * self, PyObject * args)
{
- int mode, fd;
+ int mode,
+ fd;
/* check validity */
if (!check_lo_obj(self, CHECK_CLOSE))
@@ -1033,7 +1040,7 @@ pglarge_open(pglargeobject * self, PyObject * args)
/* close large object */
static char pglarge_close__doc__[] =
- "close() -- close access to large object data.";
+"close() -- close access to large object data.";
static PyObject *
pglarge_close(pglargeobject * self, PyObject * args)
@@ -1042,7 +1049,7 @@ pglarge_close(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method close() takes no parameters.");
+ "method close() takes no parameters.");
return NULL;
}
@@ -1065,14 +1072,14 @@ pglarge_close(pglargeobject * self, PyObject * args)
/* reads from large object */
static char pglarge_read__doc__[] =
- "read(integer) -- read from large object to sized string. "
- "Object must be opened in read mode before calling this method.";
+"read(integer) -- read from large object to sized string. "
+"Object must be opened in read mode before calling this method.";
static PyObject *
pglarge_read(pglargeobject * self, PyObject * args)
{
int size;
- PyObject *buffer;
+ PyObject *buffer;
/* checks validity */
if (!check_lo_obj(self, CHECK_OPEN))
@@ -1108,14 +1115,15 @@ pglarge_read(pglargeobject * self, PyObject * args)
/* write to large object */
static char pglarge_write__doc__[] =
- "write(string) -- write sized string to large object. "
- "Object must be opened in read mode before calling this method.";
+"write(string) -- write sized string to large object. "
+"Object must be opened in read mode before calling this method.";
static PyObject *
pglarge_write(pglargeobject * self, PyObject * args)
{
- char *buffer;
- int size, bufsize;
+ char *buffer;
+ int size,
+ bufsize;
/* checks validity */
if (!check_lo_obj(self, CHECK_OPEN))
@@ -1125,13 +1133,13 @@ pglarge_write(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "s#", &buffer, &bufsize))
{
PyErr_SetString(PyExc_TypeError,
- "write(buffer), with buffer (sized string).");
+ "write(buffer), with buffer (sized string).");
return NULL;
}
/* sends query */
if ((size = lo_write(self->pgcnx->cnx, self->lo_fd, buffer,
- bufsize)) < bufsize)
+ bufsize)) < bufsize)
{
PyErr_SetString(PyExc_IOError, "buffer truncated during write.");
return NULL;
@@ -1144,15 +1152,17 @@ pglarge_write(pglargeobject * self, PyObject * args)
/* go to position in large object */
static char pglarge_seek__doc__[] =
- "seek(off, whence) -- move to specified position. Object must be opened "
- "before calling this method. whence can be SEEK_SET, SEEK_CUR or SEEK_END, "
- "constants defined by module.";
+"seek(off, whence) -- move to specified position. Object must be opened "
+"before calling this method. whence can be SEEK_SET, SEEK_CUR or SEEK_END, "
+"constants defined by module.";
static PyObject *
pglarge_lseek(pglargeobject * self, PyObject * args)
{
/* offset and whence are initialized to keep compiler happy */
- int ret, offset = 0, whence = 0;
+ int ret,
+ offset = 0,
+ whence = 0;
/* checks validity */
if (!check_lo_obj(self, CHECK_OPEN))
@@ -1162,7 +1172,7 @@ pglarge_lseek(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "ii", &offset, &whence))
{
PyErr_SetString(PyExc_TypeError,
- "lseek(offset, whence), with offset and whence (integers).");
+ "lseek(offset, whence), with offset and whence (integers).");
return NULL;
}
@@ -1179,19 +1189,20 @@ pglarge_lseek(pglargeobject * self, PyObject * args)
/* gets large object size */
static char pglarge_size__doc__[] =
- "size() -- return large object size. "
- "Object must be opened before calling this method.";
+"size() -- return large object size. "
+"Object must be opened before calling this method.";
static PyObject *
pglarge_size(pglargeobject * self, PyObject * args)
{
- int start, end;
+ int start,
+ end;
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method size() takes no parameters.");
+ "method size() takes no parameters.");
return NULL;
}
@@ -1214,10 +1225,10 @@ pglarge_size(pglargeobject * self, PyObject * args)
}
/* move back to start position */
- if ((start = lo_lseek(self->pgcnx->cnx,self->lo_fd,start,SEEK_SET)) == -1)
+ if ((start = lo_lseek(self->pgcnx->cnx, self->lo_fd, start, SEEK_SET)) == -1)
{
PyErr_SetString(PyExc_IOError,
- "error while moving back to first position.");
+ "error while moving back to first position.");
return NULL;
}
@@ -1227,19 +1238,19 @@ pglarge_size(pglargeobject * self, PyObject * args)
/* gets large object cursor position */
static char pglarge_tell__doc__[] =
- "tell() -- give current position in large object. "
- "Object must be opened before calling this method.";
+"tell() -- give current position in large object. "
+"Object must be opened before calling this method.";
static PyObject *
pglarge_tell(pglargeobject * self, PyObject * args)
{
- int start;
+ int start;
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method tell() takes no parameters.");
+ "method tell() takes no parameters.");
return NULL;
}
@@ -1260,13 +1271,13 @@ pglarge_tell(pglargeobject * self, PyObject * args)
/* exports large object as unix file */
static char pglarge_export__doc__[] =
- "export(string) -- export large object data to specified file. "
- "Object must be closed when calling this method.";
+"export(string) -- export large object data to specified file. "
+"Object must be closed when calling this method.";
static PyObject *
pglarge_export(pglargeobject * self, PyObject * args)
{
- char *name;
+ char *name;
/* checks validity */
if (!check_lo_obj(self, CHECK_CLOSE))
@@ -1276,7 +1287,7 @@ pglarge_export(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "s", &name))
{
PyErr_SetString(PyExc_TypeError,
- "export(filename), with filename (string).");
+ "export(filename), with filename (string).");
return NULL;
}
@@ -1293,8 +1304,8 @@ pglarge_export(pglargeobject * self, PyObject * args)
/* deletes a large object */
static char pglarge_unlink__doc__[] =
- "unlink() -- destroy large object. "
- "Object must be closed when calling this method.";
+"unlink() -- destroy large object. "
+"Object must be closed when calling this method.";
static PyObject *
pglarge_unlink(pglargeobject * self, PyObject * args)
@@ -1303,7 +1314,7 @@ pglarge_unlink(pglargeobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method unlink() takes no parameters.");
+ "method unlink() takes no parameters.");
return NULL;
}
@@ -1325,15 +1336,15 @@ pglarge_unlink(pglargeobject * self, PyObject * args)
/* large object methods */
static struct PyMethodDef pglarge_methods[] = {
- {"open", (PyCFunction) pglarge_open, 1, pglarge_open__doc__ },
- {"close", (PyCFunction) pglarge_close, 1, pglarge_close__doc__ },
- {"read", (PyCFunction) pglarge_read, 1, pglarge_read__doc__ },
- {"write", (PyCFunction) pglarge_write, 1, pglarge_write__doc__ },
- {"seek", (PyCFunction) pglarge_lseek, 1, pglarge_seek__doc__ },
- {"size", (PyCFunction) pglarge_size, 1, pglarge_size__doc__ },
- {"tell", (PyCFunction) pglarge_tell, 1, pglarge_tell__doc__ },
- {"export", (PyCFunction) pglarge_export, 1, pglarge_export__doc__ },
- {"unlink", (PyCFunction) pglarge_unlink, 1, pglarge_unlink__doc__ },
+ {"open", (PyCFunction) pglarge_open, 1, pglarge_open__doc__},
+ {"close", (PyCFunction) pglarge_close, 1, pglarge_close__doc__},
+ {"read", (PyCFunction) pglarge_read, 1, pglarge_read__doc__},
+ {"write", (PyCFunction) pglarge_write, 1, pglarge_write__doc__},
+ {"seek", (PyCFunction) pglarge_lseek, 1, pglarge_seek__doc__},
+ {"size", (PyCFunction) pglarge_size, 1, pglarge_size__doc__},
+ {"tell", (PyCFunction) pglarge_tell, 1, pglarge_tell__doc__},
+ {"export", (PyCFunction) pglarge_export, 1, pglarge_export__doc__},
+ {"unlink", (PyCFunction) pglarge_unlink, 1, pglarge_unlink__doc__},
{NULL, NULL}
};
@@ -1373,7 +1384,7 @@ pglarge_getattr(pglargeobject * self, char *name)
/* attributes list */
if (!strcmp(name, "__members__"))
{
- PyObject *list = PyList_New(3);
+ PyObject *list = PyList_New(3);
if (list)
{
@@ -1401,16 +1412,16 @@ pglarge_getattr(pglargeobject * self, char *name)
static int
pglarge_print(pglargeobject * self, FILE *fp, int flags)
{
- char print_buffer[128];
+ char print_buffer[128];
if (self->lo_fd >= 0)
{
#ifdef NO_SNPRINTF
sprintf(print_buffer,
- "Opened large object, oid %ld", (long)self->lo_oid);
+ "Opened large object, oid %ld", (long) self->lo_oid);
#else
snprintf(print_buffer, sizeof(print_buffer),
- "Opened large object, oid %ld", (long)self->lo_oid);
+ "Opened large object, oid %ld", (long) self->lo_oid);
#endif
fputs(print_buffer, fp);
}
@@ -1418,10 +1429,10 @@ pglarge_print(pglargeobject * self, FILE *fp, int flags)
{
#ifdef NO_SNPRINTF
sprintf(print_buffer,
- "Closed large object, oid %ld", (long)self->lo_oid);
+ "Closed large object, oid %ld", (long) self->lo_oid);
#else
snprintf(print_buffer, sizeof(print_buffer),
- "Closed large object, oid %ld", (long)self->lo_oid);
+ "Closed large object, oid %ld", (long) self->lo_oid);
#endif
fputs(print_buffer, fp);
}
@@ -1432,25 +1443,25 @@ pglarge_print(pglargeobject * self, FILE *fp, int flags)
/* object type definition */
staticforward PyTypeObject PglargeType = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "pglarge", /* tp_name */
- sizeof(pglargeobject), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* ob_size */
+ "pglarge", /* tp_name */
+ sizeof(pglargeobject), /* tp_basicsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor) pglarge_dealloc, /* tp_dealloc */
- (printfunc) pglarge_print, /* tp_print */
- (getattrfunc) pglarge_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
+ (destructor) pglarge_dealloc, /* tp_dealloc */
+ (printfunc) pglarge_print, /* tp_print */
+ (getattrfunc) pglarge_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
};
-#endif /* LARGE_OBJECTS */
+#endif /* LARGE_OBJECTS */
/* --------------------------------------------------------------------- */
@@ -1458,29 +1469,35 @@ staticforward PyTypeObject PglargeType = {
/* connects to a database */
static char connect__doc__[] =
- "connect(dbname, host, port, opt, tty) -- connect to a PostgreSQL database "
- "using specified parameters (optionals, keywords aware).";
+"connect(dbname, host, port, opt, tty) -- connect to a PostgreSQL database "
+"using specified parameters (optionals, keywords aware).";
static PyObject *
-pgconnect(pgobject *self, PyObject *args, PyObject *dict)
-{
- static const char *kwlist[] = { "dbname", "host", "port", "opt",
- "tty", "user", "passwd" , NULL };
- char *pghost, *pgopt, *pgtty, *pgdbname, *pguser, *pgpasswd;
- int pgport;
- char port_buffer[20];
- pgobject *npgobj;
+pgconnect(pgobject * self, PyObject * args, PyObject * dict)
+{
+ static const char *kwlist[] = {"dbname", "host", "port", "opt",
+ "tty", "user", "passwd", NULL};
+ char *pghost,
+ *pgopt,
+ *pgtty,
+ *pgdbname,
+ *pguser,
+ *pgpasswd;
+ int pgport;
+ char port_buffer[20];
+ pgobject *npgobj;
pghost = pgopt = pgtty = pgdbname = pguser = pgpasswd = NULL;
pgport = -1;
- /* parses standard arguments
- * With the right compiler warnings, this will issue a diagnostic.
- * There is really no way around it. If I don't declare kwlist as
- * const char *kwlist[] then it complains when I try to assign all
- * those constant strings to it. */
+ /*
+ * parses standard arguments With the right compiler warnings, this
+ * will issue a diagnostic. There is really no way around it. If I
+ * don't declare kwlist as const char *kwlist[] then it complains when
+ * I try to assign all those constant strings to it.
+ */
if (!PyArg_ParseTupleAndKeywords(args, dict, "|zzlzzzz", (char **) kwlist,
- &pgdbname, &pghost, &pgport, &pgopt, &pgtty, &pguser, &pgpasswd))
+ &pgdbname, &pghost, &pgport, &pgopt, &pgtty, &pguser, &pgpasswd))
return NULL;
#ifdef DEFAULT_VARS
@@ -1505,9 +1522,9 @@ pgconnect(pgobject *self, PyObject *args, PyObject *dict)
if ((!pgpasswd) && (pg_default_passwd != Py_None))
pgpasswd = PyString_AsString(pg_default_passwd);
-#endif /* DEFAULT_VARS */
+#endif /* DEFAULT_VARS */
- if ((npgobj = (pgobject*)pgobject_New()) == NULL)
+ if ((npgobj = (pgobject *) pgobject_New()) == NULL)
return NULL;
if (pgport != -1)
@@ -1515,11 +1532,11 @@ pgconnect(pgobject *self, PyObject *args, PyObject *dict)
memset(port_buffer, 0, sizeof(port_buffer));
sprintf(port_buffer, "%d", pgport);
npgobj->cnx = PQsetdbLogin(pghost, port_buffer, pgopt, pgtty, pgdbname,
- pguser, pgpasswd);
+ pguser, pgpasswd);
}
else
npgobj->cnx = PQsetdbLogin(pghost, NULL, pgopt, pgtty, pgdbname,
- pguser, pgpasswd);
+ pguser, pgpasswd);
if (PQstatus(npgobj->cnx) == CONNECTION_BAD)
{
@@ -1545,12 +1562,12 @@ pg_dealloc(pgobject * self)
/* close without deleting */
static char pg_close__doc__[] =
- "close() -- close connection. All instances of the connection object and "
- "derived objects (queries and large objects) can no longer be used after "
- "this call.";
+"close() -- close connection. All instances of the connection object and "
+"derived objects (queries and large objects) can no longer be used after "
+"this call.";
static PyObject *
-pg_close(pgobject *self, PyObject *args)
+pg_close(pgobject * self, PyObject * args)
{
/* gets args */
if (!PyArg_ParseTuple(args, ""))
@@ -1578,9 +1595,9 @@ pgquery_dealloc(pgqueryobject * self)
/* resets connection */
static char pg_reset__doc__[] =
- "reset() -- reset connection with current parameters. All derived queries "
- "and large objects derived from this connection will not be usable after "
- "this call.";
+"reset() -- reset connection with current parameters. All derived queries "
+"and large objects derived from this connection will not be usable after "
+"this call.";
static PyObject *
pg_reset(pgobject * self, PyObject * args)
@@ -1595,7 +1612,7 @@ pg_reset(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method reset() takes no parameters.");
+ "method reset() takes no parameters.");
return NULL;
}
@@ -1607,7 +1624,7 @@ pg_reset(pgobject * self, PyObject * args)
/* get connection socket */
static char pg_fileno__doc__[] =
- "fileno() -- return database connection socket file handle.";
+"fileno() -- return database connection socket file handle.";
static PyObject *
pg_fileno(pgobject * self, PyObject * args)
@@ -1622,7 +1639,7 @@ pg_fileno(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method fileno() takes no parameters.");
+ "method fileno() takes no parameters.");
return NULL;
}
@@ -1635,7 +1652,7 @@ pg_fileno(pgobject * self, PyObject * args)
/* get number of rows */
static char pgquery_ntuples__doc__[] =
- "ntuples() -- returns number of tuples returned by query.";
+"ntuples() -- returns number of tuples returned by query.";
static PyObject *
pgquery_ntuples(pgqueryobject * self, PyObject * args)
@@ -1644,7 +1661,7 @@ pgquery_ntuples(pgqueryobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method ntuples() takes no parameters.");
+ "method ntuples() takes no parameters.");
return NULL;
}
@@ -1653,20 +1670,22 @@ pgquery_ntuples(pgqueryobject * self, PyObject * args)
/* list fields names from query result */
static char pgquery_listfields__doc__[] =
- "listfields() -- Lists field names from result.";
+"listfields() -- Lists field names from result.";
static PyObject *
pgquery_listfields(pgqueryobject * self, PyObject * args)
{
- int i, n;
- char *name;
- PyObject *fieldstuple, *str;
+ int i,
+ n;
+ char *name;
+ PyObject *fieldstuple,
+ *str;
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method listfields() takes no parameters.");
+ "method listfields() takes no parameters.");
return NULL;
}
@@ -1686,19 +1705,19 @@ pgquery_listfields(pgqueryobject * self, PyObject * args)
/* get field name from last result */
static char pgquery_fieldname__doc__[] =
- "fieldname() -- returns name of field from result from its position.";
+"fieldname() -- returns name of field from result from its position.";
static PyObject *
pgquery_fieldname(pgqueryobject * self, PyObject * args)
{
- int i;
- char *name;
+ int i;
+ char *name;
/* gets args */
if (!PyArg_ParseTuple(args, "i", &i))
{
PyErr_SetString(PyExc_TypeError,
- "fieldname(number), with number(integer).");
+ "fieldname(number), with number(integer).");
return NULL;
}
@@ -1716,13 +1735,13 @@ pgquery_fieldname(pgqueryobject * self, PyObject * args)
/* gets fields number from name in last result */
static char pgquery_fieldnum__doc__[] =
- "fieldnum() -- returns position in query for field from its name.";
+"fieldnum() -- returns position in query for field from its name.";
static PyObject *
pgquery_fieldnum(pgqueryobject * self, PyObject * args)
{
- char *name;
- int num;
+ char *name;
+ int num;
/* gets args */
if (!PyArg_ParseTuple(args, "s", &name))
@@ -1743,21 +1762,27 @@ pgquery_fieldnum(pgqueryobject * self, PyObject * args)
/* retrieves last result */
static char pgquery_getresult__doc__[] =
- "getresult() -- Gets the result of a query. The result is returned "
- "as a list of rows, each one a list of fields in the order returned "
- "by the server.";
+"getresult() -- Gets the result of a query. The result is returned "
+"as a list of rows, each one a list of fields in the order returned "
+"by the server.";
static PyObject *
pgquery_getresult(pgqueryobject * self, PyObject * args)
{
- PyObject *rowtuple, *reslist, *val;
- int i, j, m, n, *typ;
+ PyObject *rowtuple,
+ *reslist,
+ *val;
+ int i,
+ j,
+ m,
+ n,
+ *typ;
/* checks args (args == NULL for an internal call) */
if ((args != NULL) && (!PyArg_ParseTuple(args, "")))
{
PyErr_SetString(PyExc_SyntaxError,
- "method getresult() takes no parameters.");
+ "method getresult() takes no parameters.");
return NULL;
}
@@ -1808,44 +1833,46 @@ pgquery_getresult(pgqueryobject * self, PyObject * args)
for (j = 0; j < n; j++)
{
- int k;
- char *s = PQgetvalue(self->last_result, i, j);
- char cashbuf[64];
+ int k;
+ char *s = PQgetvalue(self->last_result, i, j);
+ char cashbuf[64];
if (PQgetisnull(self->last_result, i, j))
{
Py_INCREF(Py_None);
val = Py_None;
}
- else switch (typ[j])
- {
- case 1:
- val = PyInt_FromLong(strtol(s, NULL, 10));
- break;
+ else
+ switch (typ[j])
+ {
+ case 1:
+ val = PyInt_FromLong(strtol(s, NULL, 10));
+ break;
- case 2:
- val = PyFloat_FromDouble(strtod(s, NULL));
- break;
+ case 2:
+ val = PyFloat_FromDouble(strtod(s, NULL));
+ break;
- case 3: /* get rid of the '$' and commas */
- if (*s == '$') /* there's talk of getting rid of it */
- s++;
+ case 3: /* get rid of the '$' and commas */
+ if (*s == '$') /* there's talk of getting rid of
+ * it */
+ s++;
- if ((s[0] == '-' || s[0] == '(') && s[1] == '$')
- *(++s) = '-';
+ if ((s[0] == '-' || s[0] == '(') && s[1] == '$')
+ *(++s) = '-';
- for (k = 0; *s; s++)
- if (*s != ',')
- cashbuf[k++] = *s;
+ for (k = 0; *s; s++)
+ if (*s != ',')
+ cashbuf[k++] = *s;
- cashbuf[k] = 0;
- val = PyFloat_FromDouble(strtod(cashbuf, NULL));
- break;
+ cashbuf[k] = 0;
+ val = PyFloat_FromDouble(strtod(cashbuf, NULL));
+ break;
- default:
- val = PyString_FromString(s);
- break;
- }
+ default:
+ val = PyString_FromString(s);
+ break;
+ }
if (val == NULL)
{
@@ -1870,21 +1897,27 @@ exit:
/* retrieves last result as a list of dictionaries*/
static char pgquery_dictresult__doc__[] =
- "dictresult() -- Gets the result of a query. The result is returned "
- "as a list of rows, each one a dictionary with the field names used "
- "as the labels.";
+"dictresult() -- Gets the result of a query. The result is returned "
+"as a list of rows, each one a dictionary with the field names used "
+"as the labels.";
static PyObject *
pgquery_dictresult(pgqueryobject * self, PyObject * args)
{
- PyObject *dict, *reslist, *val;
- int i, j, m, n, *typ;
+ PyObject *dict,
+ *reslist,
+ *val;
+ int i,
+ j,
+ m,
+ n,
+ *typ;
/* checks args (args == NULL for an internal call) */
if ((args != NULL) && (!PyArg_ParseTuple(args, "")))
{
PyErr_SetString(PyExc_SyntaxError,
- "method getresult() takes no parameters.");
+ "method getresult() takes no parameters.");
return NULL;
}
@@ -1935,44 +1968,46 @@ pgquery_dictresult(pgqueryobject * self, PyObject * args)
for (j = 0; j < n; j++)
{
- int k;
- char *s = PQgetvalue(self->last_result, i, j);
- char cashbuf[64];
+ int k;
+ char *s = PQgetvalue(self->last_result, i, j);
+ char cashbuf[64];
if (PQgetisnull(self->last_result, i, j))
{
Py_INCREF(Py_None);
val = Py_None;
}
- else switch (typ[j])
- {
- case 1:
- val = PyInt_FromLong(strtol(s, NULL, 10));
- break;
+ else
+ switch (typ[j])
+ {
+ case 1:
+ val = PyInt_FromLong(strtol(s, NULL, 10));
+ break;
- case 2:
- val = PyFloat_FromDouble(strtod(s, NULL));
- break;
+ case 2:
+ val = PyFloat_FromDouble(strtod(s, NULL));
+ break;
- case 3: /* get rid of the '$' and commas */
- if (*s == '$') /* there's talk of getting rid of it */
- s++;
+ case 3: /* get rid of the '$' and commas */
+ if (*s == '$') /* there's talk of getting rid of
+ * it */
+ s++;
- if ((s[0] == '-' || s[0] == '(') && s[1] == '$')
- *(++s) = '-';
+ if ((s[0] == '-' || s[0] == '(') && s[1] == '$')
+ *(++s) = '-';
- for (k = 0; *s; s++)
- if (*s != ',')
- cashbuf[k++] = *s;
+ for (k = 0; *s; s++)
+ if (*s != ',')
+ cashbuf[k++] = *s;
- cashbuf[k] = 0;
- val = PyFloat_FromDouble(strtod(cashbuf, NULL));
- break;
+ cashbuf[k] = 0;
+ val = PyFloat_FromDouble(strtod(cashbuf, NULL));
+ break;
- default:
- val = PyString_FromString(s);
- break;
- }
+ default:
+ val = PyString_FromString(s);
+ break;
+ }
if (val == NULL)
{
@@ -1998,14 +2033,15 @@ exit:
/* gets asynchronous notify */
static char pg_getnotify__doc__[] =
- "getnotify() -- get database notify for this connection.";
+"getnotify() -- get database notify for this connection.";
static PyObject *
pg_getnotify(pgobject * self, PyObject * args)
{
- PGnotify *notify;
- PGresult *result;
- PyObject *notify_result, *temp;
+ PGnotify *notify;
+ PGresult *result;
+ PyObject *notify_result,
+ *temp;
if (!self->cnx)
{
@@ -2017,17 +2053,21 @@ pg_getnotify(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method getnotify() takes no parameters.");
+ "method getnotify() takes no parameters.");
return NULL;
}
/* gets notify and builds result */
- /* notifies only come back as result of a query, so I send an empty query */
+
+ /*
+ * notifies only come back as result of a query, so I send an empty
+ * query
+ */
Py_BEGIN_ALLOW_THREADS
- result = PQexec(self->cnx, " ");
+ result = PQexec(self->cnx, " ");
Py_END_ALLOW_THREADS
- if ((notify = PQnotifies(self->cnx)) != NULL)
+ if ((notify = PQnotifies(self->cnx)) != NULL)
{
if ((notify_result = PyTuple_New(2)) == NULL)
{
@@ -2067,7 +2107,7 @@ pg_getnotify(pgobject * self, PyObject * args)
/* source creation */
static char pg_source__doc__[] =
- "source() -- creates a new source object for this connection";
+"source() -- creates a new source object for this connection";
static PyObject *
pg_source(pgobject * self, PyObject * args)
@@ -2084,21 +2124,21 @@ pg_source(pgobject * self, PyObject * args)
}
/* allocate new pg query object */
- return (PyObject *)pgsource_new(self);
+ return (PyObject *) pgsource_new(self);
}
/* database query */
static char pg_query__doc__[] =
- "query(sql) -- creates a new query object for this connection,"
- " using sql (string) request.";
+"query(sql) -- creates a new query object for this connection,"
+" using sql (string) request.";
static PyObject *
pg_query(pgobject * self, PyObject * args)
{
- char *query;
- PGresult *result;
- pgqueryobject *npgobj;
- int status;
+ char *query;
+ PGresult *result;
+ pgqueryobject *npgobj;
+ int status;
if (!self->cnx)
{
@@ -2122,11 +2162,11 @@ pg_query(pgobject * self, PyObject * args)
/* gets result */
Py_BEGIN_ALLOW_THREADS
- result = PQexec(self->cnx, query);
+ result = PQexec(self->cnx, query);
Py_END_ALLOW_THREADS
/* checks result validity */
- if (!result)
+ if (!result)
{
PyErr_SetString(PyExc_ValueError, PQerrorMessage(self->cnx));
return NULL;
@@ -2135,7 +2175,7 @@ pg_query(pgobject * self, PyObject * args)
/* checks result status */
if ((status = PQresultStatus(result)) != PGRES_TUPLES_OK)
{
- Oid oid;
+ Oid oid;
PQclear(result);
@@ -2149,7 +2189,7 @@ pg_query(pgobject * self, PyObject * args)
case PGRES_NONFATAL_ERROR:
PyErr_SetString(PGError, PQerrorMessage(self->cnx));
break;
- case PGRES_COMMAND_OK: /* could be an INSERT */
+ case PGRES_COMMAND_OK: /* could be an INSERT */
if ((oid = PQoidValue(result)) == InvalidOid) /* nope */
{
Py_INCREF(Py_None);
@@ -2159,13 +2199,13 @@ pg_query(pgobject * self, PyObject * args)
/* otherwise, return the oid */
return PyInt_FromLong(oid);
- case PGRES_COPY_OUT: /* no data will be received */
+ case PGRES_COPY_OUT: /* no data will be received */
case PGRES_COPY_IN:
Py_INCREF(Py_None);
return Py_None;
default:
PyErr_SetString(PGError, "internal error: "
- "unknown result status.");
+ "unknown result status.");
break;
}
@@ -2182,13 +2222,13 @@ pg_query(pgobject * self, PyObject * args)
#ifdef DIRECT_ACCESS
static char pg_putline__doc__[] =
- "putline() -- sends a line directly to the backend";
+"putline() -- sends a line directly to the backend";
/* direct acces function : putline */
static PyObject *
pg_putline(pgobject * self, PyObject * args)
{
- char *line;
+ char *line;
if (!self->cnx)
{
@@ -2211,13 +2251,13 @@ pg_putline(pgobject * self, PyObject * args)
/* direct access function : getline */
static char pg_getline__doc__[] =
- "getline() -- gets a line directly from the backend.";
+"getline() -- gets a line directly from the backend.";
static PyObject *
pg_getline(pgobject * self, PyObject * args)
{
char line[MAX_BUFFER_SIZE];
- PyObject *str = NULL; /* GCC */
+ PyObject *str = NULL; /* GCC */
if (!self->cnx)
{
@@ -2229,7 +2269,7 @@ pg_getline(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method getline() takes no parameters.");
+ "method getline() takes no parameters.");
return NULL;
}
@@ -2254,7 +2294,7 @@ pg_getline(pgobject * self, PyObject * args)
/* direct access function : end copy */
static char pg_endcopy__doc__[] =
- "endcopy() -- synchronizes client and server";
+"endcopy() -- synchronizes client and server";
static PyObject *
pg_endcopy(pgobject * self, PyObject * args)
@@ -2269,7 +2309,7 @@ pg_endcopy(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method endcopy() takes no parameters.");
+ "method endcopy() takes no parameters.");
return NULL;
}
@@ -2278,13 +2318,14 @@ pg_endcopy(pgobject * self, PyObject * args)
Py_INCREF(Py_None);
return Py_None;
}
-#endif /* DIRECT_ACCESS */
+
+#endif /* DIRECT_ACCESS */
static PyObject *
-pgquery_print(pgqueryobject *self, FILE *fp, int flags)
+pgquery_print(pgqueryobject * self, FILE *fp, int flags)
{
- PQprintOpt op;
+ PQprintOpt op;
memset(&op, 0, sizeof(op));
op.align = 1;
@@ -2296,26 +2337,31 @@ pgquery_print(pgqueryobject *self, FILE *fp, int flags)
}
static PyObject *
-pgquery_repr(pgqueryobject *self)
+pgquery_repr(pgqueryobject * self)
{
return PyString_FromString("<pg query result>");
}
/* insert table */
static char pg_inserttable__doc__[] =
- "inserttable(string, list) -- insert list in table. The fields in the "
- "list must be in the same order as in the table.";
+"inserttable(string, list) -- insert list in table. The fields in the "
+"list must be in the same order as in the table.";
static PyObject *
pg_inserttable(pgobject * self, PyObject * args)
{
- PGresult *result;
- char *table, *buffer, *temp;
+ PGresult *result;
+ char *table,
+ *buffer,
+ *temp;
char temp_buffer[256];
- PyObject *list, *sublist, *item;
- PyObject *(*getitem) (PyObject *, int);
- PyObject *(*getsubitem) (PyObject *, int);
- int i, j;
+ PyObject *list,
+ *sublist,
+ *item;
+ PyObject *(*getitem) (PyObject *, int);
+ PyObject *(*getsubitem) (PyObject *, int);
+ int i,
+ j;
if (!self->cnx)
{
@@ -2327,8 +2373,8 @@ pg_inserttable(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "sO:filter", &table, &list))
{
PyErr_SetString(PyExc_TypeError,
- "tableinsert(table, content), with table (string) "
- "and content (list).");
+ "tableinsert(table, content), with table (string) "
+ "and content (list).");
return NULL;
}
@@ -2340,7 +2386,7 @@ pg_inserttable(pgobject * self, PyObject * args)
else
{
PyErr_SetString(PyExc_TypeError,
- "second arg must be some kind of array.");
+ "second arg must be some kind of array.");
return NULL;
}
@@ -2350,7 +2396,7 @@ pg_inserttable(pgobject * self, PyObject * args)
if (!PyTuple_Check(sublist) && !PyList_Check(sublist))
{
PyErr_SetString(PyExc_TypeError,
- "second arg must contain some kind of arrays.");
+ "second arg must contain some kind of arrays.");
return NULL;
}
}
@@ -2366,10 +2412,10 @@ pg_inserttable(pgobject * self, PyObject * args)
sprintf(buffer, "copy %s from stdin", table);
Py_BEGIN_ALLOW_THREADS
- result = PQexec(self->cnx, buffer);
+ result = PQexec(self->cnx, buffer);
Py_END_ALLOW_THREADS
- if (!result)
+ if (!result)
{
free(buffer);
PyErr_SetString(PyExc_ValueError, PQerrorMessage(self->cnx));
@@ -2396,7 +2442,7 @@ pg_inserttable(pgobject * self, PyObject * args)
temp = PyString_AS_STRING(item);
else if (PyInt_Check(item))
{
- long k;
+ long k;
k = PyInt_AsLong(item);
sprintf(temp_buffer, "%ld", k);
@@ -2404,7 +2450,7 @@ pg_inserttable(pgobject * self, PyObject * args)
}
else if (PyLong_Check(item))
{
- long k;
+ long k;
k = PyLong_AsLong(item);
sprintf(temp_buffer, "%ld", k);
@@ -2412,7 +2458,7 @@ pg_inserttable(pgobject * self, PyObject * args)
}
else if (PyFloat_Check(item))
{
- double k;
+ double k;
k = PyFloat_AS_DOUBLE(item);
sprintf(temp_buffer, "%g", k);
@@ -2422,8 +2468,8 @@ pg_inserttable(pgobject * self, PyObject * args)
{
free(buffer);
PyErr_SetString(PyExc_ValueError,
- "items must be strings, integers, "
- "longs or double (real).");
+ "items must be strings, integers, "
+ "longs or double (real).");
return NULL;
}
@@ -2453,13 +2499,13 @@ pg_inserttable(pgobject * self, PyObject * args)
/* creates large object */
static char pg_locreate__doc__[] =
- "locreate() -- creates a new large object in the database.";
+"locreate() -- creates a new large object in the database.";
static PyObject *
pg_locreate(pgobject * self, PyObject * args)
{
- int mode;
- Oid lo_oid;
+ int mode;
+ Oid lo_oid;
/* checks validity */
if (!check_cnx_obj(self))
@@ -2469,7 +2515,7 @@ pg_locreate(pgobject * self, PyObject * args)
if (!PyArg_ParseTuple(args, "i", &mode))
{
PyErr_SetString(PyExc_TypeError,
- "locreate(mode), with mode (integer).");
+ "locreate(mode), with mode (integer).");
return NULL;
}
@@ -2486,12 +2532,12 @@ pg_locreate(pgobject * self, PyObject * args)
/* init from already known oid */
static char pg_getlo__doc__[] =
- "getlo(long) -- create a large object instance for the specified oid.";
+"getlo(long) -- create a large object instance for the specified oid.";
static PyObject *
pg_getlo(pgobject * self, PyObject * args)
{
- int lo_oid;
+ int lo_oid;
/* checks validity */
if (!check_cnx_obj(self))
@@ -2516,13 +2562,13 @@ pg_getlo(pgobject * self, PyObject * args)
/* import unix file */
static char pg_loimport__doc__[] =
- "loimport(string) -- create a new large object from specified file.";
+"loimport(string) -- create a new large object from specified file.";
static PyObject *
pg_loimport(pgobject * self, PyObject * args)
{
- char *name;
- Oid lo_oid;
+ char *name;
+ Oid lo_oid;
/* checks validity */
if (!check_cnx_obj(self))
@@ -2549,25 +2595,25 @@ pg_loimport(pgobject * self, PyObject * args)
/* connection object methods */
static struct PyMethodDef pgobj_methods[] = {
- {"source", (PyCFunction) pg_source, 1, pg_source__doc__ },
- {"query", (PyCFunction) pg_query, 1, pg_query__doc__ },
- {"reset", (PyCFunction) pg_reset, 1, pg_reset__doc__ },
- {"close", (PyCFunction) pg_close, 1, pg_close__doc__ },
- {"fileno", (PyCFunction) pg_fileno,1, pg_fileno__doc__ },
- {"getnotify", (PyCFunction) pg_getnotify, 1, pg_getnotify__doc__ },
- {"inserttable", (PyCFunction) pg_inserttable, 1, pg_inserttable__doc__ },
+ {"source", (PyCFunction) pg_source, 1, pg_source__doc__},
+ {"query", (PyCFunction) pg_query, 1, pg_query__doc__},
+ {"reset", (PyCFunction) pg_reset, 1, pg_reset__doc__},
+ {"close", (PyCFunction) pg_close, 1, pg_close__doc__},
+ {"fileno", (PyCFunction) pg_fileno, 1, pg_fileno__doc__},
+ {"getnotify", (PyCFunction) pg_getnotify, 1, pg_getnotify__doc__},
+ {"inserttable", (PyCFunction) pg_inserttable, 1, pg_inserttable__doc__},
#ifdef DIRECT_ACCESS
- {"putline", (PyCFunction) pg_putline, 1, pg_putline__doc__ },
- {"getline", (PyCFunction) pg_getline, 1, pg_getline__doc__ },
- {"endcopy", (PyCFunction) pg_endcopy, 1, pg_endcopy__doc__ },
-#endif /* DIRECT_ACCESS */
+ {"putline", (PyCFunction) pg_putline, 1, pg_putline__doc__},
+ {"getline", (PyCFunction) pg_getline, 1, pg_getline__doc__},
+ {"endcopy", (PyCFunction) pg_endcopy, 1, pg_endcopy__doc__},
+#endif /* DIRECT_ACCESS */
#ifdef LARGE_OBJECTS
- {"locreate", (PyCFunction) pg_locreate, 1, pg_locreate__doc__ },
- {"getlo", (PyCFunction) pg_getlo, 1, pg_getlo__doc__ },
- {"loimport", (PyCFunction) pg_loimport, 1, pg_loimport__doc__ },
-#endif /* LARGE_OBJECTS */
+ {"locreate", (PyCFunction) pg_locreate, 1, pg_locreate__doc__},
+ {"getlo", (PyCFunction) pg_getlo, 1, pg_getlo__doc__},
+ {"loimport", (PyCFunction) pg_loimport, 1, pg_loimport__doc__},
+#endif /* LARGE_OBJECTS */
{NULL, NULL} /* sentinel */
};
@@ -2576,9 +2622,11 @@ static struct PyMethodDef pgobj_methods[] = {
static PyObject *
pg_getattr(pgobject * self, char *name)
{
- /* Although we could check individually, there are only a few
- * attributes that don't require a live connection and unless
- * someone has an urgent need, this will have to do
+
+ /*
+ * Although we could check individually, there are only a few
+ * attributes that don't require a live connection and unless someone
+ * has an urgent need, this will have to do
*/
if (!self->cnx)
{
@@ -2591,7 +2639,8 @@ pg_getattr(pgobject * self, char *name)
/* postmaster host */
if (!strcmp(name, "host"))
{
- char *r = PQhost(self->cnx);
+ char *r = PQhost(self->cnx);
+
return r ? PyString_FromString(r) : PyString_FromString("localhost");
}
@@ -2622,12 +2671,12 @@ pg_getattr(pgobject * self, char *name)
/* provided user name */
if (!strcmp(name, "user"))
return PyString_FromString("Deprecated facility");
- /* return PyString_FromString(fe_getauthname("<unknown user>")); */
+ /* return PyString_FromString(fe_getauthname("<unknown user>")); */
/* attributes list */
if (!strcmp(name, "__members__"))
{
- PyObject *list = PyList_New(8);
+ PyObject *list = PyList_New(8);
if (list)
{
@@ -2670,12 +2719,12 @@ staticforward PyTypeObject PgType = {
/* query object methods */
static struct PyMethodDef pgquery_methods[] = {
- {"getresult", (PyCFunction) pgquery_getresult, 1, pgquery_getresult__doc__},
- {"dictresult", (PyCFunction) pgquery_dictresult, 1, pgquery_dictresult__doc__},
- {"fieldname", (PyCFunction) pgquery_fieldname, 1, pgquery_fieldname__doc__},
- {"fieldnum", (PyCFunction) pgquery_fieldnum, 1, pgquery_fieldnum__doc__},
- {"listfields", (PyCFunction) pgquery_listfields, 1, pgquery_listfields__doc__},
- {"ntuples", (PyCFunction) pgquery_ntuples, 1, pgquery_ntuples__doc__},
+ {"getresult", (PyCFunction) pgquery_getresult, 1, pgquery_getresult__doc__},
+ {"dictresult", (PyCFunction) pgquery_dictresult, 1, pgquery_dictresult__doc__},
+ {"fieldname", (PyCFunction) pgquery_fieldname, 1, pgquery_fieldname__doc__},
+ {"fieldnum", (PyCFunction) pgquery_fieldnum, 1, pgquery_fieldnum__doc__},
+ {"listfields", (PyCFunction) pgquery_listfields, 1, pgquery_listfields__doc__},
+ {"ntuples", (PyCFunction) pgquery_ntuples, 1, pgquery_ntuples__doc__},
{NULL, NULL}
};
@@ -2690,21 +2739,21 @@ pgquery_getattr(pgqueryobject * self, char *name)
/* query type definition */
staticforward PyTypeObject PgQueryType = {
PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "pgqueryobject", /* tp_name */
- sizeof(pgqueryobject), /* tp_basicsize */
- 0, /* tp_itemsize */
+ 0, /* ob_size */
+ "pgqueryobject", /* tp_name */
+ sizeof(pgqueryobject), /* tp_basicsize */
+ 0, /* tp_itemsize */
/* methods */
- (destructor) pgquery_dealloc, /* tp_dealloc */
- (printfunc) pgquery_print, /* tp_print */
- (getattrfunc) pgquery_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- (reprfunc) pgquery_repr, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
+ (destructor) pgquery_dealloc, /* tp_dealloc */
+ (printfunc) pgquery_print, /* tp_print */
+ (getattrfunc) pgquery_getattr, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ (reprfunc) pgquery_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
};
@@ -2717,16 +2766,16 @@ staticforward PyTypeObject PgQueryType = {
/* gets default host */
static char getdefhost__doc__[] =
- "get_defhost() -- return default database host.";
+"get_defhost() -- return default database host.";
static PyObject *
-pggetdefhost(PyObject *self, PyObject *args)
+pggetdefhost(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defhost() takes no parameter.");
+ "method get_defhost() takes no parameter.");
return NULL;
}
@@ -2736,19 +2785,19 @@ pggetdefhost(PyObject *self, PyObject *args)
/* sets default host */
static char setdefhost__doc__[] =
- "set_defhost(string) -- set default database host. Return previous value.";
+"set_defhost(string) -- set default database host. Return previous value.";
static PyObject *
-pgsetdefhost(PyObject * self, PyObject *args)
+pgsetdefhost(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defhost(name), with name (string/None).");
+ "set_defhost(name), with name (string/None).");
return NULL;
}
@@ -2768,16 +2817,16 @@ pgsetdefhost(PyObject * self, PyObject *args)
/* gets default base */
static char getdefbase__doc__[] =
- "get_defbase() -- return default database name.";
+"get_defbase() -- return default database name.";
static PyObject *
-pggetdefbase(PyObject * self, PyObject *args)
+pggetdefbase(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defbase() takes no parameter.");
+ "method get_defbase() takes no parameter.");
return NULL;
}
@@ -2787,19 +2836,19 @@ pggetdefbase(PyObject * self, PyObject *args)
/* sets default base */
static char setdefbase__doc__[] =
- "set_defbase(string) -- set default database name. Return previous value";
+"set_defbase(string) -- set default database name. Return previous value";
static PyObject *
-pgsetdefbase(PyObject * self, PyObject *args)
+pgsetdefbase(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defbase(name), with name (string/None).");
+ "set_defbase(name), with name (string/None).");
return NULL;
}
@@ -2819,16 +2868,16 @@ pgsetdefbase(PyObject * self, PyObject *args)
/* gets default options */
static char getdefopt__doc__[] =
- "get_defopt() -- return default database options.";
+"get_defopt() -- return default database options.";
static PyObject *
-pggetdefopt(PyObject * self, PyObject *args)
+pggetdefopt(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defopt() takes no parameter.");
+ "method get_defopt() takes no parameter.");
return NULL;
}
@@ -2838,19 +2887,19 @@ pggetdefopt(PyObject * self, PyObject *args)
/* sets default opt */
static char setdefopt__doc__[] =
- "set_defopt(string) -- set default database options. Return previous value.";
+"set_defopt(string) -- set default database options. Return previous value.";
static PyObject *
-pgsetdefopt(PyObject * self, PyObject *args)
+pgsetdefopt(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defopt(name), with name (string/None).");
+ "set_defopt(name), with name (string/None).");
return NULL;
}
@@ -2870,16 +2919,16 @@ pgsetdefopt(PyObject * self, PyObject *args)
/* gets default tty */
static char getdeftty__doc__[] =
- "get_deftty() -- return default database debug terminal.";
+"get_deftty() -- return default database debug terminal.";
static PyObject *
-pggetdeftty(PyObject * self, PyObject *args)
+pggetdeftty(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_deftty() takes no parameter.");
+ "method get_deftty() takes no parameter.");
return NULL;
}
@@ -2889,20 +2938,20 @@ pggetdeftty(PyObject * self, PyObject *args)
/* sets default tty */
static char setdeftty__doc__[] =
- "set_deftty(string) -- set default database debug terminal. "
- "Return previous value.";
+"set_deftty(string) -- set default database debug terminal. "
+"Return previous value.";
static PyObject *
-pgsetdeftty(PyObject * self, PyObject *args)
+pgsetdeftty(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_deftty(name), with name (string/None).");
+ "set_deftty(name), with name (string/None).");
return NULL;
}
@@ -2922,16 +2971,16 @@ pgsetdeftty(PyObject * self, PyObject *args)
/* gets default username */
static char getdefuser__doc__[] =
- "get_defuser() -- return default database username.";
+"get_defuser() -- return default database username.";
static PyObject *
-pggetdefuser(PyObject * self, PyObject *args)
+pggetdefuser(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defuser() takes no parameter.");
+ "method get_defuser() takes no parameter.");
return NULL;
}
@@ -2942,19 +2991,19 @@ pggetdefuser(PyObject * self, PyObject *args)
/* sets default username */
static char setdefuser__doc__[] =
- "set_defuser() -- set default database username. Return previous value.";
+"set_defuser() -- set default database username. Return previous value.";
static PyObject *
-pgsetdefuser(PyObject * self, PyObject *args)
+pgsetdefuser(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
{
PyErr_SetString(PyExc_TypeError,
- "set_defuser(name), with name (string/None).");
+ "set_defuser(name), with name (string/None).");
return NULL;
}
@@ -2974,13 +3023,13 @@ pgsetdefuser(PyObject * self, PyObject *args)
/* sets default password */
static char setdefpasswd__doc__[] =
- "set_defpasswd() -- set default database password.";
+"set_defpasswd() -- set default database password.";
static PyObject *
-pgsetdefpasswd(PyObject * self, PyObject *args)
+pgsetdefpasswd(PyObject * self, PyObject * args)
{
- char *temp = NULL;
- PyObject *old;
+ char *temp = NULL;
+ PyObject *old;
/* gets arguments */
if (!PyArg_ParseTuple(args, "z", &temp))
@@ -3007,16 +3056,16 @@ pgsetdefpasswd(PyObject * self, PyObject *args)
/* gets default port */
static char getdefport__doc__[] =
- "get_defport() -- return default database port.";
+"get_defport() -- return default database port.";
static PyObject *
-pggetdefport(PyObject * self, PyObject *args)
+pggetdefport(PyObject * self, PyObject * args)
{
/* checks args */
if (!PyArg_ParseTuple(args, ""))
{
PyErr_SetString(PyExc_SyntaxError,
- "method get_defport() takes no parameter.");
+ "method get_defport() takes no parameter.");
return NULL;
}
@@ -3026,19 +3075,19 @@ pggetdefport(PyObject * self, PyObject *args)
/* sets default port */
static char setdefport__doc__[] =
- "set_defport(integer) -- set default database port. Return previous value.";
+"set_defport(integer) -- set default database port. Return previous value.";
static PyObject *
-pgsetdefport(PyObject * self, PyObject *args)
+pgsetdefport(PyObject * self, PyObject * args)
{
long int port = -2;
- PyObject *old;
+ PyObject *old;
/* gets arguments */
if ((!PyArg_ParseTuple(args, "l", &port)) || (port < -1))
{
PyErr_SetString(PyExc_TypeError, "set_defport(port), with port "
- "(positive integer/-1).");
+ "(positive integer/-1).");
return NULL;
}
@@ -3056,28 +3105,28 @@ pgsetdefport(PyObject * self, PyObject *args)
return old;
}
-#endif /* DEFAULT_VARS */
+#endif /* DEFAULT_VARS */
/* List of functions defined in the module */
static struct PyMethodDef pg_methods[] = {
- {"connect", (PyCFunction) pgconnect, 3, connect__doc__ },
+ {"connect", (PyCFunction) pgconnect, 3, connect__doc__},
#ifdef DEFAULT_VARS
- {"get_defhost", pggetdefhost, 1, getdefhost__doc__ },
- {"set_defhost", pgsetdefhost, 1, setdefhost__doc__ },
- {"get_defbase", pggetdefbase, 1, getdefbase__doc__ },
- {"set_defbase", pgsetdefbase, 1, setdefbase__doc__ },
- {"get_defopt", pggetdefopt, 1, getdefopt__doc__ },
- {"set_defopt", pgsetdefopt, 1, setdefopt__doc__ },
- {"get_deftty", pggetdeftty, 1, getdeftty__doc__ },
- {"set_deftty", pgsetdeftty, 1, setdeftty__doc__ },
- {"get_defport", pggetdefport, 1, getdefport__doc__ },
- {"set_defport", pgsetdefport, 1, setdefport__doc__ },
- {"get_defuser", pggetdefuser, 1, getdefuser__doc__ },
- {"set_defuser", pgsetdefuser, 1, setdefuser__doc__ },
- {"set_defpasswd", pgsetdefpasswd, 1, setdefpasswd__doc__ },
-#endif /* DEFAULT_VARS */
+ {"get_defhost", pggetdefhost, 1, getdefhost__doc__},
+ {"set_defhost", pgsetdefhost, 1, setdefhost__doc__},
+ {"get_defbase", pggetdefbase, 1, getdefbase__doc__},
+ {"set_defbase", pgsetdefbase, 1, setdefbase__doc__},
+ {"get_defopt", pggetdefopt, 1, getdefopt__doc__},
+ {"set_defopt", pgsetdefopt, 1, setdefopt__doc__},
+ {"get_deftty", pggetdeftty, 1, getdeftty__doc__},
+ {"set_deftty", pgsetdeftty, 1, setdeftty__doc__},
+ {"get_defport", pggetdefport, 1, getdefport__doc__},
+ {"set_defport", pgsetdefport, 1, setdefport__doc__},
+ {"get_defuser", pggetdefuser, 1, getdefuser__doc__},
+ {"set_defuser", pgsetdefuser, 1, setdefuser__doc__},
+ {"set_defpasswd", pgsetdefpasswd, 1, setdefpasswd__doc__},
+#endif /* DEFAULT_VARS */
{NULL, NULL} /* sentinel */
};
@@ -3087,7 +3136,9 @@ static char pg__doc__[] = "Python interface to PostgreSQL DB";
DL_EXPORT(void)
init_pg(void)
{
- PyObject *mod, *dict, *v;
+ PyObject *mod,
+ *dict,
+ *v;
/* Initialize here because some WIN platforms get confused otherwise */
PglargeType.ob_type = PgType.ob_type = PgQueryType.ob_type = &PyType_Type;
@@ -3121,18 +3172,25 @@ init_pg(void)
PyDict_SetItemString(dict, "SEEK_SET", PyInt_FromLong(SEEK_SET));
PyDict_SetItemString(dict, "SEEK_CUR", PyInt_FromLong(SEEK_CUR));
PyDict_SetItemString(dict, "SEEK_END", PyInt_FromLong(SEEK_END));
-#endif /* LARGE_OBJECTS */
+#endif /* LARGE_OBJECTS */
#ifdef DEFAULT_VARS
/* prepares default values */
- Py_INCREF(Py_None); pg_default_host = Py_None;
- Py_INCREF(Py_None); pg_default_base = Py_None;
- Py_INCREF(Py_None); pg_default_opt = Py_None;
- Py_INCREF(Py_None); pg_default_port = Py_None;
- Py_INCREF(Py_None); pg_default_tty = Py_None;
- Py_INCREF(Py_None); pg_default_user = Py_None;
- Py_INCREF(Py_None); pg_default_passwd = Py_None;
-#endif /* DEFAULT_VARS */
+ Py_INCREF(Py_None);
+ pg_default_host = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_base = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_opt = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_port = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_tty = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_user = Py_None;
+ Py_INCREF(Py_None);
+ pg_default_passwd = Py_None;
+#endif /* DEFAULT_VARS */
/* Check for errors */
if (PyErr_Occurred())