[New-bugs-announce] [issue2157] sqlite numeric type conversion problems

wrobell report at bugs.python.org
Thu Feb 21 19:57:03 CET 2008

New submission from wrobell:

Numeric type conversion does not always work when using SQLite module.

Let's assume schema:

    create table test_num(no numeric);

Fetching a `test_num.no` table gives float by default.

Now, let's register some converter

    sqlite3.register_converter('numeric', lambda d: Decimal(d))

Fetching `test_num.no` gives Decimal.

But change `test_num.no` type to `numeric(10, 2)`. Float is returned.
This can be fixed by

    sqlite3.register_converter('numeric(10,', lambda d: Decimal(d))

But above will fail for `test_num.no: numeric(10,2)', which works in
case of

    sqlite3.register_converter('numeric(10,2)', lambda d: Decimal(d))

SQLite module's cursor object type cast mechanism breaks declared
type after first space {i.e. "numeric(10, 2)" -> "numeric(10,"} and
then looks up registered type converter using the first "word".

The simple fix for above could be to perform the break after space
or "(" character. Patch attached.

components: Library (Lib)
files: python-sqlite-numeric.patch
messages: 62640
nosy: wrobell
severity: normal
status: open
title: sqlite numeric type conversion problems
versions: Python 2.5
Added file: http://bugs.python.org/file9484/python-sqlite-numeric.patch

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list