Re: [pysqlite] retrieving 64-bit numbers from SQLite

Roger Binns <[email protected]> Fri, 12 Sep 2008 04:17:17 -0700
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bruce Greenblatt wrote:
> Yes. That's exactly how I know that the numbers appear to be correct in the database.  Sorry for my poor wording.  If I do a select of the table from the database, here's what I get:
> 
> sqlite> select name, num from stats order by num_bytes desc limit 20;

Try using ttypeof(num) to get the actual type SQLite is storing as.  If
it is integer then the code I pointed at is used:

>> PY_LONG_LONG 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);
>> }

You can run the pysqlite test suite to verify its operation.  The test
suite would fail if the above code isn't working correctly.

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIyk+9mOOfHg372QQRAk/6AKCU+JzzH8xtE+275Sj7vI+BaLk8HQCdFjyQ
wqx0E2hGJ72RBe54VTSwWvY=
=QJjY
-----END PGP SIGNATURE-----