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