This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wrobell
Recipients wrobell
Date 2008-02-21.18:57:01
SpamBayes Score 0.020851599
Marked as misclassified No
Message-id <1203620223.11.0.994407753132.issue2157@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008-02-21 18:57:03wrobellsetspambayes_score: 0.0208516 -> 0.020851599
recipients: + wrobell
2008-02-21 18:57:03wrobellsetspambayes_score: 0.0208516 -> 0.0208516
messageid: <1203620223.11.0.994407753132.issue2157@psf.upfronthosting.co.za>
2008-02-21 18:57:02wrobelllinkissue2157 messages
2008-02-21 18:57:01wrobellcreate