support of sqlite3
This commit is contained in:
parent
8345a4651d
commit
27838e67a3
1 changed files with 84 additions and 51 deletions
|
@ -27,49 +27,69 @@ class Properties(Sqlite3DB):
|
|||
|
||||
# properties
|
||||
def setproperties(self, path, index, properties):
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM property WHERE path = ? AND tiram_index = ? AND session_id = ?",
|
||||
(path, index, self._session_id),
|
||||
False)
|
||||
self.exportation()
|
||||
self.delproperties(path, index, commit=False)
|
||||
self.exportation()
|
||||
self._storage.execute("INSERT INTO property(path, tiram_index, properties, session_id) VALUES "
|
||||
"(?, ?, ?, ?)", (path,
|
||||
index,
|
||||
self._sqlite_encode(properties),
|
||||
self._session_id))
|
||||
self.exportation()
|
||||
|
||||
def getproperties(self, path, index, default_properties):
|
||||
path = self._sqlite_encode_path(path)
|
||||
value = self._storage.select("SELECT properties FROM property WHERE "
|
||||
"path = ? AND tiram_index = ? AND session_id = ? LIMIT 1", (path, index, self._session_id))
|
||||
sql = 'SELECT properties FROM property WHERE session_id = ? '
|
||||
params = [self._session_id]
|
||||
if path is None:
|
||||
sql += "AND path is NULL "
|
||||
else:
|
||||
sql += "AND path = ? "
|
||||
params.append(path)
|
||||
if index is None:
|
||||
sql += "AND tiram_index is NULL LIMIT 1"
|
||||
else:
|
||||
sql += "AND tiram_index = ? LIMIT 1"
|
||||
params.append(index)
|
||||
value = self._storage.select(sql, params)
|
||||
if value is None:
|
||||
return set(default_properties)
|
||||
else:
|
||||
return set(self._sqlite_decode(value[0]))
|
||||
|
||||
def delproperties(self, path, index):
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM property WHERE path = ? AND tiram_index = ? AND session_id = ?",
|
||||
(path, index, self._session_id))
|
||||
def delproperties(self, path, index, commit=True):
|
||||
sql = 'DELETE FROM property WHERE session_id = ? '
|
||||
params = [self._session_id]
|
||||
if path is None:
|
||||
sql += 'AND path is NULL '
|
||||
else:
|
||||
sql += 'AND path = ? '
|
||||
params.append(path)
|
||||
if index is None:
|
||||
sql += 'AND tiram_index is NULL'
|
||||
else:
|
||||
params.append(index)
|
||||
sql += 'AND tiram_index = ?'
|
||||
self._storage.execute(sql, params, commit)
|
||||
|
||||
def exportation(self):
|
||||
"""return all modified settings in a dictionary
|
||||
example: {'path1': set(['prop1', 'prop2'])}
|
||||
"""
|
||||
ret = {}
|
||||
for path, properties, _ in self._storage.select("SELECT * FROM property "
|
||||
for path, tiram_index, properties, _ in self._storage.select("SELECT * FROM property "
|
||||
"WHERE session_id = ?",
|
||||
(self._session_id,),
|
||||
only_one=False):
|
||||
path = self._sqlite_decode_path(path)
|
||||
ret[path] = self._sqlite_decode(properties)
|
||||
ret.setdefault(path, {})[tiram_index] = self._sqlite_decode(properties)
|
||||
return ret
|
||||
|
||||
def importation(self, properties):
|
||||
self._storage.execute("DELETE FROM property WHERE session_id = ?", (self._session_id,), commit=False)
|
||||
for path, property_ in properties.items():
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("INSERT INTO property(path, properties, session_id) "
|
||||
"VALUES (?, ?, ?)", (path,
|
||||
for path, indexed_properties in properties.items():
|
||||
for index, property_ in indexed_properties.items():
|
||||
self._storage.execute("INSERT INTO property(path, tiram_index, properties, session_id) "
|
||||
"VALUES (?, ?, ?, ?)", (path,
|
||||
index,
|
||||
self._sqlite_encode(property_),
|
||||
self._session_id,
|
||||
), False)
|
||||
|
@ -81,13 +101,8 @@ class Permissives(Sqlite3DB):
|
|||
|
||||
# permissive
|
||||
def setpermissives(self, path, index, permissive):
|
||||
path = self._sqlite_encode_path(path)
|
||||
log.debug('setpermissive %s %s %s %s', path, index, permissive, id(self))
|
||||
self._storage.execute("DELETE FROM permissive WHERE path = ? AND tiram_index = ? AND session_id = ?",
|
||||
(path,
|
||||
index,
|
||||
self._session_id),
|
||||
False)
|
||||
self.delpermissive(path, index, commit=False)
|
||||
self._storage.execute("INSERT INTO permissive(path, tiram_index, permissives, session_id) "
|
||||
"VALUES (?, ?, ?, ?)", (path,
|
||||
index,
|
||||
|
@ -95,10 +110,19 @@ class Permissives(Sqlite3DB):
|
|||
self._session_id))
|
||||
|
||||
def getpermissives(self, path, index):
|
||||
path = self._sqlite_encode_path(path)
|
||||
permissives = self._storage.select("SELECT permissives FROM "
|
||||
"permissive WHERE path = ? AND tiram_index = ? AND session_id = ? LIMIT 1",
|
||||
(path, index, self._session_id))
|
||||
sql = 'SELECT permissives FROM permissive WHERE session_id = ? '
|
||||
params = [self._session_id]
|
||||
if path is None:
|
||||
sql += "AND path is NULL "
|
||||
else:
|
||||
sql += "AND path = ? "
|
||||
params.append(path)
|
||||
if index is None:
|
||||
sql += "AND tiram_index is NULL LIMIT 1"
|
||||
else:
|
||||
sql += "AND tiram_index = ? LIMIT 1"
|
||||
params.append(index)
|
||||
permissives = self._storage.select(sql, params)
|
||||
if permissives is None:
|
||||
ret = frozenset()
|
||||
else:
|
||||
|
@ -106,10 +130,20 @@ class Permissives(Sqlite3DB):
|
|||
log.debug('getpermissive %s %s %s', path, ret, id(self))
|
||||
return ret
|
||||
|
||||
def delpermissive(self, path, index):
|
||||
path = self._sqlite_encode_path(path)
|
||||
self._storage.execute("DELETE FROM permissive WHERE path = ? AND tiram_index = ? AND session_id = ?",
|
||||
(path, index, self._session_id))
|
||||
def delpermissive(self, path, index, commit=True):
|
||||
sql = 'DELETE FROM permissive WHERE session_id = ? '
|
||||
params = [self._session_id]
|
||||
if path is None:
|
||||
sql += 'AND path is NULL '
|
||||
else:
|
||||
sql += 'AND path = ? '
|
||||
params.append(path)
|
||||
if index is None:
|
||||
sql += 'AND tiram_index is NULL'
|
||||
else:
|
||||
params.append(index)
|
||||
sql += 'AND tiram_index = ?'
|
||||
self._storage.execute(sql, params, commit)
|
||||
|
||||
def exportation(self):
|
||||
"""return all modified permissives in a dictionary
|
||||
|
@ -120,17 +154,16 @@ class Permissives(Sqlite3DB):
|
|||
"WHERE session_id = ?",
|
||||
(self._session_id,),
|
||||
only_one=False):
|
||||
path = self._sqlite_decode_path(path)
|
||||
ret[path] = self._sqlite_decode(permissives)
|
||||
ret.setdefault(path, {})[index] = self._sqlite_decode(permissives)
|
||||
return ret
|
||||
|
||||
def importation(self, permissives):
|
||||
self._storage.execute("DELETE FROM permissive WHERE session_id = ?", (self._session_id,),
|
||||
commit=False)
|
||||
for path, permissive in permissives.items():
|
||||
path = self._sqlite_encode_path(path)
|
||||
for path, indexed_permissives in permissives.items():
|
||||
for index, permissive in indexed_permissives.items():
|
||||
self._storage.execute("INSERT INTO permissive(path, tiram_index, permissives, session_id) "
|
||||
"VALUES (?, ?, ?)", (path,
|
||||
"VALUES (?, ?, ?, ?)", (path,
|
||||
index,
|
||||
self._sqlite_encode(permissive),
|
||||
self._session_id,
|
||||
|
|
Loading…
Reference in a new issue