mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-10 14:06:43 +00:00
Fix deserialization in PersistentState
This commit is contained in:
parent
78c04ef6f3
commit
372abb0076
12
hexlib/db.py
12
hexlib/db.py
@ -118,9 +118,13 @@ class Table:
|
|||||||
with sqlite3.connect(self._state.dbfile, **self._state.dbargs) as conn:
|
with sqlite3.connect(self._state.dbfile, **self._state.dbargs) as conn:
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
try:
|
try:
|
||||||
|
col_types = conn.execute("PRAGMA table_info(%s)" % self._table).fetchall()
|
||||||
cur = conn.execute("SELECT * FROM %s %s" % (self._table, where_clause), params)
|
cur = conn.execute("SELECT * FROM %s %s" % (self._table, where_clause), params)
|
||||||
for row in cur:
|
for row in cur:
|
||||||
yield dict(row)
|
yield dict(
|
||||||
|
(col[0], _deserialize(row[col[0]], col_types[i]["type"]))
|
||||||
|
for i, col in enumerate(cur.description)
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -128,9 +132,13 @@ class Table:
|
|||||||
with sqlite3.connect(self._state.dbfile, **self._state.dbargs) as conn:
|
with sqlite3.connect(self._state.dbfile, **self._state.dbargs) as conn:
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
try:
|
try:
|
||||||
|
col_types = conn.execute("PRAGMA table_info(%s)" % self._table).fetchall()
|
||||||
cur = conn.execute("SELECT * FROM %s" % (self._table,))
|
cur = conn.execute("SELECT * FROM %s" % (self._table,))
|
||||||
for row in cur:
|
for row in cur:
|
||||||
yield dict(row)
|
yield dict(
|
||||||
|
(col[0], _deserialize(row[col[0]], col_types[i]["type"]))
|
||||||
|
for i, col in enumerate(cur.description)
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.79",
|
version="1.80",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
@ -110,3 +110,24 @@ class TestPersistentState(TestCase):
|
|||||||
del s["a"][456]
|
del s["a"][456]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail(e)
|
self.fail(e)
|
||||||
|
|
||||||
|
def test_deserialize_get_set(self):
|
||||||
|
s = PersistentState()
|
||||||
|
|
||||||
|
s["a"][0] = {"x": b'abc'}
|
||||||
|
|
||||||
|
self.assertEqual(s["a"][0]["x"], b'abc')
|
||||||
|
|
||||||
|
def test_deserialize_sql(self):
|
||||||
|
s = PersistentState()
|
||||||
|
|
||||||
|
s["a"][0] = {"x": b'abc'}
|
||||||
|
|
||||||
|
self.assertEqual(list(s["a"].sql("WHERE 1=1"))[0]["x"], b'abc')
|
||||||
|
|
||||||
|
def test_deserialize_iter(self):
|
||||||
|
s = PersistentState()
|
||||||
|
|
||||||
|
s["a"][0] = {"x": b'abc'}
|
||||||
|
|
||||||
|
self.assertEqual(list(s["a"])[0]["x"], b'abc')
|
Loading…
x
Reference in New Issue
Block a user