--- MySQLmodule-1.4/MySQLmodule.c Sat Oct 3 11:14:18 1998 +++ Modules/MySQLmodule.c Sat Jan 6 19:38:43 2001 @@ -195,13 +195,12 @@ ****** Helper routines *********************************************************/ -static int clear_channel(self) - STHObject *self; +static int clear_channel(STHObject *self) { if (self->res) { /* only if we have a result */ if (!mysql_eof(self->res)) { MYSQL_ROW dummy; - while (dummy = mysql_fetch_row(self->res)) continue; + while ((dummy = mysql_fetch_row(self->res))) continue; /* check for error. make sure handle exists, though */ if (self->res->handle && mysql_error(self->res->handle)[0] != 0) { PyErr_SetString(MySQLError,mysql_error(self->res->handle)); @@ -213,8 +212,7 @@ } /* catch empty cursors (STH) */ -static int no_response(self) - STHObject *self; +static int no_response(STHObject *self) { if (self->res == NULL) { PyErr_SetString(MySQLError,"no response body"); @@ -225,14 +223,13 @@ /* Take a MYSQL_ROW and turn it into a list */ static PyObject * -pythonify_row(res, thisrow) - MYSQL_RES *res; - MYSQL_ROW thisrow; +pythonify_row(MYSQL_RES *res, + MYSQL_ROW thisrow) { PyObject *rowlist, *fieldobj; MYSQL_FIELD *tf; int i, n; - unsigned int *lengths; + unsigned long *lengths; n = mysql_num_fields(res); lengths = mysql_fetch_lengths(res); @@ -335,13 +332,12 @@ */ static PyObject * -pythonify_res(res, num) - MYSQL_RES *res; - int num; +pythonify_res(MYSQL_RES *res, + int num) { PyObject *reslist; PyObject *rowlist = NULL; - MYSQL_ROW thisrow; + MYSQL_ROW thisrow = NULL; int i = 0; reslist = PyList_New(0); @@ -369,19 +365,18 @@ /* Take a MYSQL_RES and return a table of field data */ static PyObject * -pythonify_res_fields(res) - MYSQL_RES *res; +pythonify_res_fields(MYSQL_RES *res) { PyObject *reslist, *thislist; int i, n; char *type, flags[32]; - MYSQL_FIELD *tf; + MYSQL_FIELD *tf = NULL; reslist = PyList_New(0); if (reslist == NULL) return NULL; n = mysql_num_fields(res); for (i = 0; i < n; i++) { - tf = &(mysql_fetch_field_direct(res, i)); + tf = mysql_fetch_field_direct(res, i); if (tf == NULL) { if (res->handle && mysql_error(res->handle)[0] != 0) { PyErr_SetString(MySQLError,mysql_error(res->handle)); @@ -479,11 +474,10 @@ /* concat three strings */ static void -mystrcpy(field, table, sep, name) - char *field; - char *table; - char *sep; - char *name; +mystrcpy(char *field, + char *table, + char *sep, + char *name) { char *s; s = field; @@ -498,8 +492,8 @@ ********************************************************/ static PyObject * -MySQL_connect(self, args) - PyObject *self, *args; +MySQL_connect(PyObject *self, + PyObject *args) { char *dbhost = NULL; char *dbuser = NULL; @@ -526,8 +520,8 @@ } static PyObject * -MySQL_escape(self,args) - PyObject *self, *args; +MySQL_escape(PyObject *self, + PyObject *args) { char *in = NULL; char *out = NULL; @@ -558,9 +552,8 @@ ************************************************************/ static PyObject * -DBH_selectdb(self, args) - DBHObject *self; - PyObject *args; +DBH_selectdb(DBHObject *self, + PyObject *args) { char *dbname; if (!PyArg_ParseTuple(args, "s|i:selectdb", &dbname, &(self->dbh_use_result))) return NULL; @@ -576,9 +569,8 @@ } static PyObject * -DBH_listdbs(self, args) - DBHObject *self; - PyObject *args; +DBH_listdbs(DBHObject *self, + PyObject *args) { MYSQL_RES *res; PyObject *resobj; @@ -603,9 +595,8 @@ } static PyObject * -DBH_listtables(self, args) - DBHObject *self; - PyObject *args; +DBH_listtables(DBHObject *self, + PyObject *args) { MYSQL_RES *res; PyObject *resobj; @@ -630,9 +621,8 @@ } static PyObject * -DBH_listfields(self, args) - DBHObject *self; - PyObject *args; +DBH_listfields(DBHObject *self, + PyObject *args) { char *tname; char *wildcard = NULL; @@ -658,9 +648,8 @@ } static PyObject * -DBH_listprocesses(self, args) - DBHObject *self; - PyObject *args; +DBH_listprocesses(DBHObject *self, + PyObject *args) { MYSQL_RES *res; PyObject *resobj; @@ -684,10 +673,9 @@ } static PyObject * -DBH_query_helper(self, query, size) - DBHObject *self; - char *query; - unsigned int size; +DBH_query_helper(DBHObject *self, + char *query, + unsigned int size) { MYSQL_RES *res; PyObject *resobj; @@ -718,9 +706,8 @@ } static PyObject * -DBH_do(self, args) - DBHObject *self; - PyObject *args; +DBH_do(DBHObject *self, + PyObject *args) { char *query; unsigned int size; @@ -730,9 +717,8 @@ } static PyObject * -DBH_create(self, args) - DBHObject *self; - PyObject *args; +DBH_create(DBHObject *self, + PyObject *args) { char *dbname; @@ -749,9 +735,8 @@ } static PyObject * -DBH_close(self, args) - DBHObject *self; - PyObject *args; +DBH_close(DBHObject *self, + PyObject *args) { if (!PyArg_ParseTuple(args, ":close")) return NULL; if (self->sth && clear_channel(self->sth)) return NULL; @@ -763,9 +748,8 @@ } static PyObject * -DBH_insertid(self, args) - DBHObject *self; - PyObject *args; +DBH_insertid(DBHObject *self, + PyObject *args) { if (!PyArg_ParseTuple(args, ":insertid")) return NULL; if (self->sth && clear_channel(self->sth)) return NULL; @@ -775,9 +759,8 @@ } static PyObject * -DBH_stat(self, args) - DBHObject *self; - PyObject *args; +DBH_stat(DBHObject *self, + PyObject *args) { char *stat; if (!PyArg_ParseTuple(args, ":stat")) return NULL; @@ -792,9 +775,8 @@ } static PyObject * -DBH_clientinfo(self, args) - DBHObject *self; - PyObject *args; +DBH_clientinfo(DBHObject *self, + PyObject *args) { char *info; if (!PyArg_ParseTuple(args, ":clientinfo")) return NULL; @@ -811,9 +793,8 @@ } static PyObject * -DBH_hostinfo(self, args) - DBHObject *self; - PyObject *args; +DBH_hostinfo(DBHObject *self, + PyObject *args) { char *info; if (!PyArg_ParseTuple(args, ":hostinfo")) return NULL; @@ -828,9 +809,8 @@ } static PyObject * -DBH_serverinfo(self, args) - DBHObject *self; - PyObject *args; +DBH_serverinfo(DBHObject *self, + PyObject *args) { char *info; if (!PyArg_ParseTuple(args, ":serverinfo")) return NULL; @@ -845,9 +825,8 @@ } static PyObject * -DBH_protoinfo(self, args) - DBHObject *self; - PyObject *args; +DBH_protoinfo(DBHObject *self, + PyObject *args) { int info; if (!PyArg_ParseTuple(args, ":protoinfo")) return NULL; @@ -862,9 +841,8 @@ } static PyObject * -DBH_drop(self, args) - DBHObject *self; - PyObject *args; +DBH_drop(DBHObject *self, + PyObject *args) { char *dbname; @@ -881,9 +859,8 @@ } static PyObject * -DBH_reload(self, args) - DBHObject *self; - PyObject *args; +DBH_reload(DBHObject *self, + PyObject *args) { if (!PyArg_ParseTuple(args, ":reload")) return NULL; if (self->sth && clear_channel(self->sth)) return NULL; @@ -898,9 +875,8 @@ } static PyObject * -DBH_shutdown(self, args) - DBHObject *self; - PyObject *args; +DBH_shutdown(DBHObject *self, + PyObject *args) { if (!PyArg_ParseTuple(args, ":shutdown")) return NULL; if (self->sth && clear_channel(self->sth)) return NULL; @@ -916,9 +892,8 @@ /* return a cursor object (STH) for the given query */ static PyObject * -DBH_query(self, args) - DBHObject *self; - PyObject *args; +DBH_query(DBHObject *self, + PyObject *args) { STHObject *sth; char *query; @@ -969,8 +944,8 @@ /* For DBH['query'] syntax */ static PyObject * -DBH_subscript(self, subs) - PyObject *self, *subs; +DBH_subscript(PyObject *self, + PyObject *subs) { char *query; unsigned int size; @@ -982,16 +957,17 @@ } static int -DBH_subscript_assign(self, subs, val) - PyObject *self, *subs, *val; +DBH_subscript_assign(PyObject *self, + PyObject *subs, + PyObject *val) { PyErr_SetString(MySQLError, "MySQL handle is readonly"); return -1; /* -1 is error code in interpreter main loop! (ceval.c) */ } static int -DBH_len(self, subs) - PyObject *self, *subs; +DBH_len(PyObject *self, + PyObject *subs) { PyErr_SetString(MySQLError, "len() of unsized object"); return -1; @@ -1028,16 +1004,14 @@ }; static PyObject * -DBH_getattr(self, name) - DBHObject *self; - char *name; +DBH_getattr(DBHObject *self, + char *name) { return Py_FindMethod(DBH_methods, (PyObject *) self, name); } static void -DBH_dealloc(self) - register DBHObject *self; +DBH_dealloc(register DBHObject *self) { mysql_close(self->handle); PyMem_DEL(self); @@ -1066,9 +1040,8 @@ **************************************************************/ static PyObject * -STH_fields(self, args) - STHObject *self; - PyObject *args; +STH_fields(STHObject *self, + PyObject *args) { PyObject *resobj; if ((!PyArg_ParseTuple(args, ":fields")) || no_response(self)) return NULL; @@ -1081,9 +1054,8 @@ } static PyObject * -STH_fetchrows(self, args) - STHObject *self; - PyObject *args; +STH_fetchrows(STHObject *self, + PyObject *args) { PyObject *resobj; int i = -1; @@ -1098,9 +1070,8 @@ } static PyObject * -STH_fetchdict(self,args) - STHObject *self; - PyObject *args; +STH_fetchdict(STHObject *self, + PyObject *args) { int i = -1; int tlen = 0; @@ -1108,7 +1079,7 @@ char *fieldname = NULL; PyObject *rowdict = NULL; PyObject *datalist, *rowlist, *value; - MYSQL_FIELD *tf; + MYSQL_FIELD *tf = NULL; if ((!PyArg_ParseTuple(args, "|i:fetchdict", &i)) || no_response(self)) return NULL; if (i < 0 && self->sth_use_result == 0) mysql_data_seek(self->res,0); @@ -1122,7 +1093,7 @@ if (rows > 0) { cols = mysql_num_fields(self->res); for (j=0; jres,j)); + tf = mysql_fetch_field_direct(self->res,j); if (tf == NULL) { if (self->res->handle && mysql_error(self->res->handle)[0] != 0) { PyErr_SetString(MySQLError,mysql_error(self->res->handle)); @@ -1144,7 +1115,7 @@ rowlist = PyList_GetItem(datalist,i); if (rowlist == NULL) goto error; for (j=0; jres,j)); + tf = mysql_fetch_field_direct(self->res,j); if (tf == NULL) { if (self->res->handle && mysql_error(self->res->handle)[0] != 0) { PyErr_SetString(MySQLError,mysql_error(self->res->handle)); @@ -1172,9 +1143,8 @@ } static PyObject * -STH_seek(self, args) - STHObject *self; - PyObject *args; +STH_seek(STHObject *self, + PyObject *args) { unsigned int i; if ((!PyArg_ParseTuple(args, "i:seek", &i)) || no_response(self)) return NULL; @@ -1188,27 +1158,24 @@ } static PyObject * -STH_numrows(self, args) - STHObject *self; - PyObject *args; +STH_numrows(STHObject *self, + PyObject *args) { if ((!PyArg_ParseTuple(args, ":numrows")) || no_response(self)) return NULL; return PyInt_FromLong((long) mysql_num_rows(self->res)); } static PyObject * -STH_numfields(self, args) - STHObject *self; - PyObject *args; +STH_numfields(STHObject *self, + PyObject *args) { if ((!PyArg_ParseTuple(args, ":numfields")) || no_response(self)) return NULL; return PyInt_FromLong((long) mysql_num_fields(self->res)); } static PyObject * -STH_eof(self, args) - STHObject *self; - PyObject *args; +STH_eof(STHObject *self, + PyObject *args) { if ((!PyArg_ParseTuple(args, ":eof")) || no_response(self)) return NULL; if (mysql_eof(self->res)) { /* only useful if mysql_use_result() has been used */ @@ -1221,18 +1188,16 @@ } static PyObject * -STH_affectedrows(self, args) - STHObject *self; - PyObject *args; +STH_affectedrows(STHObject *self, + PyObject *args) { if (!PyArg_ParseTuple(args, ":affectedrows")) return NULL; return PyInt_FromLong((long) self->affected_rows); } static PyObject * -STH_insertid(self, args) - STHObject *self; - PyObject *args; +STH_insertid(STHObject *self, + PyObject *args) { if (!PyArg_ParseTuple(args, ":insertid")) return NULL; return PyInt_FromLong((long) self->insert_id); @@ -1253,16 +1218,14 @@ }; static PyObject * -STH_getattr(self, name) - STHObject *self; - char *name; +STH_getattr(STHObject *self, + char *name) { return Py_FindMethod(STH_methods, (PyObject *) self, name); } static void -STH_dealloc(self) - register STHObject *self; +STH_dealloc(register STHObject *self) { if (self->res) mysql_free_result(self->res); Py_XDECREF(self->dbh); @@ -1292,7 +1255,7 @@ ***********************************************************/ void -initMySQL() +initMySQL(void) { PyObject *module, *dict, *str;