add readonly mode
This commit is contained in:
parent
e6e0e9e59e
commit
1567cf6420
|
@ -59,13 +59,14 @@ class SQLitePlugin(object):
|
||||||
unicode = str
|
unicode = str
|
||||||
|
|
||||||
def __init__(self, dbfile=':memory:', autocommit=True, dictrows=True,
|
def __init__(self, dbfile=':memory:', autocommit=True, dictrows=True,
|
||||||
keyword='db', text_factory=unicode,
|
keyword='db', text_factory=unicode, readonly=False,
|
||||||
functions=None, aggregates=None, collations=None, extensions=()):
|
functions=None, aggregates=None, collations=None, extensions=()):
|
||||||
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
|
self.text_factory = text_factory
|
||||||
|
self.readonly = readonly
|
||||||
self.functions = functions or {}
|
self.functions = functions or {}
|
||||||
self.aggregates = aggregates or {}
|
self.aggregates = aggregates or {}
|
||||||
self.collations = collations or {}
|
self.collations = collations or {}
|
||||||
|
@ -104,6 +105,7 @@ class SQLitePlugin(object):
|
||||||
dictrows = g('dictrows', self.dictrows)
|
dictrows = g('dictrows', self.dictrows)
|
||||||
keyword = g('keyword', self.keyword)
|
keyword = g('keyword', self.keyword)
|
||||||
text_factory = g('text_factory', self.text_factory)
|
text_factory = g('text_factory', self.text_factory)
|
||||||
|
readonly = g('readonly', self.readonly)
|
||||||
functions = g('functions', self.functions)
|
functions = g('functions', self.functions)
|
||||||
aggregates = g('aggregates', self.aggregates)
|
aggregates = g('aggregates', self.aggregates)
|
||||||
collations = g('collations', self.collations)
|
collations = g('collations', self.collations)
|
||||||
|
@ -117,6 +119,11 @@ class SQLitePlugin(object):
|
||||||
|
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
# Connect to the database
|
# Connect to the database
|
||||||
|
if readonly:
|
||||||
|
# drive letters not transformed
|
||||||
|
urifn = dbfile.replace('?', '%3f').replace('#', '%23')
|
||||||
|
db = sqlite3.connect('file:%s?mode=ro' % urifn, uri=True)
|
||||||
|
else:
|
||||||
db = sqlite3.connect(dbfile)
|
db = sqlite3.connect(dbfile)
|
||||||
# set text factory
|
# set text factory
|
||||||
db.text_factory = text_factory
|
db.text_factory = text_factory
|
||||||
|
|
Loading…
Reference in New Issue
Block a user