Changeset 528


Ignore:
Timestamp:
Nov 10, 2015, 9:38:22 AM (4 years ago)
Author:
darcy
Message:

As part of moving to Python 3 I am also going to re-organize the code.
Here I am renaming variables to show whichobject types they reference. See
the comment near the top for further explanation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/pgmodule.c

    r527 r528  
    108108#endif
    109109
    110 /* --------------------------------------------------------------------- */
    111 
    112110/* MODULE GLOBAL VARIABLES */
    113111
     
    122120#endif  /* DEFAULT_VARS */
    123121
    124 int *get_type_array(PGresult *result, int nfields);
    125 
    126122static PyObject *decimal = NULL, /* decimal type */
    127123                                *namedresult = NULL; /* function for getting named results */
    128124static char *decimal_point = "."; /* decimal point used in money values */
    129125
    130 
    131 /* --------------------------------------------------------------------- */
    132 /* OBJECTS DECLARATION */
     126/*
     127OBJECTS
     128=======
     129
     130  Each object has a number of elements.  The naming scheme will be based on
     131  the object type.  Here are the elements using example object type "foo".
     132   - fooObject: A structure to hold local object information.
     133   - fooXxx: Object methods such as Delete and Getattr.
     134   - fooMethods: Methods declaration.
     135   - fooType: Type definition for object.
     136
     137  This is followed by the object methods.
     138
     139  The objects that we need to create:
     140   - pg: The module itself.
     141   - conn: Connection object returned from pg.connect().
     142   - notice: Notice object returned from pg.notice().
     143   - large: Large object returned by pg.conn.locreate() and Pg.Conn.loimport().
     144   - query: Query object returned by pg.conn.Conn.query().
     145   - source: Source object returned by pg.conn.source().
     146*/
     147
     148/* forward declarations for types */
     149static PyTypeObject noticeType;
     150static PyTypeObject queryType;
     151static PyTypeObject sourceType;
     152static PyTypeObject largeType;
     153static PyTypeObject connType;
    133154
    134155/* pg connection object */
     
    140161        PGconn          *cnx;                           /* PostGres connection handle */
    141162        PyObject        *notice_receiver;       /* current notice receiver */
    142 }       pgobject;
    143 
    144 static PyTypeObject PgType;
    145 
    146 #define is_pgobject(v) (PyType(v) == &PgType)
    147 
    148 static PyObject *
    149 pgobject_New(void)
    150 {
    151         pgobject        *pgobj;
    152 
    153         if (!(pgobj = PyObject_NEW(pgobject, &PgType)))
     163}       connObject;
     164#define is_connObject(v) (PyType(v) == &connType)
     165
     166static PyObject *
     167connNew(void)
     168{
     169        connObject      *pgobj;
     170
     171        if (!(pgobj = PyObject_NEW(connObject, &connType)))
    154172                return NULL;
    155173
     
    166184{
    167185        PyObject_HEAD
    168         pgobject        *pgcnx;         /* parent connection object */
     186        connObject      *pgcnx;         /* parent connection object */
    169187        PGresult        const *res;     /* an error or warning */
    170188}       pgnoticeobject;
    171 
    172 static PyTypeObject PgNoticeType;
    173 
    174 #define is_pgnoticeobject(v) (PyType(v) == &PgNoticeType)
     189#define is_pgnoticeobject(v) (PyType(v) == &noticeType)
    175190
    176191/* pg query object */
     
    184199        long            num_rows;               /* number of (affected) rows */
    185200}       pgqueryobject;
    186 
    187 static PyTypeObject PgQueryType;
    188 
    189 #define is_pgqueryobject(v) (PyType(v) == &PgQueryType)
     201#define is_pgqueryobject(v) (PyType(v) == &queryType)
    190202
    191203/* pg source object */
     
    195207        PyObject_HEAD
    196208        int                     valid;                  /* validity flag */
    197         pgobject        *pgcnx;                 /* parent connection object */
     209        connObject      *pgcnx;                 /* parent connection object */
    198210        PGresult        *result;                /* result content */
    199211        int                     result_type;    /* result type (DDL/DML/DQL) */
     
    203215        int                     num_fields;             /* number of fields in each row */
    204216}       pgsourceobject;
    205 
    206 static PyTypeObject PgSourceType;
    207 
    208 #define is_pgsourceobject(v) (PyType(v) == &PgSourceType)
     217#define is_pgsourceobject(v) (PyType(v) == &sourceType)
    209218
    210219#ifdef LARGE_OBJECTS
     
    214223{
    215224        PyObject_HEAD
    216         pgobject        *pgcnx;                 /* parent connection object */
     225        connObject      *pgcnx;                 /* parent connection object */
    217226        Oid                     lo_oid;                 /* large object oid */
    218227        int                     lo_fd;                  /* large object fd */
    219228}       pglargeobject;
    220 
    221 static PyTypeObject PglargeType;
    222 
    223 #define is_pglargeobject(v) (PyType(v) == &PglargeType)
     229#define is_pglargeobject(v) (PyType(v) == &largeType)
    224230#endif /* LARGE_OBJECTS */
    225231
     
    268274/* checks connection validity */
    269275static int
    270 check_cnx_obj(pgobject *self)
     276check_cnx_obj(connObject *self)
    271277{
    272278        if (!self->valid)
     
    562568}
    563569
    564 /* prototypes for constructors */
    565 static pgsourceobject *pgsource_new(pgobject *pgcnx);
    566 
    567570/* --------------------------------------------------------------------- */
    568571/* PG SOURCE OBJECT IMPLEMENTATION */
     
    570573/* constructor (internal use only) */
    571574static pgsourceobject *
    572 pgsource_new(pgobject *pgcnx)
     575sourceNew(connObject *pgcnx)
    573576{
    574577        pgsourceobject *npgobj;
    575578
    576579        /* allocates new query object */
    577         if (!(npgobj = PyObject_NEW(pgsourceobject, &PgSourceType)))
     580        if (!(npgobj = PyObject_NEW(pgsourceobject, &sourceType)))
    578581                return NULL;
    579582
     
    590593/* destructor */
    591594static void
    592 pgsource_dealloc(pgsourceobject *self)
     595sourceDelete(pgsourceobject *self)
    593596{
    594597        if (self->result)
     
    600603
    601604/* closes object */
    602 static char pgsource_close__doc__[] =
     605static char sourceClose__doc__[] =
    603606"close() -- close query object without deleting it. "
    604607"All instances of the query object can no longer be used after this call.";
     
    630633
    631634/* database query */
    632 static char pgsource_execute__doc__[] =
     635static char sourceExecute__doc__[] =
    633636"execute(sql) -- execute a SQL statement (string).\n "
    634637"On success, this call returns the number of affected rows, "
     
    729732
    730733/* gets oid status for last query (valid for INSERTs, 0 for other) */
    731 static char pgsource_oidstatus__doc__[] =
     734static char sourceOidstatus__doc__[] =
    732735"oidstatus() -- return oid of last inserted row (if available).";
    733736
     
    760763
    761764/* fetches rows from last result */
    762 static char pgsource_fetch__doc__[] =
     765static char sourceFetch__doc__[] =
    763766"fetch(num) -- return the next num rows from the last result in a list. "
    764767"If num parameter is omitted arraysize attribute value is used. "
     
    869872
    870873/* move to first result row */
    871 static char pgsource_movefirst__doc__[] =
     874static char sourceMovefirst__doc__[] =
    872875"movefirst() -- move to first result row.";
    873876
     
    879882
    880883/* move to last result row */
    881 static char pgsource_movelast__doc__[] =
     884static char sourceMovelast__doc__[] =
    882885"movelast() -- move to last valid result row.";
    883886
     
    889892
    890893/* move to next result row */
    891 static char pgsource_movenext__doc__[] =
     894static char sourceMovenext__doc__[] =
    892895"movenext() -- move to next result row.";
    893896
     
    899902
    900903/* move to previous result row */
    901 static char pgsource_moveprev__doc__[] =
     904static char sourceMoveprev__doc__[] =
    902905"moveprev() -- move to previous result row.";
    903906
     
    961964
    962965/* lists fields info */
    963 static char pgsource_listinfo__doc__[] =
     966static char sourceListinfo__doc__[] =
    964967"listinfo() -- return information for all fields "
    965968"(position, name, type oid).";
     
    10041007
    10051008/* list fields information for last result */
    1006 static char pgsource_fieldinfo__doc__[] =
     1009static char sourceFieldinfo__doc__[] =
    10071010"fieldinfo(string|integer) -- return specified field information "
    10081011"(position, name, type oid).";
     
    10321035
    10331036/* retrieve field value */
    1034 static char pgsource_field__doc__[] =
     1037static char sourceField__doc__[] =
    10351038"field(string|integer) -- return specified field value.";
    10361039
     
    10611064static PyMethodDef pgsource_methods[] = {
    10621065        {"close", (PyCFunction) pgsource_close, METH_VARARGS,
    1063                         pgsource_close__doc__},
     1066                        sourceClose__doc__},
    10641067        {"execute", (PyCFunction) pgsource_execute, METH_VARARGS,
    1065                         pgsource_execute__doc__},
     1068                        sourceExecute__doc__},
    10661069        {"oidstatus", (PyCFunction) pgsource_oidstatus, METH_VARARGS,
    1067                         pgsource_oidstatus__doc__},
     1070                        sourceOidstatus__doc__},
    10681071        {"fetch", (PyCFunction) pgsource_fetch, METH_VARARGS,
    1069                         pgsource_fetch__doc__},
     1072                        sourceFetch__doc__},
    10701073        {"movefirst", (PyCFunction) pgsource_movefirst, METH_VARARGS,
    1071                         pgsource_movefirst__doc__},
     1074                        sourceMovefirst__doc__},
    10721075        {"movelast", (PyCFunction) pgsource_movelast, METH_VARARGS,
    1073                         pgsource_movelast__doc__},
     1076                        sourceMovelast__doc__},
    10741077        {"movenext", (PyCFunction) pgsource_movenext, METH_VARARGS,
    1075                         pgsource_movenext__doc__},
     1078                        sourceMovenext__doc__},
    10761079        {"moveprev", (PyCFunction) pgsource_moveprev, METH_VARARGS,
    1077                         pgsource_moveprev__doc__},
     1080                        sourceMoveprev__doc__},
    10781081        {"field", (PyCFunction) pgsource_field, METH_VARARGS,
    1079                         pgsource_field__doc__},
     1082                        sourceField__doc__},
    10801083        {"fieldinfo", (PyCFunction) pgsource_fieldinfo, METH_VARARGS,
    1081                         pgsource_fieldinfo__doc__},
     1084                        sourceFieldinfo__doc__},
    10821085        {"listinfo", (PyCFunction) pgsource_listinfo, METH_VARARGS,
    1083                         pgsource_listinfo__doc__},
     1086                        sourceListinfo__doc__},
    10841087        {NULL, NULL}
    10851088};
     
    10871090/* gets query object attributes */
    10881091static PyObject *
    1089 pgsource_getattr(pgsourceobject *self, char *name)
     1092sourceGetattr(pgsourceobject *self, char *name)
    10901093{
    10911094        /* pg connection object */
     
    11451148/* sets query object attributes */
    11461149static int
    1147 pgsource_setattr(pgsourceobject *self, char *name, PyObject *v)
     1150sourceSetattr(pgsourceobject *self, char *name, PyObject *v)
    11481151{
    11491152        /* arraysize */
     
    11661169
    11671170static PyObject *
    1168 pgsource_repr(pgsourceobject *self)
     1171sourceRepr(pgsourceobject *self)
    11691172{
    11701173        return PyBytes_FromString("<pg source object>");
     
    11741177
    11751178static PyObject *
    1176 pgsource_str(pgsourceobject *self)
     1179sourceStr(pgsourceobject *self)
    11771180{
    11781181        switch (self->result_type)
     
    11901193
    11911194/* query type definition */
    1192 static PyTypeObject PgSourceType = {
     1195static PyTypeObject sourceType = {
    11931196        PyObject_HEAD_INIT(NULL)
    11941197        0,                                                              /* ob_size */
     
    11971200        0,                                                              /* tp_itemsize */
    11981201        /* methods */
    1199         (destructor) pgsource_dealloc,  /* tp_dealloc */
     1202        (destructor) sourceDelete,              /* tp_dealloc */
    12001203        0,                                                              /* tp_print */
    1201         (getattrfunc) pgsource_getattr, /* tp_getattr */
    1202         (setattrfunc) pgsource_setattr, /* tp_setattr */
     1204        (getattrfunc) sourceGetattr,    /* tp_getattr */
     1205        (setattrfunc) sourceSetattr,    /* tp_setattr */
    12031206        0,                                                              /* tp_compare */
    1204         (reprfunc) pgsource_repr,               /* tp_repr */
     1207        (reprfunc) sourceRepr,                  /* tp_repr */
    12051208        0,                                                              /* tp_as_number */
    12061209        0,                                                              /* tp_as_sequence */
     
    12081211        0,                                                              /* tp_hash */
    12091212        0,                                                              /* tp_call */
    1210         (reprfunc) pgsource_str,                /* tp_str */
     1213        (reprfunc) sourceStr,                   /* tp_str */
    12111214};
    12121215
     
    12181221/* constructor (internal use only) */
    12191222static pglargeobject *
    1220 pglarge_new(pgobject *pgcnx, Oid oid)
     1223pglarge_new(connObject *pgcnx, Oid oid)
    12211224{
    12221225        pglargeobject *npglo;
    12231226
    1224         if (!(npglo = PyObject_NEW(pglargeobject, &PglargeType)))
     1227        if (!(npglo = PyObject_NEW(pglargeobject, &largeType)))
    12251228                return NULL;
    12261229
     
    12451248
    12461249/* opens large object */
    1247 static char pglarge_open__doc__[] =
     1250static char largeOpen__doc__[] =
    12481251"open(mode) -- open access to large object with specified mode "
    12491252"(INV_READ, INV_WRITE constants defined by module).";
     
    12801283
    12811284/* close large object */
    1282 static char pglarge_close__doc__[] =
     1285static char largeClose__doc__[] =
    12831286"close() -- close access to large object data.";
    12841287
     
    13121315
    13131316/* reads from large object */
    1314 static char pglarge_read__doc__[] =
     1317static char largeRead__doc__[] =
    13151318"read(integer) -- read from large object to sized string. "
    13161319"Object must be opened in read mode before calling this method.";
     
    13551358
    13561359/* write to large object */
    1357 static char pglarge_write__doc__[] =
     1360static char largeWrite__doc__[] =
    13581361"write(string) -- write sized string to large object. "
    13591362"Object must be opened in read mode before calling this method.";
     
    13921395
    13931396/* go to position in large object */
    1394 static char pglarge_seek__doc__[] =
     1397static char largeSeek__doc__[] =
    13951398"seek(off, whence) -- move to specified position. Object must be opened "
    13961399"before calling this method. whence can be SEEK_SET, SEEK_CUR or SEEK_END, "
     
    14291432
    14301433/* gets large object size */
    1431 static char pglarge_size__doc__[] =
     1434static char largeSize__doc__[] =
    14321435"size() -- return large object size. "
    14331436"Object must be opened before calling this method.";
     
    14781481
    14791482/* gets large object cursor position */
    1480 static char pglarge_tell__doc__[] =
     1483static char largeTell__doc__[] =
    14811484"tell() -- give current position in large object. "
    14821485"Object must be opened before calling this method.";
     
    15111514
    15121515/* exports large object as unix file */
    1513 static char pglarge_export__doc__[] =
     1516static char largeExport__doc__[] =
    15141517"export(string) -- export large object data to specified file. "
    15151518"Object must be closed when calling this method.";
     
    15441547
    15451548/* deletes a large object */
    1546 static char pglarge_unlink__doc__[] =
     1549static char largeUnlink__doc__[] =
    15471550"unlink() -- destroy large object. "
    15481551"Object must be closed when calling this method.";
     
    15781581/* large object methods */
    15791582static struct PyMethodDef pglarge_methods[] = {
    1580         {"open", (PyCFunction) pglarge_open, METH_VARARGS, pglarge_open__doc__},
    1581         {"close", (PyCFunction) pglarge_close, METH_VARARGS, pglarge_close__doc__},
    1582         {"read", (PyCFunction) pglarge_read, METH_VARARGS, pglarge_read__doc__},
    1583         {"write", (PyCFunction) pglarge_write, METH_VARARGS, pglarge_write__doc__},
    1584         {"seek", (PyCFunction) pglarge_lseek, METH_VARARGS, pglarge_seek__doc__},
    1585         {"size", (PyCFunction) pglarge_size, METH_VARARGS, pglarge_size__doc__},
    1586         {"tell", (PyCFunction) pglarge_tell, METH_VARARGS, pglarge_tell__doc__},
    1587         {"export",(PyCFunction) pglarge_export,METH_VARARGS,pglarge_export__doc__},
    1588         {"unlink",(PyCFunction) pglarge_unlink,METH_VARARGS,pglarge_unlink__doc__},
     1583        {"open", (PyCFunction) pglarge_open, METH_VARARGS, largeOpen__doc__},
     1584        {"close", (PyCFunction) pglarge_close, METH_VARARGS, largeClose__doc__},
     1585        {"read", (PyCFunction) pglarge_read, METH_VARARGS, largeRead__doc__},
     1586        {"write", (PyCFunction) pglarge_write, METH_VARARGS, largeWrite__doc__},
     1587        {"seek", (PyCFunction) pglarge_lseek, METH_VARARGS, largeSeek__doc__},
     1588        {"size", (PyCFunction) pglarge_size, METH_VARARGS, largeSize__doc__},
     1589        {"tell", (PyCFunction) pglarge_tell, METH_VARARGS, largeTell__doc__},
     1590        {"export", (PyCFunction) pglarge_export, METH_VARARGS, largeExport__doc__},
     1591        {"unlink", (PyCFunction) pglarge_unlink, METH_VARARGS, largeUnlink__doc__},
    15891592        {NULL, NULL}
    15901593};
     
    16641667
    16651668/* object type definition */
    1666 static PyTypeObject PglargeType = {
     1669static PyTypeObject largeType = {
    16671670        PyObject_HEAD_INIT(NULL)
    16681671        0,                                                      /* ob_size */
     
    16901693
    16911694/* connects to a database */
    1692 static char connect__doc__[] =
     1695static char pgConnect__doc__[] =
    16931696"connect(dbname, host, port, opt, tty) -- connect to a PostgreSQL database "
    16941697"using specified parameters (optionals, keywords aware).";
    16951698
    16961699static PyObject *
    1697 pgconnect(pgobject *self, PyObject *args, PyObject *dict)
     1700pgconnect(connObject *self, PyObject *args, PyObject *dict)
    16981701{
    16991702        static const char *kwlist[] = {"dbname", "host", "port", "opt",
     
    17081711        int                     pgport;
    17091712        char            port_buffer[20];
    1710         pgobject   *npgobj;
     1713        connObject   *npgobj;
    17111714
    17121715        pghost = pgopt = pgtty = pgdbname = pguser = pgpasswd = NULL;
     
    17471750#endif /* DEFAULT_VARS */
    17481751
    1749         if (!(npgobj = (pgobject *) pgobject_New()))
     1752        if (!(npgobj = (connObject *) connNew()))
    17501753                return NULL;
    17511754
     
    17791782{
    17801783        PyGILState_STATE gstate = PyGILState_Ensure();
    1781         pgobject *self = (pgobject*) arg;
     1784        connObject *self = (connObject*) arg;
    17821785        PyObject *proc = self->notice_receiver;
    17831786        if (proc && PyCallable_Check(proc))
    17841787        {
    1785                 pgnoticeobject *notice = PyObject_NEW(pgnoticeobject, &PgNoticeType);
     1788                pgnoticeobject *notice = PyObject_NEW(pgnoticeobject, &noticeType);
    17861789                PyObject *args, *ret;
    17871790                if (notice)
     
    18031806}
    18041807
    1805 /* pgobject methods */
     1808/* connObject methods */
    18061809
    18071810/* destructor */
    18081811static void
    1809 pg_dealloc(pgobject *self)
     1812connDelete(connObject *self)
    18101813{
    18111814        if (self->cnx)
     
    18231826
    18241827/* close without deleting */
    1825 static char pg_close__doc__[] =
     1828static char connClose__doc__[] =
    18261829"close() -- close connection. All instances of the connection object and "
    18271830"derived objects (queries and large objects) can no longer be used after "
     
    18291832
    18301833static PyObject *
    1831 pg_close(pgobject *self, PyObject *args)
     1834pg_close(connObject *self, PyObject *args)
    18321835{
    18331836        /* gets args */
     
    18641867
    18651868/* resets connection */
    1866 static char pg_reset__doc__[] =
     1869static char connReset__doc__[] =
    18671870"reset() -- reset connection with current parameters. All derived queries "
    18681871"and large objects derived from this connection will not be usable after "
     
    18701873
    18711874static PyObject *
    1872 pg_reset(pgobject *self, PyObject *args)
     1875pg_reset(connObject *self, PyObject *args)
    18731876{
    18741877        if (!self->cnx)
     
    18931896
    18941897/* cancels current command */
    1895 static char pg_cancel__doc__[] =
     1898static char connCancel__doc__[] =
    18961899"cancel() -- abandon processing of the current command.";
    18971900
    18981901static PyObject *
    1899 pg_cancel(pgobject *self, PyObject *args)
     1902pg_cancel(connObject *self, PyObject *args)
    19001903{
    19011904        if (!self->cnx)
     
    19181921
    19191922/* get connection socket */
    1920 static char pg_fileno__doc__[] =
     1923static char connFileno__doc__[] =
    19211924"fileno() -- return database connection socket file handle.";
    19221925
    19231926static PyObject *
    1924 pg_fileno(pgobject *self, PyObject *args)
     1927pg_fileno(connObject *self, PyObject *args)
    19251928{
    19261929        if (!self->cnx)
     
    19461949
    19471950/* set notice receiver callback function */
    1948 static char pg_set_notice_receiver__doc__[] =
     1951static char connSset_notice_receiver__doc__[] =
    19491952"set_notice_receiver() -- set the current notice receiver.";
    19501953
    19511954static PyObject *
    1952 pg_set_notice_receiver(pgobject * self, PyObject * args)
     1955pg_set_notice_receiver(connObject * self, PyObject * args)
    19531956{
    19541957        PyObject *ret = NULL;
     
    19711974
    19721975/* get notice receiver callback function */
    1973 static char pg_get_notice_receiver__doc__[] =
     1976static char connGet_notice_receiver__doc__[] =
    19741977"get_notice_receiver() -- get the current notice receiver.";
    19751978
    19761979static PyObject *
    1977 pg_get_notice_receiver(pgobject * self, PyObject * args)
     1980pg_get_notice_receiver(connObject * self, PyObject * args)
    19781981{
    19791982        PyObject *ret = NULL;
     
    19951998
    19961999/* get number of rows */
    1997 static char pgquery_ntuples__doc__[] =
     2000static char queryNtuples__doc__[] =
    19982001"ntuples() -- returns number of tuples returned by query.";
    19992002
     
    20132016
    20142017/* list fields names from query result */
    2015 static char pgquery_listfields__doc__[] =
     2018static char queryListfields__doc__[] =
    20162019"listfields() -- Lists field names from result.";
    20172020
     
    20482051
    20492052/* get field name from last result */
    2050 static char pgquery_fieldname__doc__[] =
     2053static char queryFieldname__doc__[] =
    20512054"fieldname() -- returns name of field from result from its position.";
    20522055
     
    20782081
    20792082/* gets fields number from name in last result */
    2080 static char pgquery_fieldnum__doc__[] =
     2083static char queryFieldnum__doc__[] =
    20812084"fieldnum() -- returns position in query for field from its name.";
    20822085
     
    21052108
    21062109/* retrieves last result */
    2107 static char pgquery_getresult__doc__[] =
     2110static char queryGetresult__doc__[] =
    21082111"getresult() -- Gets the result of a query.  The result is returned "
    21092112"as a list of rows, each one a tuple of fields in the order returned "
     
    22322235
    22332236/* retrieves last result as a list of dictionaries*/
    2234 static char pgquery_dictresult__doc__[] =
     2237static char queryDictresult__doc__[] =
    22352238"dictresult() -- Gets the result of a query.  The result is returned "
    22362239"as a list of rows, each one a dictionary with the field names used "
     
    23602363
    23612364/* retrieves last result as named tuples */
    2362 static char pgquery_namedresult__doc__[] =
     2365static char queryNamedresult__doc__[] =
    23632366"namedresult() -- Gets the result of a query.  The result is returned "
    23642367"as a list of rows, each one a tuple of fields in the order returned "
     
    23972400
    23982401/* gets asynchronous notify */
    2399 static char pg_getnotify__doc__[] =
     2402static char connGetnotify__doc__[] =
    24002403"getnotify() -- get database notify for this connection.";
    24012404
    24022405static PyObject *
    2403 pg_getnotify(pgobject *self, PyObject *args)
     2406pg_getnotify(connObject *self, PyObject *args)
    24042407{
    24052408        PGnotify   *notify;
     
    24642467
    24652468/* source creation */
    2466 static char pg_source__doc__[] =
     2469static char connSource__doc__[] =
    24672470"source() -- creates a new source object for this connection";
    24682471
    24692472static PyObject *
    2470 pg_source(pgobject *self, PyObject *args)
     2473pg_source(connObject *self, PyObject *args)
    24712474{
    24722475        /* checks validity */
     
    24822485
    24832486        /* allocate new pg query object */
    2484         return (PyObject *) pgsource_new(self);
     2487        return (PyObject *) sourceNew(self);
    24852488}
    24862489
    24872490/* database query */
    2488 static char pg_query__doc__[] =
     2491static char connQuery__doc__[] =
    24892492"query(sql, [args]) -- creates a new query object for this connection, using"
    24902493" sql (string) request and optionally a tuple with positional parameters.";
    24912494
    24922495static PyObject *
    2493 pg_query(pgobject *self, PyObject *args)
     2496pg_query(connObject *self, PyObject *args)
    24942497{
    24952498        char            *query;
     
    26902693        }
    26912694
    2692         if (!(npgobj = PyObject_NEW(pgqueryobject, &PgQueryType)))
     2695        if (!(npgobj = PyObject_NEW(pgqueryobject, &queryType)))
    26932696                return NULL;
    26942697
     
    26992702
    27002703#ifdef DIRECT_ACCESS
    2701 static char pg_putline__doc__[] =
     2704static char connPutline__doc__[] =
    27022705"putline() -- sends a line directly to the backend";
    27032706
    27042707/* direct acces function : putline */
    27052708static PyObject *
    2706 pg_putline(pgobject *self, PyObject *args)
     2709pg_putline(connObject *self, PyObject *args)
    27072710{
    27082711        char *line;
     
    27322735
    27332736/* direct access function : getline */
    2734 static char pg_getline__doc__[] =
     2737static char connGetline__doc__[] =
    27352738"getline() -- gets a line directly from the backend.";
    27362739
    27372740static PyObject *
    2738 pg_getline(pgobject *self, PyObject *args)
     2741pg_getline(connObject *self, PyObject *args)
    27392742{
    27402743        char            line[MAX_BUFFER_SIZE];
     
    27752778
    27762779/* direct access function : end copy */
    2777 static char pg_endcopy__doc__[] =
     2780static char connEndcopy__doc__[] =
    27782781"endcopy() -- synchronizes client and server";
    27792782
    27802783static PyObject *
    2781 pg_endcopy(pgobject *self, PyObject *args)
     2784pg_endcopy(connObject *self, PyObject *args)
    27822785{
    27832786        if (!self->cnx)
     
    28192822
    28202823/* insert table */
    2821 static char pg_inserttable__doc__[] =
     2824static char connInserttable__doc__[] =
    28222825"inserttable(string, list) -- insert list in table. The fields in the "
    28232826"list must be in the same order as in the table.";
    28242827
    28252828static PyObject *
    2826 pg_inserttable(pgobject *self, PyObject *args)
     2829pg_inserttable(connObject *self, PyObject *args)
    28272830{
    28282831        PGresult        *result;
     
    30443047
    30453048/* get transaction state */
    3046 static char pg_transaction__doc__[] =
     3049static char connTransaction__doc__[] =
    30473050"Returns the current transaction status.";
    30483051
    30493052static PyObject *
    3050 pg_transaction(pgobject *self, PyObject *args)
     3053pg_transaction(connObject *self, PyObject *args)
    30513054{
    30523055        if (!self->cnx)
     
    30683071
    30693072/* get parameter setting */
    3070 static char pg_parameter__doc__[] =
     3073static char connParameter__doc__[] =
    30713074"Looks up a current parameter setting.";
    30723075
    30733076static PyObject *
    3074 pg_parameter(pgobject *self, PyObject *args)
     3077pg_parameter(connObject *self, PyObject *args)
    30753078{
    30763079        const char *name;
     
    31023105
    31033106/* escape literal */
    3104 static char pg_escape_literal__doc__[] =
     3107static char connEscape_literal__doc__[] =
    31053108"pg_escape_literal(str) -- escape a literal constant for use within SQL.";
    31063109
    31073110static PyObject *
    3108 pg_escape_literal(pgobject *self, PyObject *args)
     3111pg_escape_literal(connObject *self, PyObject *args)
    31093112{
    31103113        char *str; /* our string argument */
     
    31253128
    31263129/* escape identifier */
    3127 static char pg_escape_identifier__doc__[] =
     3130static char connEscape_identifier__doc__[] =
    31283131"pg_escape_identifier(str) -- escape an identifier for use within SQL.";
    31293132
    31303133static PyObject *
    3131 pg_escape_identifier(pgobject *self, PyObject *args)
     3134pg_escape_identifier(connObject *self, PyObject *args)
    31323135{
    31333136        char *str; /* our string argument */
     
    31503153
    31513154/* escape string */
    3152 static char pg_escape_string__doc__[] =
     3155static char connEscape_string__doc__[] =
    31533156"pg_escape_string(str) -- escape a string for use within SQL.";
    31543157
    31553158static PyObject *
    3156 pg_escape_string(pgobject *self, PyObject *args)
     3159pg_escape_string(connObject *self, PyObject *args)
    31573160{
    31583161        char *from; /* our string argument */
     
    31823185
    31833186/* escape bytea */
    3184 static char pg_escape_bytea__doc__[] =
     3187static char connEscape_bytea__doc__[] =
    31853188"pg_escape_bytea(data) -- escape binary data for use within SQL as type bytea.";
    31863189
    31873190static PyObject *
    3188 pg_escape_bytea(pgobject *self, PyObject *args)
     3191pg_escape_bytea(connObject *self, PyObject *args)
    31893192{
    31903193        unsigned char *from; /* our string argument */
     
    32073210#ifdef LARGE_OBJECTS
    32083211/* creates large object */
    3209 static char pg_locreate__doc__[] =
     3212static char connLocreate__doc__[] =
    32103213"locreate() -- creates a new large object in the database.";
    32113214
    32123215static PyObject *
    3213 pg_locreate(pgobject *self, PyObject *args)
     3216pg_locreate(connObject *self, PyObject *args)
    32143217{
    32153218        int                     mode;
     
    32403243
    32413244/* init from already known oid */
    3242 static char pg_getlo__doc__[] =
     3245static char connGetlo__doc__[] =
    32433246"getlo(long) -- create a large object instance for the specified oid.";
    32443247
    32453248static PyObject *
    3246 pg_getlo(pgobject *self, PyObject *args)
     3249pg_getlo(connObject *self, PyObject *args)
    32473250{
    32483251        int                     lo_oid;
     
    32703273
    32713274/* import unix file */
    3272 static char pg_loimport__doc__[] =
     3275static char connLoimport__doc__[] =
    32733276"loimport(string) -- create a new large object from specified file.";
    32743277
    32753278static PyObject *
    3276 pg_loimport(pgobject *self, PyObject *args)
     3279pg_loimport(connObject *self, PyObject *args)
    32773280{
    32783281        char   *name;
     
    33053308/* connection object methods */
    33063309static struct PyMethodDef pgobj_methods[] = {
    3307         {"source", (PyCFunction) pg_source, METH_VARARGS, pg_source__doc__},
    3308         {"query", (PyCFunction) pg_query, METH_VARARGS, pg_query__doc__},
    3309         {"reset", (PyCFunction) pg_reset, METH_VARARGS, pg_reset__doc__},
    3310         {"cancel", (PyCFunction) pg_cancel, METH_VARARGS, pg_cancel__doc__},
    3311         {"close", (PyCFunction) pg_close, METH_VARARGS, pg_close__doc__},
    3312         {"fileno", (PyCFunction) pg_fileno, METH_VARARGS, pg_fileno__doc__},
     3310        {"source", (PyCFunction) pg_source, METH_VARARGS, connSource__doc__},
     3311        {"query", (PyCFunction) pg_query, METH_VARARGS, connQuery__doc__},
     3312        {"reset", (PyCFunction) pg_reset, METH_VARARGS, connReset__doc__},
     3313        {"cancel", (PyCFunction) pg_cancel, METH_VARARGS, connCancel__doc__},
     3314        {"close", (PyCFunction) pg_close, METH_VARARGS, connClose__doc__},
     3315        {"fileno", (PyCFunction) pg_fileno, METH_VARARGS, connFileno__doc__},
    33133316        {"get_notice_receiver", (PyCFunction) pg_get_notice_receiver, METH_VARARGS,
    3314                         pg_get_notice_receiver__doc__},
     3317                        connGet_notice_receiver__doc__},
    33153318        {"set_notice_receiver", (PyCFunction) pg_set_notice_receiver, METH_VARARGS,
    3316                         pg_set_notice_receiver__doc__},
     3319                        connSset_notice_receiver__doc__},
    33173320        {"getnotify", (PyCFunction) pg_getnotify, METH_VARARGS,
    3318                         pg_getnotify__doc__},
     3321                        connGetnotify__doc__},
    33193322        {"inserttable", (PyCFunction) pg_inserttable, METH_VARARGS,
    3320                         pg_inserttable__doc__},
     3323                        connInserttable__doc__},
    33213324        {"transaction", (PyCFunction) pg_transaction, METH_VARARGS,
    3322                         pg_transaction__doc__},
     3325                        connTransaction__doc__},
    33233326        {"parameter", (PyCFunction) pg_parameter, METH_VARARGS,
    3324                         pg_parameter__doc__},
     3327                        connParameter__doc__},
    33253328
    33263329#ifdef ESCAPING_FUNCS
    33273330        {"escape_literal", (PyCFunction) pg_escape_literal, METH_VARARGS,
    3328                         pg_escape_literal__doc__},
     3331                        connEscape_literal__doc__},
    33293332        {"escape_identifier", (PyCFunction) pg_escape_identifier, METH_VARARGS,
    3330                         pg_escape_identifier__doc__},
     3333                        connEscape_identifier__doc__},
    33313334#endif  /* ESCAPING_FUNCS */
    33323335        {"escape_string", (PyCFunction) pg_escape_string, METH_VARARGS,
    3333                         pg_escape_string__doc__},
     3336                        connEscape_string__doc__},
    33343337        {"escape_bytea", (PyCFunction) pg_escape_bytea, METH_VARARGS,
    3335                         pg_escape_bytea__doc__},
     3338                        connEscape_bytea__doc__},
    33363339
    33373340#ifdef DIRECT_ACCESS
    3338         {"putline", (PyCFunction) pg_putline, 1, pg_putline__doc__},
    3339         {"getline", (PyCFunction) pg_getline, 1, pg_getline__doc__},
    3340         {"endcopy", (PyCFunction) pg_endcopy, 1, pg_endcopy__doc__},
     3341        {"putline", (PyCFunction) pg_putline, 1, connPutline__doc__},
     3342        {"getline", (PyCFunction) pg_getline, 1, connGetline__doc__},
     3343        {"endcopy", (PyCFunction) pg_endcopy, 1, connEndcopy__doc__},
    33413344#endif /* DIRECT_ACCESS */
    33423345
    33433346#ifdef LARGE_OBJECTS
    3344         {"locreate", (PyCFunction) pg_locreate, 1, pg_locreate__doc__},
    3345         {"getlo", (PyCFunction) pg_getlo, 1, pg_getlo__doc__},
    3346         {"loimport", (PyCFunction) pg_loimport, 1, pg_loimport__doc__},
     3347        {"locreate", (PyCFunction) pg_locreate, 1, connLocreate__doc__},
     3348        {"getlo", (PyCFunction) pg_getlo, 1, connGetlo__doc__},
     3349        {"loimport", (PyCFunction) pg_loimport, 1, connLoimport__doc__},
    33473350#endif /* LARGE_OBJECTS */
    33483351
     
    33523355/* get attribute */
    33533356static PyObject *
    3354 pg_getattr(pgobject *self, char *name)
     3357connGetattr(connObject *self, char *name)
    33553358{
    33563359        /*
     
    34443447
    34453448/* object type definition */
    3446 static PyTypeObject PgType = {
     3449static PyTypeObject connType = {
    34473450        PyObject_HEAD_INIT(NULL)
    34483451        0,                                                      /* ob_size */
    3449         "pgobject",                                     /* tp_name */
    3450         sizeof(pgobject),                       /* tp_basicsize */
     3452        "connObject",                                   /* tp_name */
     3453        sizeof(connObject),                     /* tp_basicsize */
    34513454        0,                                                      /* tp_itemsize */
    34523455        /* methods */
    3453         (destructor) pg_dealloc,        /* tp_dealloc */
     3456        (destructor) connDelete,        /* tp_dealloc */
    34543457        0,                                                      /* tp_print */
    3455         (getattrfunc) pg_getattr,       /* tp_getattr */
     3458        (getattrfunc) connGetattr,      /* tp_getattr */
    34563459        0,                                                      /* tp_setattr */
    34573460        0,                                                      /* tp_compare */
     
    35453548
    35463549/* object type definition */
    3547 static PyTypeObject PgNoticeType = {
     3550static PyTypeObject noticeType = {
    35483551        PyObject_HEAD_INIT(NULL)
    35493552        0,                                                      /* ob_size */
     
    35703573static struct PyMethodDef pgquery_methods[] = {
    35713574        {"getresult", (PyCFunction) pgquery_getresult, METH_VARARGS,
    3572                         pgquery_getresult__doc__},
     3575                        queryGetresult__doc__},
    35733576        {"dictresult", (PyCFunction) pgquery_dictresult, METH_VARARGS,
    3574                         pgquery_dictresult__doc__},
     3577                        queryDictresult__doc__},
    35753578        {"namedresult", (PyCFunction) pgquery_namedresult, METH_VARARGS,
    3576                         pgquery_namedresult__doc__},
     3579                        queryNamedresult__doc__},
    35773580        {"fieldname", (PyCFunction) pgquery_fieldname, METH_VARARGS,
    3578                          pgquery_fieldname__doc__},
     3581                         queryFieldname__doc__},
    35793582        {"fieldnum", (PyCFunction) pgquery_fieldnum, METH_VARARGS,
    3580                         pgquery_fieldnum__doc__},
     3583                        queryFieldnum__doc__},
    35813584        {"listfields", (PyCFunction) pgquery_listfields, METH_VARARGS,
    3582                         pgquery_listfields__doc__},
     3585                        queryListfields__doc__},
    35833586        {"ntuples", (PyCFunction) pgquery_ntuples, METH_VARARGS,
    3584                         pgquery_ntuples__doc__},
     3587                        queryNtuples__doc__},
    35853588        {NULL, NULL}
    35863589};
     
    35953598
    35963599/* query type definition */
    3597 static PyTypeObject PgQueryType = {
     3600static PyTypeObject queryType = {
    35983601        PyObject_HEAD_INIT(NULL)
    35993602        0,                                                              /* ob_size */
     
    36223625
    36233626/* escape string */
    3624 static char escape_string__doc__[] =
     3627static char pgEscape_string__doc__[] =
    36253628"escape_string(str) -- escape a string for use within SQL.";
    36263629
     
    36533656
    36543657/* escape bytea */
    3655 static char escape_bytea__doc__[] =
     3658static char pgEscape_bytea__doc__[] =
    36563659"escape_bytea(data) -- escape binary data for use within SQL as type bytea.";
    36573660
     
    36773680
    36783681/* unescape bytea */
    3679 static char unescape_bytea__doc__[] =
     3682static char pgUnescape_bytea__doc__[] =
    36803683"unescape_bytea(str) -- unescape bytea data that has been retrieved as text.";
    36813684
     
    37003703
    37013704/* set decimal point */
    3702 static char set_decimal_point__doc__[] =
     3705static char pgSet_decimal_point__doc__[] =
    37033706"set_decimal_point() -- set decimal point to be used for money values.";
    37043707
     
    37183721
    37193722/* get decimal point */
    3720 static char get_decimal_point__doc__[] =
     3723static char pgGet_decimal_point__doc__[] =
    37213724"get_decimal_point() -- get decimal point to be used for money values.";
    37223725
     
    37413744
    37423745/* set decimal */
    3743 static char set_decimal__doc__[] =
     3746static char pgSet_decimal__doc__[] =
    37443747"set_decimal(cls) -- set a decimal type to be used for numeric values.";
    37453748
     
    37693772
    37703773/* set named result */
    3771 static char set_namedresult__doc__[] =
     3774static char pgSet_namedresult__doc__[] =
    37723775"set_namedresult(cls) -- set a function to be used for getting named results.";
    37733776
     
    37943797
    37953798/* gets default host */
    3796 static char getdefhost__doc__[] =
     3799static char pgGetdefhost__doc__[] =
    37973800"get_defhost() -- return default database host.";
    37983801
     
    38133816
    38143817/* sets default host */
    3815 static char setdefhost__doc__[] =
     3818static char pgSetdefhost__doc__[] =
    38163819"set_defhost(string) -- set default database host. Return previous value.";
    38173820
     
    38453848
    38463849/* gets default base */
    3847 static char getdefbase__doc__[] =
     3850static char pgGetdefbase__doc__[] =
    38483851"get_defbase() -- return default database name.";
    38493852
     
    38643867
    38653868/* sets default base */
    3866 static char setdefbase__doc__[] =
     3869static char pgSetdefbase__doc__[] =
    38673870"set_defbase(string) -- set default database name. Return previous value";
    38683871
     
    38963899
    38973900/* gets default options */
    3898 static char getdefopt__doc__[] =
     3901static char pgGetdefopt__doc__[] =
    38993902"get_defopt() -- return default database options.";
    39003903
     
    39153918
    39163919/* sets default opt */
    3917 static char setdefopt__doc__[] =
     3920static char pgSetdefopt__doc__[] =
    39183921"set_defopt(string) -- set default database options. Return previous value.";
    39193922
     
    39473950
    39483951/* gets default tty */
    3949 static char getdeftty__doc__[] =
     3952static char pgGetdeftty__doc__[] =
    39503953"get_deftty() -- return default database debug terminal.";
    39513954
     
    39663969
    39673970/* sets default tty */
    3968 static char setdeftty__doc__[] =
     3971static char pgSetdeftty__doc__[] =
    39693972"set_deftty(string) -- set default database debug terminal. "
    39703973"Return previous value.";
     
    39994002
    40004003/* gets default username */
    4001 static char getdefuser__doc__[] =
     4004static char pgGetdefuser__doc__[] =
    40024005"get_defuser() -- return default database username.";
    40034006
     
    40194022
    40204023/* sets default username */
    4021 static char setdefuser__doc__[] =
     4024static char pgSetdefuser__doc__[] =
    40224025"set_defuser() -- set default database username. Return previous value.";
    40234026
     
    40514054
    40524055/* sets default password */
    4053 static char setdefpasswd__doc__[] =
     4056static char pgSetdefpasswd__doc__[] =
    40544057"set_defpasswd() -- set default database password.";
    40554058
     
    40804083
    40814084/* gets default port */
    4082 static char getdefport__doc__[] =
     4085static char pgGetdefport__doc__[] =
    40834086"get_defport() -- return default database port.";
    40844087
     
    40994102
    41004103/* sets default port */
    4101 static char setdefport__doc__[] =
     4104static char pgSetdefport__doc__[] =
    41024105"set_defport(integer) -- set default database port. Return previous value.";
    41034106
     
    41354138static struct PyMethodDef pg_methods[] = {
    41364139        {"connect", (PyCFunction) pgconnect, METH_VARARGS|METH_KEYWORDS,
    4137                         connect__doc__},
     4140                        pgConnect__doc__},
    41384141        {"escape_string", (PyCFunction) escape_string, METH_VARARGS,
    4139                         escape_string__doc__},
     4142                        pgEscape_string__doc__},
    41404143        {"escape_bytea", (PyCFunction) escape_bytea, METH_VARARGS,
    4141                         escape_bytea__doc__},
     4144                        pgEscape_bytea__doc__},
    41424145        {"unescape_bytea", (PyCFunction) unescape_bytea, METH_VARARGS,
    4143                         unescape_bytea__doc__},
     4146                        pgUnescape_bytea__doc__},
    41444147        {"set_decimal_point", (PyCFunction) set_decimal_point, METH_VARARGS,
    4145                         set_decimal_point__doc__},
     4148                        pgSet_decimal_point__doc__},
    41464149        {"get_decimal_point", (PyCFunction) get_decimal_point, METH_VARARGS,
    4147                         get_decimal_point__doc__},
     4150                        pgGet_decimal_point__doc__},
    41484151        {"set_decimal", (PyCFunction) set_decimal, METH_VARARGS,
    4149                         set_decimal__doc__},
     4152                        pgSet_decimal__doc__},
    41504153        {"set_namedresult", (PyCFunction) set_namedresult, METH_VARARGS,
    4151                         set_namedresult__doc__},
     4154                        pgSet_namedresult__doc__},
    41524155
    41534156#ifdef DEFAULT_VARS
    4154         {"get_defhost", pggetdefhost, METH_VARARGS, getdefhost__doc__},
    4155         {"set_defhost", pgsetdefhost, METH_VARARGS, setdefhost__doc__},
    4156         {"get_defbase", pggetdefbase, METH_VARARGS, getdefbase__doc__},
    4157         {"set_defbase", pgsetdefbase, METH_VARARGS, setdefbase__doc__},
    4158         {"get_defopt", pggetdefopt, METH_VARARGS, getdefopt__doc__},
    4159         {"set_defopt", pgsetdefopt, METH_VARARGS, setdefopt__doc__},
    4160         {"get_deftty", pggetdeftty, METH_VARARGS, getdeftty__doc__},
    4161         {"set_deftty", pgsetdeftty, METH_VARARGS, setdeftty__doc__},
    4162         {"get_defport", pggetdefport, METH_VARARGS, getdefport__doc__},
    4163         {"set_defport", pgsetdefport, METH_VARARGS, setdefport__doc__},
    4164         {"get_defuser", pggetdefuser, METH_VARARGS, getdefuser__doc__},
    4165         {"set_defuser", pgsetdefuser, METH_VARARGS, setdefuser__doc__},
    4166         {"set_defpasswd", pgsetdefpasswd, METH_VARARGS, setdefpasswd__doc__},
     4157        {"get_defhost", pggetdefhost, METH_VARARGS, pgGetdefhost__doc__},
     4158        {"set_defhost", pgsetdefhost, METH_VARARGS, pgSetdefhost__doc__},
     4159        {"get_defbase", pggetdefbase, METH_VARARGS, pgGetdefbase__doc__},
     4160        {"set_defbase", pgsetdefbase, METH_VARARGS, pgSetdefbase__doc__},
     4161        {"get_defopt", pggetdefopt, METH_VARARGS, pgGetdefopt__doc__},
     4162        {"set_defopt", pgsetdefopt, METH_VARARGS, pgSetdefopt__doc__},
     4163        {"get_deftty", pggetdeftty, METH_VARARGS, pgGetdeftty__doc__},
     4164        {"set_deftty", pgsetdeftty, METH_VARARGS, pgSetdeftty__doc__},
     4165        {"get_defport", pggetdefport, METH_VARARGS, pgGetdefport__doc__},
     4166        {"set_defport", pgsetdefport, METH_VARARGS, pgSetdefport__doc__},
     4167        {"get_defuser", pggetdefuser, METH_VARARGS, pgGetdefuser__doc__},
     4168        {"set_defuser", pgsetdefuser, METH_VARARGS, pgSetdefuser__doc__},
     4169        {"set_defpasswd", pgsetdefpasswd, METH_VARARGS, pgSetdefpasswd__doc__},
    41674170#endif /* DEFAULT_VARS */
    41684171        {NULL, NULL} /* sentinel */
     
    41804183
    41814184        /* Initialize here because some WIN platforms get confused otherwise */
    4182         PgType.ob_type = PgNoticeType.ob_type =
    4183                 PgQueryType.ob_type = PgSourceType.ob_type = &PyType_Type;
     4185        connType.ob_type = noticeType.ob_type =
     4186                queryType.ob_type = sourceType.ob_type = &PyType_Type;
    41844187#ifdef LARGE_OBJECTS
    4185         PglargeType.ob_type = &PyType_Type;
     4188        largeType.ob_type = &PyType_Type;
    41864189#endif
    41874190
Note: See TracChangeset for help on using the changeset viewer.