Commit 759b5088 authored by Alain Takoudjou's avatar Alain Takoudjou

slapos.collect: allow connect without call boostrap, set timeout option

parent 62627b23
...@@ -121,15 +121,17 @@ class Database: ...@@ -121,15 +121,17 @@ class Database:
" date, time) values "\ " date, time) values "\
"( '%s', '%s', %s, %s, %s, %s, '%s', '%s' )" "( '%s', '%s', %s, %s, %s, %s, '%s', '%s' )"
def __init__(self, directory = None): def __init__(self, directory = None, create = True, timeout=None):
assert self.database_name is not None assert self.database_name is not None
self.uri = os.path.join(directory, self.database_name) self.uri = os.path.join(directory, self.database_name)
self.connection = None self.connection = None
self.cursor = None self.cursor = None
self.timeout = timeout
if create:
self._bootstrap() self._bootstrap()
def connect(self): def connect(self):
self.connection = sqlite_connect(self.uri) self.connection = sqlite_connect(self.uri, timeout=self.timeout)
self.cursor = self.connection.cursor() self.cursor = self.connection.cursor()
def commit(self): def commit(self):
......
...@@ -97,7 +97,10 @@ def string_to_boolean(string): ...@@ -97,7 +97,10 @@ def string_to_boolean(string):
raise ValueError('%s is neither True nor False.' % string) raise ValueError('%s is neither True nor False.' % string)
def sqlite_connect(dburi): def sqlite_connect(dburi, timeout=None):
conn = sqlite3.connect(dburi) connect_kw = {}
if timeout is not None:
connect_kw['timeout'] = timeout
conn = sqlite3.connect(dburi, **connect_kw)
conn.text_factory = str # allow 8-bit strings conn.text_factory = str # allow 8-bit strings
return conn return conn
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment