Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #227 -- the sqlite backend now correctly typecasts unicode obje…

…cts to bytestrings (thanks hugo)

git-svn-id: http://code.djangoproject.com/svn/django/trunk@383 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1510ca1a80f811d6e681a880d7e49d413ce8afb4 1 parent e73c734
@jacobian jacobian authored
Showing with 14 additions and 3 deletions.
  1. +14 −3 django/core/db/backends/sqlite3.py
View
17 django/core/db/backends/sqlite3.py
@@ -16,6 +16,14 @@
# Database wrapper ############################################################
+def utf8rowFactory(cursor, row):
+ def utf8(s):
+ if type(s) == unicode:
+ return s.encode("utf-8")
+ else:
+ return s
+ return [utf8(r) for r in row]
+
class DatabaseWrapper:
def __init__(self):
self.connection = None
@@ -28,9 +36,12 @@ def cursor(self):
# register extract and date_trun functions
self.connection.create_function("django_extract", 2, _sqlite_extract)
self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
+ cursor = self.connection.cursor(factory=SQLiteCursorWrapper)
+ cursor.row_factory = utf8rowFactory
if DEBUG:
- return base.CursorDebugWrapper(FormatStylePlaceholderCursor(self.connection), self)
- return FormatStylePlaceholderCursor(self.connection)
+ return base.CursorDebugWrapper(cursor, self)
+ else:
+ return cursor
def commit(self):
self.connection.commit()
@@ -44,7 +55,7 @@ def close(self):
self.connection.close()
self.connection = None
-class FormatStylePlaceholderCursor(Database.Cursor):
+class SQLiteCursorWrapper(Database.Cursor):
"""
Django uses "format" style placeholders, but pysqlite2 uses "qmark" style.
This fixes it -- but note that if you want to use a literal "%s" in a query,
Please sign in to comment.
Something went wrong with that request. Please try again.