Menu

#20 VARCHAR containing binary data truncated on first null

1.1 Branch
open
nobody
None
5
2011-01-05
2011-01-05
No

Please note - there is a similar bug which was raised before - but I dont think it's the same.

When selecting from a VARCHAR that contains binrary data the data is truncated on the first null.

Extract of fix in _db2_module.c below:
<code>
static PyObject *
_SQL_CType_2_PyType(DB2BindStruct *bs, int idx)
{
PyObject *val, *tmpVal;
char *tempStr;
int size;
SQLPOINTER buf = (SQLPOINTER)((SQLCHAR *)bs->buf + (bs->bufLen * idx));

DATE_STRUCT dateSt;
TIME_STRUCT timeSt;
TIMESTAMP_STRUCT timestampSt;
char *fractionPart;

if ( bs->outLen[idx] == SQL_NULL_DATA ) {
Py_INCREF(Py_None);
return Py_None;
}

switch (bs->type) {

case SQL_C_CHAR:
switch (bs->typeEx) {

case SQL_BIGINT:
val = PyLong_FromString((SQLCHAR *)(buf), NULL, 0);
break;

case SQL_DECIMAL: /* WARNING! */
case SQL_NUMERIC: /* WARNING! */
tmpVal = PyString_FromString((SQLCHAR *)(buf));
val = PyFloat_FromString(tmpVal, NULL);
Py_DECREF(tmpVal);
break;

default:
//buf may contain null characters
//val = PyString_FromString((SQLCHAR *)(buf));
val = PyString_FromStringAndSize((SQLCHAR *)(buf), *bs->outLen);
break;

}
break;
..
...
...
</cvde>

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.