From 921819a8bd9c1223ed488fe12b0fa231f02b1890 Mon Sep 17 00:00:00 2001 From: abi Date: Mon, 15 Dec 2014 21:00:00 +0100 Subject: [PATCH] make sqlite.text_factory setting configurable --- bottle_sqlite.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bottle_sqlite.py b/bottle_sqlite.py index 7f4c3ae..28e3cdf 100755 --- a/bottle_sqlite.py +++ b/bottle_sqlite.py @@ -53,11 +53,12 @@ class SQLitePlugin(object): api = 2 def __init__(self, dbfile=':memory:', autocommit=True, dictrows=True, - keyword='db'): + keyword='db', text_factory=unicode): self.dbfile = dbfile self.autocommit = autocommit self.dictrows = dictrows self.keyword = keyword + self.text_factory = text_factory def setup(self, app): ''' Make sure that other installed plugins don't affect the same @@ -91,6 +92,7 @@ class SQLitePlugin(object): autocommit = g('autocommit', self.autocommit) dictrows = g('dictrows', self.dictrows) keyword = g('keyword', self.keyword) + text_factory = g('keyword', self.text_factory) # Test if the original callback accepts a 'db' keyword. # Ignore it if it does not need a database handle. @@ -101,6 +103,8 @@ class SQLitePlugin(object): def wrapper(*args, **kwargs): # Connect to the database db = sqlite3.connect(dbfile) + # set text factory + db.text_factory = text_factory # This enables column access by name: row['column_name'] if dictrows: db.row_factory = sqlite3.Row