Django

Code

Changeset 383

Show
Ignore:
Timestamp:
08/01/05 16:49:57 (3 years ago)
Author:
jacob
Message:

Fixed #227 -- the sqlite backend now correctly typecasts unicode objects to bytestrings (thanks hugo)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/db/backends/sqlite3.py

    r309 r383  
    1717# Database wrapper ############################################################ 
    1818 
     19def utf8rowFactory(cursor, row): 
     20    def utf8(s): 
     21        if type(s) == unicode: 
     22            return s.encode("utf-8") 
     23        else: 
     24            return s 
     25    return [utf8(r) for r in row] 
     26 
    1927class DatabaseWrapper: 
    2028    def __init__(self): 
     
    2937            self.connection.create_function("django_extract", 2, _sqlite_extract) 
    3038            self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 
     39        cursor = self.connection.cursor(factory=SQLiteCursorWrapper) 
     40        cursor.row_factory = utf8rowFactory 
    3141        if DEBUG: 
    32             return base.CursorDebugWrapper(FormatStylePlaceholderCursor(self.connection), self) 
    33         return FormatStylePlaceholderCursor(self.connection) 
     42            return base.CursorDebugWrapper(cursor, self) 
     43        else: 
     44            return cursor 
    3445 
    3546    def commit(self): 
     
    4556            self.connection = None 
    4657 
    47 class FormatStylePlaceholderCursor(Database.Cursor): 
     58class SQLiteCursorWrapper(Database.Cursor): 
    4859    """ 
    4960    Django uses "format" style placeholders, but pysqlite2 uses "qmark" style.