[issue8033] sqlite: broken long integer handling for arguments to user-defined functions

2010-02-28 Thread Fred Fettinger

New submission from Fred Fettinger :

Handling of long integers is broken for arguments to sqlite functions created 
with the create_function api. Integers passed to a sqlite function are always 
converted to int instead of long, which produces an incorrect value for 
integers outside the range of a int32 on a 32 bit machine. These failures 
cannot be reproduced on a 64 bit machine, since sizeof(long) == sizeof(long 
long).

I attached a program that demonstrates the failure. This program reports 
failures on a 32 bit machine, and all tests pass on a 64 bit machine.

--
components: Library (Lib)
files: sqlite_long_test.py
messages: 100235
nosy: BinaryMan32
severity: normal
status: open
title: sqlite: broken long integer handling for arguments to user-defined 
functions
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file16404/sqlite_long_test.py

___
Python tracker 
<http://bugs.python.org/issue8033>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8033] sqlite: broken long integer handling for arguments to user-defined functions

2010-02-28 Thread Fred Fettinger

Fred Fettinger  added the comment:

I've never really looked at the python source before, but this is my best guess 
at the problem:

For the standard SELECT query:
In Modules/_sqlite/cursor.c, _pysqlite_fetch_one_row() has this code:
PY_LONG_LONG intval;
...
} else if (coltype == SQLITE_INTEGER) {
intval = sqlite3_column_int64(self->statement->st, i);
if (intval < INT32_MIN || intval > INT32_MAX) {
converted = PyLong_FromLongLong(intval);
} else {
converted = PyInt_FromLong((long)intval);
}
}

For user-defined function arguments:
In Modules/_sqlite/connection.c, _pysqlite_build_py_params() has this code:
PY_LONG_LONG val_int;
...
case SQLITE_INTEGER:
val_int = sqlite3_value_int64(cur_value);
cur_py_value = PyInt_FromLong((long)val_int);
break;

A select query can return long integers from C to python but a user-defined 
function argument cannot.

--

___
Python tracker 
<http://bugs.python.org/issue8033>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com