make sqlite.text_factory setting configurable

This commit is contained in:
abi 2014-12-15 21:00:00 +01:00
parent 961d4e8f0a
commit 921819a8bd

View File

@ -53,11 +53,12 @@ class SQLitePlugin(object):
api = 2 api = 2
def __init__(self, dbfile=':memory:', autocommit=True, dictrows=True, def __init__(self, dbfile=':memory:', autocommit=True, dictrows=True,
keyword='db'): keyword='db', text_factory=unicode):
self.dbfile = dbfile self.dbfile = dbfile
self.autocommit = autocommit self.autocommit = autocommit
self.dictrows = dictrows self.dictrows = dictrows
self.keyword = keyword self.keyword = keyword
self.text_factory = text_factory
def setup(self, app): def setup(self, app):
''' Make sure that other installed plugins don't affect the same ''' Make sure that other installed plugins don't affect the same
@ -91,6 +92,7 @@ class SQLitePlugin(object):
autocommit = g('autocommit', self.autocommit) autocommit = g('autocommit', self.autocommit)
dictrows = g('dictrows', self.dictrows) dictrows = g('dictrows', self.dictrows)
keyword = g('keyword', self.keyword) keyword = g('keyword', self.keyword)
text_factory = g('keyword', self.text_factory)
# Test if the original callback accepts a 'db' keyword. # Test if the original callback accepts a 'db' keyword.
# Ignore it if it does not need a database handle. # Ignore it if it does not need a database handle.
@ -101,6 +103,8 @@ class SQLitePlugin(object):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
# Connect to the database # Connect to the database
db = sqlite3.connect(dbfile) db = sqlite3.connect(dbfile)
# set text factory
db.text_factory = text_factory
# This enables column access by name: row['column_name'] # This enables column access by name: row['column_name']
if dictrows: if dictrows:
db.row_factory = sqlite3.Row db.row_factory = sqlite3.Row