There is an issue in the sqlite backend regarding encoding/decoding. Below 
is the relevant code from the __init__ method:

class SQLiteConnection(DBAPI):
    [...]
    def __init__(self, filename, autoCommit=1, **kw):
        global sqlite
        global using_sqlite2
        if sqlite is None:
            try:
                import sqlite3 as sqlite
                using_sqlite2 = True
            except ImportError:
                try:
                    from pysqlite2 import dbapi2 as sqlite
                    using_sqlite2 = True
                except ImportError:
                    import sqlite
                    using_sqlite2 = False
        self.module = sqlite
        [...]
        if using_sqlite2:
            [...]
            try:
                from sqlite import encode, decode
            except ImportError:
                import base64
                sqlite.encode = base64.encodestring
                sqlite.decode = base64.decodestring
            else:
                sqlite.encode = encode
                sqlite.decode = decode

Now if I have pysqlite2 installed it will be preferred over sqlite. 
However the issue is that if I also have sqlite installed it will import 
the encode/decode functions from there, while if I don't it will use 
base64 encoding. 

I was recently hit by this as I has both installed and I was using a 
sqlite3 database with PickleCol. Later I removed sqlite and suddenly my 
database stopped working and gave errors on the pickle columns as the 
encoder/decoder changed.

IMO if we use pysqlite2 or sqlite3 we shouldn't import encoders/decoders 
from the old sqlite module, but instead use base64 always. Even more 
considering that sqlite2 and sqlite3 databases are not compatible, there 
is no reason to try to keep the columns in the same format. Maybe it 
makes sense if we try to migrate from one to another by dumping the 
database and the reloading it with the new backend, but then we need to 
make sure that the encoding doesn't change. So why shouldn't we use 
base64 with all backends in the end if we want to have consistent 
encoding/decoding for binary columns independently of what backends are 
installed?


-- 
Dan

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to