mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-21 18:46:42 +00:00
Compare commits
No commits in common. "826312115c7a87e8af5bf27a4d2c181630130481" and "78c04ef6f3f420935735b5ff1185abba352cc581" have entirely different histories.
826312115c
...
78c04ef6f3
14
hexlib/db.py
14
hexlib/db.py
@ -118,13 +118,9 @@ class Table:
|
||||
with sqlite3.connect(self._state.dbfile, **self._state.dbargs) as conn:
|
||||
conn.row_factory = sqlite3.Row
|
||||
try:
|
||||
col_types = conn.execute("PRAGMA table_info(%s)" % self._table).fetchall()
|
||||
cur = conn.execute("SELECT * FROM %s %s" % (self._table, where_clause), params)
|
||||
for row in cur:
|
||||
yield dict(
|
||||
(col[0], _deserialize(row[col[0]], col_types[i]["type"]))
|
||||
for i, col in enumerate(cur.description)
|
||||
)
|
||||
yield dict(row)
|
||||
except:
|
||||
return None
|
||||
|
||||
@ -132,13 +128,9 @@ class Table:
|
||||
with sqlite3.connect(self._state.dbfile, **self._state.dbargs) as conn:
|
||||
conn.row_factory = sqlite3.Row
|
||||
try:
|
||||
col_types = conn.execute("PRAGMA table_info(%s)" % self._table).fetchall()
|
||||
cur = conn.execute("SELECT * FROM %s" % (self._table,))
|
||||
for row in cur:
|
||||
yield dict(
|
||||
(col[0], _deserialize(row[col[0]], col_types[i]["type"]))
|
||||
for i, col in enumerate(cur.description)
|
||||
)
|
||||
yield dict(row)
|
||||
except:
|
||||
return None
|
||||
|
||||
@ -217,7 +209,7 @@ def _serialize(value):
|
||||
|
||||
|
||||
def _deserialize(value, col_type):
|
||||
if col_type.lower() == "blob":
|
||||
if col_type == "blob":
|
||||
return base64.b64decode(value)
|
||||
return value
|
||||
|
||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
||||
|
||||
setup(
|
||||
name="hexlib",
|
||||
version="1.81",
|
||||
version="1.79",
|
||||
description="Misc utility methods",
|
||||
author="simon987",
|
||||
author_email="me@simon987.net",
|
||||
|
@ -110,24 +110,3 @@ class TestPersistentState(TestCase):
|
||||
del s["a"][456]
|
||||
except Exception as 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