informixdb-cvs Mailing List for InformixDB (Page 6)
Brought to you by:
chaese,
f-apolloner
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(36) |
Nov
(40) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(1) |
Feb
|
Mar
(6) |
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(13) |
Oct
(12) |
Nov
(10) |
Dec
(8) |
2007 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
(5) |
Jul
|
Aug
(1) |
Sep
(4) |
Oct
(15) |
Nov
|
Dec
(1) |
2008 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(5) |
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(4) |
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Carsten H. <ch...@us...> - 2005-11-17 23:53:54
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28670/ext Modified Files: _informixdb.ec Log Message: Fix doCopy() for user-defined distinct types. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** _informixdb.ec 17 Nov 2005 05:35:52 -0000 1.39 --- _informixdb.ec 17 Nov 2005 23:53:44 -0000 1.40 *************** *** 1682,1686 **** struct Connection_t *conn) { ! switch(type){ case SQLDATE: { --- 1682,1686 ---- struct Connection_t *conn) { ! switch(type & SQLTYPE){ case SQLDATE: { |
From: Carsten H. <ch...@us...> - 2005-11-17 21:26:31
|
Update of /cvsroot/informixdb/informixdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15863 Modified Files: informixdb.py Log Message: It's probably safer to update self.__dict__ than blatantly replacing it. Index: informixdb.py =================================================================== RCS file: /cvsroot/informixdb/informixdb/informixdb.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** informixdb.py 17 Nov 2005 02:24:22 -0000 1.13 --- informixdb.py 17 Nov 2005 21:26:23 -0000 1.14 *************** *** 48,52 **** class Row(object): ! def __init__(self, d): self.__dict__ = d def __repr__(self): return repr(self.__dict__) def __str__(self): return str(self.__dict__) --- 48,52 ---- class Row(object): ! def __init__(self, d): self.__dict__.update(d) def __repr__(self): return repr(self.__dict__) def __str__(self): return str(self.__dict__) |
From: Carsten H. <ch...@us...> - 2005-11-17 05:36:00
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4846/ext Modified Files: _informixdb.ec Log Message: Add support for initializing, inspecting, and altering Sblob storage characteristics. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** _informixdb.ec 17 Nov 2005 02:24:22 -0000 1.38 --- _informixdb.ec 17 Nov 2005 05:35:52 -0000 1.39 *************** *** 2,6 **** * Copyright (c) 1997 by IV DocEye AB * Copyright (c) 1999 by Stephen J. Turner ! * Copyright (c) 1999 by Carsten Haese * * By obtaining, using, and/or copying this software and/or its --- 2,6 ---- * Copyright (c) 1997 by IV DocEye AB * Copyright (c) 1999 by Stephen J. Turner ! * Copyright (c) 2005 by Carsten Haese * * By obtaining, using, and/or copying this software and/or its *************** *** 234,237 **** --- 234,239 ---- static PyObject *Sblob_tell(Sblob *self); static PyObject *Sblob_stat(Sblob *self); + static PyObject *Sblob_specget(Sblob *self, void *closure); + static int Sblob_alter(Sblob *self, PyObject *value, void *closure); static PyMethodDef Sblob_methods[] = { *************** *** 250,254 **** --- 252,274 ---- }; + enum SBLOB_CSPECS { + SBLOB_CSPEC_ESTBYTES=1, + SBLOB_CSPEC_EXTSZ, + SBLOB_CSPEC_FLAGS, + SBLOB_CSPEC_MAXBYTES, + SBLOB_CSPEC_SBSPACE + } ; + static PyGetSetDef Sblob_properties[] = { + { "estbytes", (getter)Sblob_specget, (setter)NULL, "", + (void*)SBLOB_CSPEC_ESTBYTES }, + { "extsz", (getter)Sblob_specget, (setter)Sblob_alter, "", + (void*)SBLOB_CSPEC_EXTSZ }, + { "flags", (getter)Sblob_specget, (setter)Sblob_alter, "", + (void*)SBLOB_CSPEC_FLAGS }, + { "maxbytes", (getter)Sblob_specget, (setter)NULL, "", + (void*)SBLOB_CSPEC_MAXBYTES }, + { "sbspace", (getter)Sblob_specget, (setter)NULL, "", + (void*)SBLOB_CSPEC_SBSPACE }, { NULL } }; *************** *** 2872,2875 **** --- 2892,2907 ---- #ifdef HAVE_SBLOB + static int makeint8(PyObject *in, ifx_int8_t *out) + { + PyObject *sitem; + char *val; + mint result; + sitem = PyObject_Str(in); + val = PyString_AS_STRING((PyStringObject*)sitem); + result = ifx_int8cvasc(val, strlen(val), out); + Py_DECREF(sitem); + return result; + } + static int Sblob_init(Sblob *self, PyObject *args, PyObject* kwargs) { *************** *** 2879,2890 **** mint open_flags = LO_RDWR; int sblob_type = 0; static char* kwdlist[] = { ! "connection", "do_create", "type", "create_flags", "open_flags", 0 }; mint result, err; if (!PyArg_ParseTupleAndKeywords( ! args, kwargs, "O!i|iii", kwdlist, &Connection_type, &conn, ! &do_create, &sblob_type, &create_flags, &open_flags)) return -1; --- 2911,2930 ---- mint open_flags = LO_RDWR; int sblob_type = 0; + char *col_info = NULL; + char *sbspace = NULL; + mint extsz = 0; + PyObject *py_estbytes = NULL, *py_maxbytes = NULL; + ifx_int8_t estbytes, maxbytes; + static char* kwdlist[] = { ! "connection", "do_create", "type", "create_flags", "open_flags", ! "col_info", "sbspace", "extsz", "estbytes", "maxbytes", 0 }; mint result, err; if (!PyArg_ParseTupleAndKeywords( ! args, kwargs, "O!i|iiissiOO", kwdlist, &Connection_type, &conn, ! &do_create, &sblob_type, &create_flags, &open_flags, &col_info, ! &sbspace, &extsz, &py_estbytes, &py_maxbytes)) return -1; *************** *** 2902,2909 **** return -1; } ! result = ifx_lo_specset_flags(self->lo_spec, create_flags); ! if (result<0) { ! is_dberror(self->conn, NULL, "ifx_lo_specset_flags"); ! return -1; } result = ifx_lo_create(self->lo_spec, open_flags, &self->lo, &err); --- 2942,2988 ---- return -1; } ! if (col_info && *col_info) { ! if (ifx_lo_col_info(col_info, self->lo_spec)<0) { ! is_dberror(self->conn, NULL, "ifx_lo_col_info"); ! return -1; ! } ! } ! if (sbspace && *sbspace) { ! if (ifx_lo_specset_sbspace(self->lo_spec, sbspace)<0) { ! is_dberror(self->conn, NULL, "ifx_lo_specset_sbspace"); ! return -1; ! } ! } ! if (extsz>0) { ! if (ifx_lo_specset_extsz(self->lo_spec, extsz)<0) { ! is_dberror(self->conn, NULL, "ifx_lo_specset_extsz"); ! return -1; ! } ! } ! if (py_estbytes) { ! if (makeint8(py_estbytes, &estbytes)<0) { ! PyErr_SetString(PyExc_TypeError, "non-numeric estbytes"); ! return -1; ! } ! if (ifx_lo_specset_estbytes(self->lo_spec, &estbytes)<0) { ! is_dberror(self->conn, NULL, "ifx_lo_specset_estbytes"); ! return -1; ! } ! } ! if (py_maxbytes) { ! if (makeint8(py_maxbytes, &maxbytes)<0) { ! PyErr_SetString(PyExc_TypeError, "non-numeric maxbytes"); ! return -1; ! } ! if (ifx_lo_specset_maxbytes(self->lo_spec, &maxbytes)<0) { ! is_dberror(self->conn, NULL, "ifx_lo_specset_maxbytes"); ! return -1; ! } ! } ! if (create_flags) { ! if (ifx_lo_specset_flags(self->lo_spec, create_flags)<0) { ! is_dberror(self->conn, NULL, "ifx_lo_specset_flags"); ! return -1; ! } } result = ifx_lo_create(self->lo_spec, open_flags, &self->lo, &err); *************** *** 3022,3027 **** mint result; PyObject *py_offset; ! PyObject *sitem; ! char *val, pos_str[30]; mint whence = LO_SEEK_SET; ifx_int8_t offset, seek_pos; --- 3101,3105 ---- mint result; PyObject *py_offset; ! char pos_str[30]; mint whence = LO_SEEK_SET; ifx_int8_t offset, seek_pos; *************** *** 3036,3045 **** return NULL; ! sitem = PyObject_Str(py_offset); ! val = PyString_AS_STRING((PyStringObject*)sitem); ! result = ifx_int8cvasc(val, strlen(val), &offset); ! Py_DECREF(sitem); ! if (result<0) { ! ret_on_dberror(self->conn, NULL, "ifx_int8cvasc"); } if (setConnection(self->conn)) return NULL; --- 3114,3120 ---- return NULL; ! if (makeint8(py_offset, &offset)<0) { ! PyErr_SetString(PyExc_TypeError, "non-numeric offset"); ! return NULL; } if (setConnection(self->conn)) return NULL; *************** *** 3138,3141 **** --- 3213,3327 ---- "mtime", mtime_result, "refcnt", refcnt); } + + static PyObject *Sblob_specget(Sblob *self, void *closure) + { + ifx_lo_stat_t *lo_stat; + ifx_lo_create_spec_t *lo_spec; + ifx_int8_t int8result; + mint mintresult; + char buf[129]; + + if (!self->lofd) { + if (error_handle(self->conn, NULL, ExcInterfaceError, + PyString_FromString("Sblob is not open"))) + return NULL; + } + if (setConnection(self->conn)) return NULL; + if (ifx_lo_stat(self->lofd, &lo_stat)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_stat"); + } + lo_spec = ifx_lo_stat_cspec(lo_stat); + if (!lo_spec) { + ret_on_dberror(self->conn, NULL, "ifx_lo_stat_cspec"); + } + switch ((int)closure) { + case SBLOB_CSPEC_ESTBYTES: + if (ifx_lo_specget_estbytes(lo_spec, &int8result)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_specget_estbytes"); + } + break; + case SBLOB_CSPEC_MAXBYTES: + if (ifx_lo_specget_maxbytes(lo_spec, &int8result)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_specget_maxbytes"); + } + break; + case SBLOB_CSPEC_EXTSZ: + if ((mintresult=ifx_lo_specget_extsz(lo_spec))<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_specget_extsz"); + } + break; + case SBLOB_CSPEC_FLAGS: + if ((mintresult=ifx_lo_specget_flags(lo_spec))<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_specget_flags"); + } + break; + break; + case SBLOB_CSPEC_SBSPACE: + if (ifx_lo_specget_sbspace(lo_spec, buf, 128)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_specget_sbspace"); + } + break; + } + if (ifx_lo_stat_free(lo_stat)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_stat_free"); + } + switch ((int)closure) { + case SBLOB_CSPEC_EXTSZ: + case SBLOB_CSPEC_FLAGS: + return PyInt_FromLong((long)mintresult); break; + case SBLOB_CSPEC_SBSPACE: + return PyString_FromString(buf); break; + case SBLOB_CSPEC_ESTBYTES: + case SBLOB_CSPEC_MAXBYTES: + if (ifx_int8toasc(&int8result, buf, 29)<0) { + ret_on_dberror(self->conn, NULL, "ifx_int8toasc"); + } + buf[29] = 0; + return PyLong_FromString(buf, NULL, 10); + break; + } + Py_INCREF(Py_None); + return Py_None; + } + + static int Sblob_alter(Sblob *self, PyObject *value, void *closure) + { + ifx_lo_stat_t *lo_stat; + ifx_lo_create_spec_t *lo_spec; + mint mintval; + + if (!self->lofd) { + if (error_handle(self->conn, NULL, ExcInterfaceError, + PyString_FromString("Sblob is not open"))) + return 1; + } + if (setConnection(self->conn)) return 1; + if (ifx_lo_stat(self->lofd, &lo_stat)<0) { + if (is_dberror(self->conn, NULL, "ifx_lo_stat")) return 1; + } + mintval = PyInt_AsLong(value); + if (PyErr_Occurred()) return 1; + lo_spec = ifx_lo_stat_cspec(lo_stat); + if (!lo_spec) { + if (is_dberror(self->conn, NULL, "ifx_lo_stat_cspec")) return 1; + } + if ((long)closure==SBLOB_CSPEC_EXTSZ) { + if (ifx_lo_specset_extsz(lo_spec, mintval)<0) { + if (is_dberror(self->conn, NULL, "ifx_lo_specset_extsz")) return 1; + } + } + if ((long)closure==SBLOB_CSPEC_FLAGS) { + if (ifx_lo_specset_flags(lo_spec, mintval)<0) { + if (is_dberror(self->conn, NULL, "ifx_lo_specset_flags")) return 1; + } + } + if (ifx_lo_alter(&self->lo, lo_spec)<0) { + if (is_dberror(self->conn, NULL, "ifx_lo_alter")) return 1; + } + if (ifx_lo_stat_free(lo_stat)<0) { + if (is_dberror(self->conn, NULL, "ifx_lo_stat_free")) return 1; + } + return 0; + } #endif |
From: Carsten H. <ch...@us...> - 2005-11-17 02:24:33
|
Update of /cvsroot/informixdb/informixdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7736 Modified Files: informixdb.py Log Message: The user shouldn't instantiate Sblobs directly, which I prevented by not making the Sblob name visible. However, that makes it hard to expose doc strings once I get around to writing them. This way is better. Do the same for Connection and Cursor since those shouldn't be instantiated directly, either. Index: informixdb.py =================================================================== RCS file: /cvsroot/informixdb/informixdb/informixdb.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** informixdb.py 16 Nov 2005 15:14:31 -0000 1.12 --- informixdb.py 17 Nov 2005 02:24:22 -0000 1.13 *************** *** 129,134 **** # promote the class definitions of _informixdb.Cursor and # _informixdb.Connection into this namespace so that help(informixdb) ! # sees their doc strings. from _informixdb import Cursor as _Cursor, Connection as _Connection ! class Cursor(_Cursor): pass ! class Connection(_Connection): pass --- 129,149 ---- # promote the class definitions of _informixdb.Cursor and # _informixdb.Connection into this namespace so that help(informixdb) ! # sees their doc strings. Also make it impossible for the user to try ! # to instantiate these classes directly. from _informixdb import Cursor as _Cursor, Connection as _Connection ! class Cursor(_Cursor): ! def __new__(self, *args, **kwargs): ! raise InterfaceError, "Use Connection.cursor() to instantiate a cursor." ! del _Cursor ! class Connection(_Connection): ! def __new__(self, *args, **kwargs): ! raise InterfaceError, "Use connect() to instantiate a connection." ! del _Connection ! try: ! # Same for Sblobs if we have support for them in _informixdb ! from _informixdb import Sblob as _Sblob ! class Sblob(_Sblob): ! def __new__(self, *args, **kwargs): ! raise InterfaceError, "Use Connection.Sblob() to instantiate an Sblob." ! del _Sblob ! except: pass |
From: Carsten H. <ch...@us...> - 2005-11-17 02:24:33
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7736/ext Modified Files: _informixdb.ec Log Message: The user shouldn't instantiate Sblobs directly, which I prevented by not making the Sblob name visible. However, that makes it hard to expose doc strings once I get around to writing them. This way is better. Do the same for Connection and Cursor since those shouldn't be instantiated directly, either. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** _informixdb.ec 17 Nov 2005 01:40:06 -0000 1.37 --- _informixdb.ec 17 Nov 2005 02:24:22 -0000 1.38 *************** *** 3256,3259 **** --- 3256,3261 ---- ExposeIntConstant(LO_SEEK_CUR); ExposeIntConstant(LO_SEEK_END); + Py_INCREF(&Sblob_type); + PyModule_AddObject(m, "Sblob", (PyObject*)&Sblob_type); #endif |
From: Carsten H. <ch...@us...> - 2005-11-17 01:40:28
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1435/ext Modified Files: _informixdb.ec Log Message: PyTuple_SET_ITEM steals the reference to v, but PyDict_SetItemString does not. Consequently, we need to decref v in the dict case. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** _informixdb.ec 16 Nov 2005 15:14:31 -0000 1.36 --- _informixdb.ec 17 Nov 2005 01:40:06 -0000 1.37 *************** *** 1894,1897 **** --- 1894,1898 ---- cur->rowformat==CURSOR_ROWFORMAT_ROWOBJ) { PyDict_SetItemString(row, var->sqlname, v); + Py_DECREF(v); } else { PyTuple_SET_ITEM(row, pos, v); |
From: Carsten H. <ch...@us...> - 2005-11-16 15:14:45
|
Update of /cvsroot/informixdb/informixdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2086 Modified Files: informixdb.py Log Message: add option to have rows returned as objects with attributes corresponding to column names Index: informixdb.py =================================================================== RCS file: /cvsroot/informixdb/informixdb/informixdb.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** informixdb.py 31 Oct 2005 18:08:51 -0000 1.11 --- informixdb.py 16 Nov 2005 15:14:31 -0000 1.12 *************** *** 47,50 **** --- 47,55 ---- """ + class Row(object): + def __init__(self, d): self.__dict__ = d + def __repr__(self): return repr(self.__dict__) + def __str__(self): return str(self.__dict__) + class IntervalYearToMonth(object): def __init__(self, years=0, months=0): |
From: Carsten H. <ch...@us...> - 2005-11-16 15:14:39
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2086/ext Modified Files: _informixdb.ec Log Message: add option to have rows returned as objects with attributes corresponding to column names Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** _informixdb.ec 15 Nov 2005 21:48:29 -0000 1.35 --- _informixdb.ec 16 Nov 2005 15:14:31 -0000 1.36 *************** *** 111,114 **** --- 111,115 ---- static PyObject *IntervalY2MType; static PyObject *IntervalD2FType; + static PyObject *DataRowType; PyDoc_STRVAR(ExcWarning_doc, *************** *** 299,303 **** /************************* Cursors *************************/ ! enum CURSOR_ROWFORMAT { CURSOR_ROWFORMAT_TUPLE, CURSOR_ROWFORMAT_DICT }; typedef struct Cursor_t --- 300,308 ---- /************************* Cursors *************************/ ! enum CURSOR_ROWFORMAT { ! CURSOR_ROWFORMAT_TUPLE, ! CURSOR_ROWFORMAT_DICT, ! CURSOR_ROWFORMAT_ROWOBJ ! }; typedef struct Cursor_t *************** *** 1866,1870 **** int pos; struct sqlvar_struct *var; ! if (cur->rowformat == CURSOR_ROWFORMAT_DICT) { row = PyDict_New(); } else { --- 1871,1876 ---- int pos; struct sqlvar_struct *var; ! if (cur->rowformat==CURSOR_ROWFORMAT_DICT || ! cur->rowformat==CURSOR_ROWFORMAT_ROWOBJ) { row = PyDict_New(); } else { *************** *** 1885,1889 **** } ! if (cur->rowformat == CURSOR_ROWFORMAT_DICT) { PyDict_SetItemString(row, var->sqlname, v); } else { --- 1891,1896 ---- } ! if (cur->rowformat==CURSOR_ROWFORMAT_DICT || ! cur->rowformat==CURSOR_ROWFORMAT_ROWOBJ) { PyDict_SetItemString(row, var->sqlname, v); } else { *************** *** 1891,1894 **** --- 1898,1904 ---- } } + if (cur->rowformat == CURSOR_ROWFORMAT_ROWOBJ) { + row = CallObjectAndDiscardArgs(DataRowType, Py_BuildValue("(N)", row) ); + } return row; } *************** *** 2138,2145 **** self->errorhandler = conn->errorhandler; Py_INCREF(self->errorhandler); if (rowformat == CURSOR_ROWFORMAT_DICT) { self->rowformat = CURSOR_ROWFORMAT_DICT; ! } else { ! self->rowformat = CURSOR_ROWFORMAT_TUPLE; } --- 2148,2157 ---- self->errorhandler = conn->errorhandler; Py_INCREF(self->errorhandler); + self->rowformat = CURSOR_ROWFORMAT_TUPLE; if (rowformat == CURSOR_ROWFORMAT_DICT) { self->rowformat = CURSOR_ROWFORMAT_DICT; ! } ! if (rowformat == CURSOR_ROWFORMAT_ROWOBJ) { ! self->rowformat = CURSOR_ROWFORMAT_ROWOBJ; } *************** *** 3212,3215 **** --- 3224,3228 ---- PyModule_AddIntConstant(m, "ROW_AS_TUPLE", CURSOR_ROWFORMAT_TUPLE); PyModule_AddIntConstant(m, "ROW_AS_DICT", CURSOR_ROWFORMAT_DICT); + PyModule_AddIntConstant(m, "ROW_AS_OBJECT", CURSOR_ROWFORMAT_ROWOBJ); #ifdef HAVE_SBLOB *************** *** 3256,3261 **** --- 3269,3276 ---- IntervalD2FType = PyDict_GetItemString( informixdbmdict, "IntervalDayToFraction"); + DataRowType = PyDict_GetItemString(informixdbmdict, "Row"); Py_INCREF(IntervalY2MType); Py_INCREF(IntervalD2FType); + Py_INCREF(DataRowType); PyDateTime_IMPORT; |
From: Carsten H. <ch...@us...> - 2005-11-15 21:48:37
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6164/ext Modified Files: _informixdb.ec Log Message: Set correct connection context before calling ifx_lo_close in Sblob destructor and fix an object reference leak. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** _informixdb.ec 15 Nov 2005 20:31:23 -0000 1.34 --- _informixdb.ec 15 Nov 2005 21:48:29 -0000 1.35 *************** *** 2907,2911 **** { if (self->lofd) { ! ifx_lo_close(self->lofd); self->lofd = 0; } --- 2907,2914 ---- { if (self->lofd) { ! if (self->conn) { ! if (setConnection(self->conn)) PyErr_Clear(); ! else ifx_lo_close(self->lofd); ! } self->lofd = 0; } *************** *** 2914,2917 **** --- 2917,2921 ---- self->lo_spec = NULL; } + Py_XDECREF(self->conn); self->ob_type->tp_free((PyObject*)self); } |
From: Carsten H. <ch...@us...> - 2005-11-15 20:31:31
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21763/ext Modified Files: _informixdb.ec Log Message: Apparently calling ifx_lo_release explicitly does more harm than good due to a bug in the engine. Leave it out and let the engine clean up behind us when the connection is closed. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** _informixdb.ec 15 Nov 2005 18:25:39 -0000 1.33 --- _informixdb.ec 15 Nov 2005 20:31:23 -0000 1.34 *************** *** 2910,2914 **** self->lofd = 0; } - ifx_lo_release(&self->lo); if (self->lo_spec) { ifx_lo_spec_free(self->lo_spec); --- 2910,2913 ---- |
From: Carsten H. <ch...@us...> - 2005-11-15 18:25:49
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30674/ext Modified Files: _informixdb.ec Log Message: Fix object reference leaks that Daniel found. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** _informixdb.ec 14 Nov 2005 18:20:12 -0000 1.32 --- _informixdb.ec 15 Nov 2005 18:25:39 -0000 1.33 *************** *** 1646,1649 **** --- 1646,1657 ---- } + static PyObject *CallObjectAndDiscardArgs(PyObject *t, PyObject *a) + { + PyObject *result; + result = PyObject_CallObject(t, a); + Py_DECREF(a); + return result; + } + static PyObject *doCopy(/* const */ void *data, int type, int4 xid, struct Connection_t *conn) *************** *** 1732,1736 **** pos--; } ! return PyObject_CallObject(IntervalY2MType, Py_BuildValue("(ii)",sign*year,sign*month) ); } --- 1740,1744 ---- pos--; } ! return CallObjectAndDiscardArgs(IntervalY2MType, Py_BuildValue("(ii)",sign*year,sign*month) ); } *************** *** 1756,1760 **** pos--; } ! return PyObject_CallObject(IntervalD2FType, Py_BuildValue("(iii)", sign*day, sign*(3600*hour+60*minute+second), sign*usec) ); --- 1764,1768 ---- pos--; } ! return CallObjectAndDiscardArgs(IntervalD2FType, Py_BuildValue("(iii)", sign*day, sign*(3600*hour+60*minute+second), sign*usec) ); *************** *** 1819,1823 **** if (ISSMARTBLOB(type,xid)) { Sblob *new_sblob; ! new_sblob = (Sblob*)PyObject_CallObject((PyObject*)&Sblob_type, Py_BuildValue("(Oi)", conn, 0) ); memcpy(&new_sblob->lo, data, sizeof(ifx_lo_t)); --- 1827,1831 ---- if (ISSMARTBLOB(type,xid)) { Sblob *new_sblob; ! new_sblob = (Sblob*)CallObjectAndDiscardArgs((PyObject*)&Sblob_type, Py_BuildValue("(Oi)", conn, 0) ); memcpy(&new_sblob->lo, data, sizeof(ifx_lo_t)); *************** *** 3051,3054 **** --- 3059,3071 ---- } + static PyObject *maketimestamp(int ticks) + { + PyObject *a, *result; + a = Py_BuildValue("(i)",ticks); + result = db_TimestampFromTicks(NULL,a); + Py_DECREF(a); + return result; + } + static PyObject *Sblob_stat(Sblob *self) { *************** *** 3072,3090 **** ret_on_dberror(self->conn, NULL, "ifx_lo_stat_size"); } ! if ((atime=ifx_lo_stat_atime(lo_stat))<0) { ! atime_result = Py_None; Py_INCREF(Py_None); ! } else { ! atime_result = db_TimestampFromTicks(NULL,Py_BuildValue("(i)",atime)); ! } ! if ((ctime=ifx_lo_stat_ctime(lo_stat))<0) { ! ctime_result = Py_None; Py_INCREF(Py_None); ! } else { ! ctime_result = db_TimestampFromTicks(NULL,Py_BuildValue("(i)",ctime)); ! } ! if ((mtime=ifx_lo_stat_mtime_sec(lo_stat))<0) { ! mtime_result = Py_None; Py_INCREF(Py_None); ! } else { ! mtime_result = db_TimestampFromTicks(NULL,Py_BuildValue("(i)",mtime)); ! } if ((refcnt=ifx_lo_stat_refcnt(lo_stat))<0) { refcnt = 0; --- 3089,3095 ---- ret_on_dberror(self->conn, NULL, "ifx_lo_stat_size"); } ! atime=ifx_lo_stat_atime(lo_stat); ! ctime=ifx_lo_stat_ctime(lo_stat); ! mtime=ifx_lo_stat_mtime_sec(lo_stat); if ((refcnt=ifx_lo_stat_refcnt(lo_stat))<0) { refcnt = 0; *************** *** 3096,3099 **** --- 3101,3119 ---- ret_on_dberror(self->conn, NULL, "ifx_int8toasc"); } + if (atime<0) { + atime_result = Py_None; Py_INCREF(Py_None); + } else { + atime_result = maketimestamp(atime); + } + if (ctime<0) { + ctime_result = Py_None; Py_INCREF(Py_None); + } else { + ctime_result = maketimestamp(ctime); + } + if (mtime<0) { + mtime_result = Py_None; Py_INCREF(Py_None); + } else { + mtime_result = maketimestamp(mtime); + } size_str[29] = 0; size_result = PyLong_FromString(size_str, NULL, 10); |
From: Daniel S. <da...@us...> - 2005-11-14 18:20:28
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24129/ext Modified Files: _informixdb.ec Log Message: fix three compiler warnings (gcc) Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** _informixdb.ec 10 Nov 2005 16:47:48 -0000 1.31 --- _informixdb.ec 14 Nov 2005 18:20:12 -0000 1.32 *************** *** 1122,1125 **** --- 1122,1126 ---- var->sqllen = sizeof(ifx_lo_t); *var->sqlind = 0; + return 1; } #endif *************** *** 2995,2999 **** { static char* kwdlist[] = { "offset", "whence", 0 }; ! mint result, err; PyObject *py_offset; PyObject *sitem; --- 2996,3000 ---- { static char* kwdlist[] = { "offset", "whence", 0 }; ! mint result; PyObject *py_offset; PyObject *sitem; *************** *** 3053,3057 **** { ifx_lo_stat_t *lo_stat; - mint result; ifx_int8_t stat_size; char size_str[30]; --- 3054,3057 ---- |
From: Carsten H. <ch...@us...> - 2005-11-10 16:47:56
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10971/ext Modified Files: _informixdb.ec Log Message: make sure that the ifx_lo_xxx calls are made in the correct connection context Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** _informixdb.ec 10 Nov 2005 16:31:38 -0000 1.30 --- _informixdb.ec 10 Nov 2005 16:47:48 -0000 1.31 *************** *** 2911,2914 **** --- 2911,2915 ---- static PyObject *Sblob_close(Sblob *self) { if (self->lofd) { + if (setConnection(self->conn)) return NULL; ifx_lo_close(self->lofd); self->lofd = 0; *************** *** 2931,2934 **** --- 2932,2936 ---- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwdlist, &flags)) return NULL; + if (setConnection(self->conn)) return NULL; result = ifx_lo_open(&self->lo, flags, &err); if (result<0) { *************** *** 2958,2961 **** --- 2960,2964 ---- return PyErr_NoMemory(); } + if (setConnection(self->conn)) return NULL; result = ifx_lo_read(self->lofd, buf, buflen, &err); if (result<0) { *************** *** 2981,2984 **** --- 2984,2988 ---- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#", kwdlist, &buf, &buflen)) return NULL; + if (setConnection(self->conn)) return NULL; result = ifx_lo_write(self->lofd, buf, buflen, &err); if (result<0) { *************** *** 3014,3017 **** --- 3018,3022 ---- ret_on_dberror(self->conn, NULL, "ifx_int8cvasc"); } + if (setConnection(self->conn)) return NULL; if (ifx_lo_seek(self->lofd, &offset, whence, &seek_pos)<0) { ret_on_dberror(self->conn, NULL, "ifx_lo_seek"); *************** *** 3034,3037 **** --- 3039,3043 ---- return NULL; } + if (setConnection(self->conn)) return NULL; if (ifx_lo_tell(self->lofd, &seek_pos)<0) { ret_on_dberror(self->conn, NULL, "ifx_lo_tell"); *************** *** 3059,3062 **** --- 3065,3069 ---- return NULL; } + if (setConnection(self->conn)) return NULL; if (ifx_lo_stat(self->lofd, &lo_stat)<0) { ret_on_dberror(self->conn, NULL, "ifx_lo_stat"); |
From: Carsten H. <ch...@us...> - 2005-11-10 16:31:49
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7545/ext Modified Files: _informixdb.ec Log Message: make arguments optional: flags in Sblob.open and whence in Sblob.seek Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** _informixdb.ec 10 Nov 2005 05:04:07 -0000 1.29 --- _informixdb.ec 10 Nov 2005 16:31:38 -0000 1.30 *************** *** 2929,2933 **** return NULL; } ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwdlist, &flags)) return NULL; result = ifx_lo_open(&self->lo, flags, &err); --- 2929,2933 ---- return NULL; } ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwdlist, &flags)) return NULL; result = ifx_lo_open(&self->lo, flags, &err); *************** *** 2995,2999 **** PyObject *sitem; char *val, pos_str[30]; ! mint whence; ifx_int8_t offset, seek_pos; --- 2995,2999 ---- PyObject *sitem; char *val, pos_str[30]; ! mint whence = LO_SEEK_SET; ifx_int8_t offset, seek_pos; *************** *** 3003,3007 **** return NULL; } ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi", kwdlist, &py_offset, &whence)) return NULL; --- 3003,3007 ---- return NULL; } ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i", kwdlist, &py_offset, &whence)) return NULL; |
From: Carsten H. <ch...@us...> - 2005-11-10 05:04:15
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31916/ext Modified Files: _informixdb.ec Log Message: Initial (experimental) support for Smart Blobs. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** _informixdb.ec 9 Nov 2005 07:58:47 -0000 1.28 --- _informixdb.ec 10 Nov 2005 05:04:07 -0000 1.29 *************** *** 52,55 **** --- 52,64 ---- #include <datetime.h> + /* Use LO_RDWR to determine if the CSDK supports Smart Blobs */ + #ifdef LO_RDWR + #define HAVE_SBLOB + #define SBLOB_TYPE_BLOB 0 + #define SBLOB_TYPE_CLOB 1 + #else + #undef HAVE_SBLOB + #endif + #if HAVE_C_DATETIME == 1 /* Python and Informix both have a datetime.h, the Informix header is *************** *** 203,206 **** --- 212,300 ---- } while(0) + #ifdef HAVE_SBLOB + /************************* Smart Blobs *************************/ + typedef struct Sblob_t + { + PyObject_HEAD + struct Connection_t *conn; + int sblob_type; + ifx_lo_create_spec_t *lo_spec; + ifx_lo_t lo; + mint lofd; + } Sblob; + + static int Sblob_init(Sblob *self, PyObject *args, PyObject *kwargs); + static void Sblob_dealloc(Sblob *self); + static PyObject *Sblob_close(Sblob *self); + static PyObject *Sblob_open(Sblob *self, PyObject *args, PyObject *kwargs); + static PyObject *Sblob_read(Sblob *self, PyObject *args, PyObject *kwargs); + static PyObject *Sblob_write(Sblob *self, PyObject *args, PyObject *kwargs); + static PyObject *Sblob_seek(Sblob *self, PyObject *args, PyObject *kwargs); + static PyObject *Sblob_tell(Sblob *self); + static PyObject *Sblob_stat(Sblob *self); + + static PyMethodDef Sblob_methods[] = { + { "close", (PyCFunction)Sblob_close, METH_NOARGS }, + { "open", (PyCFunction)Sblob_open, METH_VARARGS|METH_KEYWORDS }, + { "read", (PyCFunction)Sblob_read, METH_VARARGS|METH_KEYWORDS }, + { "write", (PyCFunction)Sblob_write, METH_VARARGS|METH_KEYWORDS }, + { "seek", (PyCFunction)Sblob_seek, METH_VARARGS|METH_KEYWORDS }, + { "tell", (PyCFunction)Sblob_tell, METH_NOARGS }, + { "stat", (PyCFunction)Sblob_stat, METH_NOARGS }, + { NULL } + }; + + static PyMemberDef Sblob_members[] = { + { NULL } + }; + + static PyGetSetDef Sblob_properties[] = { + { NULL } + }; + + static PyTypeObject Sblob_type = { + PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) + 0, /* ob_size*/ + "_informixdb.Sblob", /* tp_name */ + sizeof(Sblob), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)Sblob_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* 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 */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + "", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + Sblob_methods, /* tp_methods */ + Sblob_members, /* tp_members */ + Sblob_properties, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Sblob_init, /* tp_init */ + PyType_GenericAlloc, /* tp_alloc */ + PyType_GenericNew, /* tp_new */ + _PyObject_Del /* tp_free */ + }; + #endif + /************************* Cursors *************************/ *************** *** 218,221 **** --- 312,316 ---- struct sqlda *daOut; int *originalType; + int4 *originalXid; char *outputBuffer; short *indIn; *************** *** 467,470 **** --- 562,568 ---- static PyObject *Connection_rollback(Connection *self); static PyObject *Connection_close(Connection *self); + #ifdef HAVE_SBLOB + static PyObject *Connection_Sblob(Connection *self, PyObject *args, PyObject *kwds); + #endif PyDoc_STRVAR(Connection_cursor_doc, *************** *** 513,516 **** --- 611,618 ---- { "close", (PyCFunction)Connection_close, METH_NOARGS, Connection_close_doc }, + #ifdef HAVE_SBLOB + { "Sblob", (PyCFunction)Connection_Sblob, METH_VARARGS|METH_KEYWORDS, + "" }, + #endif { NULL } }; *************** *** 853,857 **** } - static int ibindBinary(struct sqlvar_struct *var, PyObject *item) { --- 955,958 ---- *************** *** 1007,1010 **** --- 1108,1128 ---- } + #ifdef HAVE_SBLOB + static int ibindSblob(struct sqlvar_struct *var, PyObject *item) + { + Sblob *sblob = (Sblob*)item; + ifx_lo_t *data = malloc(sizeof(ifx_lo_t)); + memcpy(data, &(sblob->lo), sizeof(ifx_lo_t)); + var->sqltype = SQLUDTFIXED; + if (sblob->sblob_type==SBLOB_TYPE_CLOB) + var->sqlxid = XID_CLOB; + else + var->sqlxid = XID_BLOB; + var->sqldata = (void*)data; + var->sqllen = sizeof(ifx_lo_t); + *var->sqlind = 0; + } + #endif + static int ibindNone(struct sqlvar_struct *var, PyObject *item) { *************** *** 1020,1023 **** --- 1138,1146 ---- static ibindFptr ibindFcn(PyObject* item) { + #ifdef HAVE_SBLOB + if (PyObject_IsInstance(item, (PyObject*)&Sblob_type)) { + return ibindSblob; + } else + #endif if (PyObject_IsInstance(item, IntervalY2MType) || PyObject_IsInstance(item, IntervalD2FType)) { *************** *** 1126,1129 **** --- 1249,1253 ---- cur->indOut = calloc(cur->daOut->sqld, sizeof(short)); cur->originalType = calloc(cur->daOut->sqld, sizeof(int)); + cur->originalXid = calloc(cur->daOut->sqld, sizeof(int4)); Py_DECREF(cur->description); *************** *** 1143,1146 **** --- 1267,1271 ---- var->sqlind = &cur->indOut[pos]; cur->originalType[pos] = var->sqltype; + cur->originalXid[pos] = var->sqlxid; switch(var->sqltype & SQLTYPE){ *************** *** 1186,1200 **** break; default: #ifdef CLVCHARPTRTYPE ! if (ISCOMPLEXTYPE(var->sqltype) || ISUDTTYPE(var->sqltype)) ! var->sqltype = CLVCHARPTRTYPE; ! else #endif ! var->sqltype = CCHARTYPE; break; } var->sqllen = rtypmsize(var->sqltype, var->sqllen); count = rtypalign(count, var->sqltype) + var->sqllen; } --- 1311,1336 ---- break; default: + #ifdef HAVE_SBLOB + if (ISSMARTBLOB(var->sqltype, var->sqlxid)) + ; /* do nothing */ + else + #endif #ifdef CLVCHARPTRTYPE ! if (ISCOMPLEXTYPE(var->sqltype) || ISUDTTYPE(var->sqltype)) ! var->sqltype = CLVCHARPTRTYPE; ! else #endif ! var->sqltype = CCHARTYPE; break; } + #ifdef HAVE_SBLOB + if (!ISSMARTBLOB(var->sqltype, var->sqlxid)) { + #endif var->sqllen = rtypmsize(var->sqltype, var->sqllen); count = rtypalign(count, var->sqltype) + var->sqllen; + #ifdef HAVE_SBLOB + } + #endif } *************** *** 1206,1209 **** --- 1342,1351 ---- bufp = (char *) rtypalign( (int) bufp, var->sqltype); + #ifdef HAVE_SBLOB + if (ISSMARTBLOB(var->sqltype, var->sqlxid)) { + var->sqldata = malloc(sizeof(ifx_lo_t)); + } + else + #endif if (var->sqltype == CLOCATORTYPE) { loc_t *loc = (loc_t*) bufp; *************** *** 1503,1507 **** } ! static PyObject *doCopy(/* const */ void *data, int type) { switch(type){ --- 1645,1650 ---- } ! static PyObject *doCopy(/* const */ void *data, int type, int4 xid, ! struct Connection_t *conn) { switch(type){ *************** *** 1672,1675 **** --- 1815,1831 ---- } /* case SQLTEXT */ } /* switch */ + #ifdef HAVE_SBLOB + if (ISSMARTBLOB(type,xid)) { + Sblob *new_sblob; + new_sblob = (Sblob*)PyObject_CallObject((PyObject*)&Sblob_type, + Py_BuildValue("(Oi)", conn, 0) ); + memcpy(&new_sblob->lo, data, sizeof(ifx_lo_t)); + if (xid==XID_CLOB) + new_sblob->sblob_type = SBLOB_TYPE_CLOB; + else + new_sblob->sblob_type = SBLOB_TYPE_BLOB; + return (PyObject*)new_sblob; + } else + #endif #ifdef CLVCHARPTRTYPE if (ISCOMPLEXTYPE(type)||ISUDTTYPE(type)) { *************** *** 1716,1720 **** Py_INCREF(v); } else { ! v = doCopy(var->sqldata, cur->originalType[pos]); } --- 1872,1877 ---- Py_INCREF(v); } else { ! v = doCopy(var->sqldata, cur->originalType[pos], cur->originalXid[pos], ! cur->conn); } *************** *** 1749,1752 **** --- 1906,1933 ---- } + #ifdef HAVE_SBLOB + static PyObject *Connection_Sblob(Connection *self, PyObject *args, PyObject *kwds) + { + PyObject *a, *slob; + int i; + + require_open(self); + + a = PyTuple_New(PyTuple_Size(args) + 2); + Py_INCREF(self); + PyTuple_SET_ITEM(a, 0, (PyObject*)self); + PyTuple_SET_ITEM(a, 1, PyInt_FromLong(1)); + for (i = 0; i < PyTuple_Size(args); ++i) { + PyObject *o = PyTuple_GetItem(args, i); + Py_INCREF(o); + PyTuple_SET_ITEM(a, i+2, o); + } + + slob = PyObject_Call((PyObject*)&Sblob_type, a, kwds); + Py_DECREF(a); + return slob; + } + #endif + static void cleanInputBinding(Cursor *cur) { *************** *** 1804,1807 **** --- 1985,1993 ---- free(loc->loc_buffer); } + #ifdef HAVE_SBLOB + if (ISSMARTBLOB(da->sqlvar[i].sqltype,da->sqlvar[i].sqlxid)) { + free(da->sqlvar[i].sqldata); + } + #endif free(cur->daOut); cur->daOut = 0; *************** *** 1815,1818 **** --- 2001,2008 ---- cur->originalType = 0; } + if (cur->originalXid) { + free(cur->originalXid); + cur->originalXid = 0; + } if (cur->outputBuffer) { free(cur->outputBuffer); *************** *** 1919,1922 **** --- 2109,2113 ---- self->daOut = 0; self->originalType = 0; + self->originalXid = 0; self->outputBuffer = 0; self->indIn = 0; *************** *** 2658,2661 **** --- 2849,3100 ---- }; + #ifdef HAVE_SBLOB + static int Sblob_init(Sblob *self, PyObject *args, PyObject* kwargs) + { + struct Connection_t *conn; + int do_create = 0; + mint create_flags = 0; + mint open_flags = LO_RDWR; + int sblob_type = 0; + static char* kwdlist[] = { + "connection", "do_create", "type", "create_flags", "open_flags", 0 + }; + mint result, err; + + if (!PyArg_ParseTupleAndKeywords( + args, kwargs, "O!i|iii", kwdlist, &Connection_type, &conn, + &do_create, &sblob_type, &create_flags, &open_flags)) + return -1; + + self->conn = conn; + Py_INCREF(conn); + + self->lofd = 0; + self->lo_spec = NULL; + self->sblob_type = sblob_type; + if (do_create) { + if (setConnection(self->conn)) return -1; + result = ifx_lo_def_create_spec(&self->lo_spec); + if (result<0) { + is_dberror(self->conn, NULL, "ifx_lo_def_create_spec"); + return -1; + } + result = ifx_lo_specset_flags(self->lo_spec, create_flags); + if (result<0) { + is_dberror(self->conn, NULL, "ifx_lo_specset_flags"); + return -1; + } + result = ifx_lo_create(self->lo_spec, open_flags, &self->lo, &err); + if (result<0) { + is_dberror(self->conn, NULL, "ifx_lo_create"); + return -1; + } + self->lofd = result; + } + return 0; + } + + static void Sblob_dealloc(Sblob *self) + { + if (self->lofd) { + ifx_lo_close(self->lofd); + self->lofd = 0; + } + ifx_lo_release(&self->lo); + if (self->lo_spec) { + ifx_lo_spec_free(self->lo_spec); + self->lo_spec = NULL; + } + self->ob_type->tp_free((PyObject*)self); + } + + static PyObject *Sblob_close(Sblob *self) { + if (self->lofd) { + ifx_lo_close(self->lofd); + self->lofd = 0; + } + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject *Sblob_open(Sblob *self, PyObject *args, PyObject *kwargs) + { + mint flags = 0; + static char* kwdlist[] = { "flags", 0 }; + mint result, err; + + if (self->lofd) { + if (error_handle(self->conn, NULL, ExcInterfaceError, + PyString_FromString("Sblob is already open"))) + return NULL; + } + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwdlist, &flags)) + return NULL; + result = ifx_lo_open(&self->lo, flags, &err); + if (result<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_open"); + } + self->lofd = result; + Py_INCREF(Py_None); + return Py_None; + } + + static PyObject *Sblob_read(Sblob *self, PyObject *args, PyObject *kwargs) + { + static char* kwdlist[] = { "nbytes", 0 }; + mint result, err; + char *buf; + PyObject *py_result; + mint buflen; + if (!self->lofd) { + if (error_handle(self->conn, NULL, ExcInterfaceError, + PyString_FromString("Sblob is not open"))) + return NULL; + } + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwdlist, &buflen)) + return NULL; + buf = PyMem_Malloc(buflen); + if (!buf) { + return PyErr_NoMemory(); + } + result = ifx_lo_read(self->lofd, buf, buflen, &err); + if (result<0) { + PyMem_Free(buf); + ret_on_dberror(self->conn, NULL, "ifx_lo_read"); + } + py_result = PyString_FromStringAndSize(buf, result); + PyMem_Free(buf); + return py_result; + } + + static PyObject *Sblob_write(Sblob *self, PyObject *args, PyObject *kwargs) + { + static char* kwdlist[] = { "buf", 0 }; + mint result, err; + char *buf; + mint buflen; + if (!self->lofd) { + if (error_handle(self->conn, NULL, ExcInterfaceError, + PyString_FromString("Sblob is not open"))) + return NULL; + } + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#", kwdlist, &buf, &buflen)) + return NULL; + result = ifx_lo_write(self->lofd, buf, buflen, &err); + if (result<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_write"); + } + return PyInt_FromLong((long)result); + } + + static PyObject *Sblob_seek(Sblob *self, PyObject *args, PyObject *kwargs) + { + static char* kwdlist[] = { "offset", "whence", 0 }; + mint result, err; + PyObject *py_offset; + PyObject *sitem; + char *val, pos_str[30]; + mint whence; + ifx_int8_t offset, seek_pos; + + if (!self->lofd) { + if (error_handle(self->conn, NULL, ExcInterfaceError, + PyString_FromString("Sblob is not open"))) + return NULL; + } + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi", kwdlist, + &py_offset, &whence)) + return NULL; + + sitem = PyObject_Str(py_offset); + val = PyString_AS_STRING((PyStringObject*)sitem); + result = ifx_int8cvasc(val, strlen(val), &offset); + Py_DECREF(sitem); + if (result<0) { + ret_on_dberror(self->conn, NULL, "ifx_int8cvasc"); + } + if (ifx_lo_seek(self->lofd, &offset, whence, &seek_pos)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_seek"); + } + if (ifx_int8toasc(&seek_pos, pos_str, 29)<0) { + ret_on_dberror(self->conn, NULL, "ifx_int8toasc"); + } + pos_str[29] = 0; + return PyLong_FromString(pos_str, NULL, 10); + } + + static PyObject *Sblob_tell(Sblob *self) + { + ifx_int8_t seek_pos; + char pos_str[30]; + + if (!self->lofd) { + if (error_handle(self->conn, NULL, ExcInterfaceError, + PyString_FromString("Sblob is not open"))) + return NULL; + } + if (ifx_lo_tell(self->lofd, &seek_pos)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_tell"); + } + if (ifx_int8toasc(&seek_pos, pos_str, 29)<0) { + ret_on_dberror(self->conn, NULL, "ifx_int8toasc"); + } + pos_str[29] = 0; + return PyLong_FromString(pos_str, NULL, 10); + } + + static PyObject *Sblob_stat(Sblob *self) + { + ifx_lo_stat_t *lo_stat; + mint result; + ifx_int8_t stat_size; + char size_str[30]; + PyObject *size_result; + mint atime, ctime, mtime, refcnt; + PyObject *atime_result, *ctime_result, *mtime_result; + + if (!self->lofd) { + if (error_handle(self->conn, NULL, ExcInterfaceError, + PyString_FromString("Sblob is not open"))) + return NULL; + } + if (ifx_lo_stat(self->lofd, &lo_stat)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_stat"); + } + if (ifx_lo_stat_size(lo_stat, &stat_size)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_stat_size"); + } + if ((atime=ifx_lo_stat_atime(lo_stat))<0) { + atime_result = Py_None; Py_INCREF(Py_None); + } else { + atime_result = db_TimestampFromTicks(NULL,Py_BuildValue("(i)",atime)); + } + if ((ctime=ifx_lo_stat_ctime(lo_stat))<0) { + ctime_result = Py_None; Py_INCREF(Py_None); + } else { + ctime_result = db_TimestampFromTicks(NULL,Py_BuildValue("(i)",ctime)); + } + if ((mtime=ifx_lo_stat_mtime_sec(lo_stat))<0) { + mtime_result = Py_None; Py_INCREF(Py_None); + } else { + mtime_result = db_TimestampFromTicks(NULL,Py_BuildValue("(i)",mtime)); + } + if ((refcnt=ifx_lo_stat_refcnt(lo_stat))<0) { + refcnt = 0; + } + if (ifx_lo_stat_free(lo_stat)<0) { + ret_on_dberror(self->conn, NULL, "ifx_lo_stat_free"); + } + if (ifx_int8toasc(&stat_size, size_str, 29)<0) { + ret_on_dberror(self->conn, NULL, "ifx_int8toasc"); + } + size_str[29] = 0; + size_result = PyLong_FromString(size_str, NULL, 10); + return Py_BuildValue("{sNsNsNsNsi}", "size", size_result, + "atime", atime_result, "ctime", ctime_result, + "mtime", mtime_result, "refcnt", refcnt); + } + #endif + PyDoc_STRVAR(_informixdb_doc, "DB-API 2.0 compliant interface for Informix databases.\n"); *************** *** 2720,2723 **** --- 3159,3168 ---- PyType_Ready(&DBAPIType_type); + #ifdef HAVE_SBLOB + Sblob_type.ob_type = &PyType_Type; + PyType_Ready(&Sblob_type); + Py_INCREF(&Sblob_type); + #endif + #ifdef IFX_THREAD threadsafety = 1; *************** *** 2738,2741 **** --- 3183,3217 ---- PyModule_AddIntConstant(m, "ROW_AS_DICT", CURSOR_ROWFORMAT_DICT); + #ifdef HAVE_SBLOB + #define ExposeIntConstant(x) PyModule_AddIntConstant(m, #x, x) + ExposeIntConstant(SBLOB_TYPE_BLOB); + ExposeIntConstant(SBLOB_TYPE_CLOB); + ExposeIntConstant(LO_OPEN_APPEND); + ExposeIntConstant(LO_OPEN_WRONLY); + ExposeIntConstant(LO_OPEN_RDONLY); + ExposeIntConstant(LO_OPEN_RDWR); + ExposeIntConstant(LO_OPEN_DIRTY_READ); + ExposeIntConstant(LO_OPEN_RANDOM); + ExposeIntConstant(LO_OPEN_SEQUENTIAL); + ExposeIntConstant(LO_OPEN_FORWARD); + ExposeIntConstant(LO_OPEN_REVERSE); + ExposeIntConstant(LO_OPEN_BUFFER); + ExposeIntConstant(LO_OPEN_NOBUFFER); + ExposeIntConstant(LO_OPEN_NODIRTY_READ); + ExposeIntConstant(LO_OPEN_LOCKALL); + ExposeIntConstant(LO_OPEN_LOCKRANGE); + ExposeIntConstant(LO_ATTR_LOG); + ExposeIntConstant(LO_ATTR_NOLOG); + ExposeIntConstant(LO_ATTR_DELAY_LOG); + ExposeIntConstant(LO_ATTR_KEEP_LASTACCESS_TIME); + ExposeIntConstant(LO_ATTR_NOKEEP_LASTACCESS_TIME); + ExposeIntConstant(LO_ATTR_HIGH_INTEG); + ExposeIntConstant(LO_ATTR_MODERATE_INTEG); + ExposeIntConstant(LO_ATTR_TEMP); + ExposeIntConstant(LO_SEEK_SET); + ExposeIntConstant(LO_SEEK_CUR); + ExposeIntConstant(LO_SEEK_END); + #endif + Py_INCREF(&Connection_type); PyModule_AddObject(m, "Connection", (PyObject*)&Connection_type); |
From: Daniel S. <da...@us...> - 2005-11-09 07:58:55
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23497/ext Modified Files: _informixdb.ec Log Message: Allow Informix to handle SIGCHLD, otherwise when using a connection method which uses pipes (e.g. sqlexec) child processes become defunct and the process might run out of file handles & other ugly stuff may happen. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** _informixdb.ec 9 Nov 2005 07:56:14 -0000 1.27 --- _informixdb.ec 9 Nov 2005 07:58:47 -0000 1.28 *************** *** 2754,2756 **** --- 2754,2761 ---- PyDateTime_IMPORT; + + /* when using a connection mode with forking (i.e. Informix SE) + child processes might stay around as <defunct> unless SIGCHLD + is handled */ + sqlsignal(-1, (void*)NULL, 0); } |
From: Daniel S. <da...@us...> - 2005-11-09 07:56:22
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23130/ext Modified Files: _informixdb.ec Log Message: Made module compileable under AIX and/or older Informix versions again Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** _informixdb.ec 30 Oct 2005 15:47:45 -0000 1.26 --- _informixdb.ec 9 Nov 2005 07:56:14 -0000 1.27 *************** *** 939,942 **** --- 939,945 ---- static int ibindString(struct sqlvar_struct *var, PyObject *item) { + PyObject *sitem; + const char *val; + int n; #if HAVE_PY_BOOL == 1 if (PyBool_Check(item)) { *************** *** 944,958 **** } #endif ! PyObject *sitem = PyObject_Str(item); ! const char *val = PyString_AS_STRING((PyStringObject*)sitem); ! int n = strlen(val); ! if (n<32768) { ! var->sqltype = CSTRINGTYPE; ! var->sqldata = malloc(n+1); ! var->sqllen = n+1; ! *var->sqlind = 0; ! memcpy(var->sqldata, val, n+1); ! } ! else { /* use lvarchar* instead */ EXEC SQL BEGIN DECLARE SECTION; --- 947,955 ---- } #endif ! sitem = PyObject_Str(item); ! val = PyString_AS_STRING((PyStringObject*)sitem); ! n = strlen(val); ! EXEC SQL ifdef SQLLVARCHAR; ! if (n >= 32768) { /* use lvarchar* instead */ EXEC SQL BEGIN DECLARE SECTION; *************** *** 972,975 **** --- 969,981 ---- free( data ); } + else + EXEC SQL endif; + { + var->sqltype = CSTRINGTYPE; + var->sqldata = malloc(n+1); + var->sqllen = n+1; + *var->sqlind = 0; + memcpy(var->sqldata, val, n+1); + } Py_DECREF(sitem); return 1; *************** *** 1166,1169 **** --- 1172,1176 ---- var->sqltype = CLONGTYPE; break; + #ifdef SQLINT8 case SQLINT8: case SQLSERIAL8: *************** *** 1171,1174 **** --- 1178,1182 ---- var->sqllen = 20; break; + #endif case SQLDTIME: var->sqltype = CDTIMETYPE; *************** *** 1178,1184 **** --- 1186,1194 ---- break; default: + #ifdef CLVCHARPTRTYPE if (ISCOMPLEXTYPE(var->sqltype) || ISUDTTYPE(var->sqltype)) var->sqltype = CLVCHARPTRTYPE; else + #endif var->sqltype = CCHARTYPE; break; *************** *** 1203,1206 **** --- 1213,1217 ---- loc->loc_mflags = 0; } + EXEC SQL ifdef SQLLVARCHAR; else if (var->sqltype == CLVCHARPTRTYPE ) { *************** *** 1217,1220 **** --- 1228,1232 ---- var->sqllen = sizeof(void *); } + EXEC SQL endif; else { var->sqldata = bufp; *************** *** 1635,1641 **** --- 1647,1655 ---- case SQLSERIAL: return PyInt_FromLong(*(long*)data); + #ifdef SQLINT8 case SQLINT8: case SQLSERIAL8: return PyLong_FromString((char *)data, NULL, 10); + #endif case SQLBYTES: case SQLTEXT: *************** *** 1658,1661 **** --- 1672,1676 ---- } /* case SQLTEXT */ } /* switch */ + #ifdef CLVCHARPTRTYPE if (ISCOMPLEXTYPE(type)||ISUDTTYPE(type)) { PyObject *buffer; *************** *** 1676,1679 **** --- 1691,1695 ---- return buffer; } + #endif Py_INCREF(Py_None); return Py_None; *************** *** 1747,1753 **** --- 1763,1771 ---- } } + #ifdef SQLUDTVAR if (da->sqlvar[i].sqltype == SQLUDTVAR) { ifx_var_dealloc((void**)&(da->sqlvar[i].sqldata)); } + #endif free(da->sqlvar[i].sqldata); } |
From: Carsten H. <ch...@us...> - 2005-10-31 18:09:00
|
Update of /cvsroot/informixdb/informixdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21316 Modified Files: informixdb.py Log Message: Month arithmetic did dumb things if the result landed in December. Fixed. Index: informixdb.py =================================================================== RCS file: /cvsroot/informixdb/informixdb/informixdb.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** informixdb.py 29 Oct 2005 17:25:20 -0000 1.10 --- informixdb.py 31 Oct 2005 18:08:51 -0000 1.11 *************** *** 70,76 **** otherdate = datetime.date(y,m,d) # shift the date by the desired number of months ! y2,m2 = divmod(m+self._months,12) try: ! date2 = datetime.date(y+y2,m2,d) except ValueError: raise ValueError, "month arithmetic yielded an invalid date." --- 70,76 ---- otherdate = datetime.date(y,m,d) # shift the date by the desired number of months ! y2,m2 = divmod(m-1+self._months,12) try: ! date2 = datetime.date(y+y2,m2+1,d) except ValueError: raise ValueError, "month arithmetic yielded an invalid date." |
From: Carsten H. <ch...@us...> - 2005-10-30 15:48:00
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18509/ext Modified Files: _informixdb.ec Log Message: correct the order of parameters for calling a custom errorhandler Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** _informixdb.ec 29 Oct 2005 17:25:21 -0000 1.25 --- _informixdb.ec 30 Oct 2005 15:47:45 -0000 1.26 *************** *** 2371,2376 **** PyObject *args, *hret; ! args = Py_BuildValue("(ONOO)", type, value, (PyObject*)connection, ! cursor ? (PyObject*)cursor : Py_None); hret = PyObject_Call(handler, args, NULL); Py_DECREF(args); --- 2371,2376 ---- PyObject *args, *hret; ! args = Py_BuildValue("(OOON)", (PyObject*)connection, ! cursor ? (PyObject*)cursor : Py_None, type, value); hret = PyObject_Call(handler, args, NULL); Py_DECREF(args); |
From: Carsten H. <ch...@us...> - 2005-10-29 17:25:28
|
Update of /cvsroot/informixdb/informixdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31142 Modified Files: informixdb.py Log Message: add support for Interval types Index: informixdb.py =================================================================== RCS file: /cvsroot/informixdb/informixdb/informixdb.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** informixdb.py 20 Oct 2005 02:52:09 -0000 1.9 --- informixdb.py 29 Oct 2005 17:25:20 -0000 1.10 *************** *** 47,50 **** --- 47,123 ---- """ + class IntervalYearToMonth(object): + def __init__(self, years=0, months=0): + self._months = 12*years+months + self.years, self.months = divmod(self._months,12) + def __repr__(self): + return "%s(%d, %d)"%(self.__class__.__name__,self.years,self.months) + # str() returns the Interval in Informix's format + def __str__(self): + if self._months < 0: + return "-%d-%02d" % divmod(-self._months,12) + else: + return "%d-%02d" % divmod(self._months,12) + # arithmetic operations: analogous to timedelta. Supports adding to + # and subtracting from dates, datetimes, and other IntervalYearToMonths, + # as well as multiplying with and dividing by scalar factors. + def __add__(self, other): + if isinstance(other, IntervalYearToMonth): + return self.__class__(0, int(self._months+other._months)) + elif isinstance(other, (datetime.datetime, datetime.date)): + # extract the date from the other operand + y,m,d = other.timetuple()[0:3] + otherdate = datetime.date(y,m,d) + # shift the date by the desired number of months + y2,m2 = divmod(m+self._months,12) + try: + date2 = datetime.date(y+y2,m2,d) + except ValueError: + raise ValueError, "month arithmetic yielded an invalid date." + # apply the resulting timedelta to the operand + return other + (date2 - otherdate) + else: return NotImplemented + def __neg__(self): return self.__class__(0, -self._months) + def __sub__(self, other): return self + -other + def __rsub__(self, other): return -self + other + def __abs__(self): + if self._months < 0: return -self + else: return self + def __mul__(self, other): + if isinstance(other, (int,long,float)): + return self.__class__(0, int(self._months*other)) + else: return NotImplemented + def __div__(self, other): + if isinstance(other, (int,long,float)): + return self.__class__(0, int(self._months/other)) + else: return NotImplemented + __radd__ = __add__ + __rmul__ = __mul__ + __floordiv__ = __div__ + # implement comparison to other IntervalYearToMonths + def __cmp__(self, other): + if isinstance(other, IntervalYearToMonth): + return self._months - other._months + else: return NotImplemented + + # Define IntervalDayToFraction for symmetry. All the heavy lifting is done + # by datetime.timedelta, from which this class is derived. + import datetime + class IntervalDayToFraction(datetime.timedelta): + def __init__(self,days=0,seconds=0,microseconds=0): + datetime.timedelta.__init__(self, days, seconds, microseconds) + # str() returns the Interval in Informix's format + def __str__(self): + if self.days<0: + neg = IntervalDayToFraction(-self.days, -self.seconds, -self.microseconds) + return '-'+str(neg) + else: + minutes, seconds = divmod(self.seconds, 60) + hours, minutes = divmod(minutes, 60) + return "%d %02d:%02d:%02d.%05d" % (self.days, hours,minutes,seconds, + self.microseconds/10) + + # The module initialization of _informixdb references the Interval classes + # above, so don't put this import before the interval class definitions. from _informixdb import * |
From: Carsten H. <ch...@us...> - 2005-10-29 17:25:28
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31142/ext Modified Files: _informixdb.ec Log Message: add support for Interval types Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** _informixdb.ec 28 Oct 2005 00:14:48 -0000 1.24 --- _informixdb.ec 29 Oct 2005 17:25:21 -0000 1.25 *************** *** 100,103 **** --- 100,106 ---- static PyObject *ExcNotSupportedError; + static PyObject *IntervalY2MType; + static PyObject *IntervalD2FType; + PyDoc_STRVAR(ExcWarning_doc, "Exception class for SQL warnings.\n\n\ *************** *** 973,976 **** --- 976,1004 ---- } + static int ibindInterval(struct sqlvar_struct *var, PyObject *item) + { + PyObject *sitem = PyObject_Str(item); + const char *val = PyString_AS_STRING((PyStringObject*)sitem); + intrvl_t *inv = (intrvl_t*)malloc(sizeof(intrvl_t)); + int ret; + + if (PyObject_IsInstance(item, IntervalY2MType)) + inv->in_qual = TU_IENCODE(9,TU_YEAR,TU_MONTH); + else + inv->in_qual = TU_IENCODE(9,TU_DAY,TU_F5); + + if ((ret = incvasc((char *)val, inv)) != 0) { + PyErr_Format(ExcInterfaceError, + "Failed to parse interval value %s. incvasc returned %d", val, ret); + return 0; + } + + var->sqldata = (void*)inv; + var->sqllen = sizeof(intrvl_t); + var->sqltype = CINVTYPE; + *var->sqlind = 0; + return 1; + } + static int ibindNone(struct sqlvar_struct *var, PyObject *item) { *************** *** 986,990 **** static ibindFptr ibindFcn(PyObject* item) { ! if (PyBuffer_Check(item)) { return ibindBinary; } else if (PyDateTime_Check(item)) { --- 1014,1021 ---- static ibindFptr ibindFcn(PyObject* item) { ! if (PyObject_IsInstance(item, IntervalY2MType) || ! PyObject_IsInstance(item, IntervalD2FType)) { ! return ibindInterval; ! } else if (PyBuffer_Check(item)) { return ibindBinary; } else if (PyDateTime_Check(item)) { *************** *** 1143,1146 **** --- 1174,1180 ---- var->sqltype = CDTIMETYPE; break; + case SQLINTERVAL: + var->sqltype = CINVTYPE; + break; default: if (ISCOMPLEXTYPE(var->sqltype) || ISUDTTYPE(var->sqltype)) *************** *** 1188,1192 **** } ! if (var->sqltype == CDTIMETYPE) { /* let the database set the correct datetime format */ var->sqllen = 0; --- 1222,1226 ---- } ! if (var->sqltype == CDTIMETYPE || var->sqltype == CINVTYPE) { /* let the database set the correct datetime format */ var->sqllen = 0; *************** *** 1506,1509 **** --- 1540,1608 ---- hour, minute, second, usec); } + case SQLINTERVAL: + { + /* Informix stores an interval as a decimal number, which in turn is + stored as a sequence of base 100 "digits." Since the starting unit + may span several base-100 digits, I extend the given interval to + the full length of its interval class, so that the starting unit, + is either the year or the day. This leads to the two following cases: + + Year(9) to Month + decimal digits: 0YYYYYYYYYMM00000000.00000 + base-100 position: 10_9_8_7_6_5_4_3_2_1 _0-1-2 + + Day(9) to Fraction(5) + decimal digits: 0DDDDDDDDDHHMMSS.FFFFF + base-100 position: _8_7_6_5_4_3_2_1 _0-1-2 + */ + int i, pos, d, sign=0; + int year=0,month=0,day=0,hour=0,minute=0,second=0,usec=0; + intrvl_t* inv = (intrvl_t*)data; + sign = (inv->in_dec.dec_pos==0)?-1:1; + if (TU_START(inv->in_qual) <= TU_MONTH) { + exec sql begin declare section; + interval year(9) to month inv_extended; + exec sql end declare section; + invextend(inv, &inv_extended); + inv = &inv_extended; + pos = inv->in_dec.dec_exp; + for (i=0; i<inv->in_dec.dec_ndgts; i++) { + d = inv->in_dec.dec_dgts[i]; + switch(pos) { + case 10: case 9: case 8: case 7: case 6: + year = 100*year + d; break; + case 5: month = d; break; + } + pos--; + } + return PyObject_CallObject(IntervalY2MType, + Py_BuildValue("(ii)",sign*year,sign*month) ); + } + else { + exec sql begin declare section; + interval day(9) to fraction(5) inv_extended; + exec sql end declare section; + invextend(inv, &inv_extended); + inv = &inv_extended; + pos = inv->in_dec.dec_exp; + for (i=0; i<inv->in_dec.dec_ndgts; i++) { + d = inv->in_dec.dec_dgts[i]; + switch(pos) { + case 8: case 7: case 6: case 5: case 4: + day = 100*day + d; break; + case 3: hour = d; break; + case 2: minute = d; break; + case 1: second = d; break; + case 0: usec += 10000*d; break; + case -1: usec += 100*d; break; + case -2: usec += d; break; + } + pos--; + } + return PyObject_CallObject(IntervalD2FType, + Py_BuildValue("(iii)", sign*day, + sign*(3600*hour+60*minute+second), sign*usec) ); + } + } case SQLCHAR: case SQLVCHAR: *************** *** 2558,2561 **** --- 2657,2662 ---- PyObject *m = Py_InitModule3("_informixdb", globalMethods, _informixdb_doc); + PyObject *informixdbmodule; + PyObject *informixdbmdict; #define defException(name, base) \ *************** *** 2624,2627 **** --- 2725,2738 ---- PyModule_AddObject(m, "Cursor", (PyObject*)&Cursor_type); + /* obtain the type objects for the Interval classes */ + informixdbmodule = PyImport_ImportModule("informixdb"); + informixdbmdict = PyModule_GetDict(informixdbmodule); + IntervalY2MType = PyDict_GetItemString( + informixdbmdict, "IntervalYearToMonth"); + IntervalD2FType = PyDict_GetItemString( + informixdbmdict, "IntervalDayToFraction"); + Py_INCREF(IntervalY2MType); + Py_INCREF(IntervalD2FType); + PyDateTime_IMPORT; } |
From: Carsten H. <ch...@us...> - 2005-10-28 00:15:01
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22167/ext Modified Files: _informixdb.ec Log Message: add INT8 and SERIAL8 support Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** _informixdb.ec 27 Oct 2005 15:22:21 -0000 1.23 --- _informixdb.ec 28 Oct 2005 00:14:48 -0000 1.24 *************** *** 1135,1138 **** --- 1135,1143 ---- var->sqltype = CLONGTYPE; break; + case SQLINT8: + case SQLSERIAL8: + var->sqltype = CCHARTYPE; + var->sqllen = 20; + break; case SQLDTIME: var->sqltype = CDTIMETYPE; *************** *** 1531,1534 **** --- 1536,1542 ---- case SQLSERIAL: return PyInt_FromLong(*(long*)data); + case SQLINT8: + case SQLSERIAL8: + return PyLong_FromString((char *)data, NULL, 10); case SQLBYTES: case SQLTEXT: *************** *** 2544,2551 **** "nvarchar", "lvarchar", NULL }; static char* dbtp_binary[] = { "byte", "text", NULL }; ! static char* dbtp_number[] = { "smallint", "integer", "float", "smallfloat", "decimal", "money", NULL }; static char* dbtp_datetime[] = { "date", "datetime", NULL }; ! static char* dbtp_rowid[] = { "serial", NULL }; PyObject *m = Py_InitModule3("_informixdb", globalMethods, _informixdb_doc); --- 2552,2559 ---- "nvarchar", "lvarchar", NULL }; static char* dbtp_binary[] = { "byte", "text", NULL }; ! static char* dbtp_number[] = { "smallint", "integer", "int8", "float", "smallfloat", "decimal", "money", NULL }; static char* dbtp_datetime[] = { "date", "datetime", NULL }; ! static char* dbtp_rowid[] = { "serial", "serial8", NULL }; PyObject *m = Py_InitModule3("_informixdb", globalMethods, _informixdb_doc); |
From: Carsten H. <ch...@us...> - 2005-10-27 15:22:35
|
Update of /cvsroot/informixdb/informixdb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19650 Modified Files: setup.py Log Message: restore compatibility with Python 2.2 Index: setup.py =================================================================== RCS file: /cvsroot/informixdb/informixdb/setup.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** setup.py 19 Oct 2005 04:20:53 -0000 1.7 --- setup.py 27 Oct 2005 15:22:20 -0000 1.8 *************** *** 149,154 **** return 0 extra_macros = [('PYTHON_INCLUDE', get_python_inc(plat_specific=1)), ! ('HAVE_C_DATETIME', have_c_datetime())] modules = [ 'informixdb' ] --- 149,163 ---- return 0 + def have_py_bool(): + if sys.version_info[0] > 2: + return 1 + elif sys.version_info[0] == 2 and sys.version_info[1] >= 3: + return 1 + else: + return 0 + extra_macros = [('PYTHON_INCLUDE', get_python_inc(plat_specific=1)), ! ('HAVE_C_DATETIME', have_c_datetime()), ! ('HAVE_PY_BOOL', have_py_bool()) ] modules = [ 'informixdb' ] |
From: Carsten H. <ch...@us...> - 2005-10-27 15:22:35
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19650/ext Modified Files: _informixdb.ec Log Message: restore compatibility with Python 2.2 Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** _informixdb.ec 27 Oct 2005 15:10:18 -0000 1.22 --- _informixdb.ec 27 Oct 2005 15:22:21 -0000 1.23 *************** *** 936,942 **** --- 936,944 ---- static int ibindString(struct sqlvar_struct *var, PyObject *item) { + #if HAVE_PY_BOOL == 1 if (PyBool_Check(item)) { item = PyNumber_Int(item); } + #endif PyObject *sitem = PyObject_Str(item); const char *val = PyString_AS_STRING((PyStringObject*)sitem); |
From: Carsten H. <ch...@us...> - 2005-10-27 15:10:29
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16473 Modified Files: _informixdb.ec Log Message: Fix mysterious typo. This didn't even compile. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** _informixdb.ec 27 Oct 2005 03:50:07 -0000 1.21 --- _informixdb.ec 27 Oct 2005 15:10:18 -0000 1.22 *************** *** 936,940 **** static int ibindString(struct sqlvar_struct *var, PyObject *item) { ! if PyBool_Check(item) { item = PyNumber_Int(item); } --- 936,940 ---- static int ibindString(struct sqlvar_struct *var, PyObject *item) { ! if (PyBool_Check(item)) { item = PyNumber_Int(item); } |