Commit 759b5088 by Alain Takoudjou

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

1 parent 62627b23
......@@ -121,15 +121,17 @@ class Database:
" date, time) values "\
"( '%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
self.uri = os.path.join(directory, self.database_name)
self.connection = None
self.cursor = None
self._bootstrap()
self.timeout = timeout
if create:
self._bootstrap()
def connect(self):
self.connection = sqlite_connect(self.uri)
self.connection = sqlite_connect(self.uri, timeout=self.timeout)
self.cursor = self.connection.cursor()
def commit(self):
......
......@@ -97,7 +97,10 @@ def string_to_boolean(string):
raise ValueError('%s is neither True nor False.' % string)
def sqlite_connect(dburi):
conn = sqlite3.connect(dburi)
def sqlite_connect(dburi, timeout=None):
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
return conn
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!