mirror of
https://github.com/HelloZeroNet/ZeroNet.git
synced 2023-12-14 04:33:03 +01:00
Allow like parameters in database queries
This commit is contained in:
parent
67d6b1e724
commit
f4f0e2afa8
2 changed files with 7 additions and 0 deletions
|
@ -49,6 +49,8 @@ class DbCursor:
|
|||
else:
|
||||
if key.startswith("not__"):
|
||||
query_wheres.append(key.replace("not__", "") + " != ?")
|
||||
elif key.endswith("__like"):
|
||||
query_wheres.append(key.replace("__like", "") + " LIKE ?")
|
||||
elif key.endswith(">"):
|
||||
query_wheres.append(key.replace(">", "") + " > ?")
|
||||
elif key.endswith("<"):
|
||||
|
|
|
@ -75,6 +75,11 @@ class TestDb:
|
|||
{"not__title": ["Test #%s" % i for i in range(50, 3000)]}
|
||||
).fetchone()["num"] == 50
|
||||
|
||||
assert db.execute(
|
||||
"SELECT COUNT(*) AS num FROM test WHERE ?",
|
||||
{"title__like": "%20%"}
|
||||
).fetchone()["num"] == 1
|
||||
|
||||
# Test named parameter escaping
|
||||
assert db.execute(
|
||||
"SELECT COUNT(*) AS num FROM test WHERE test_id = :test_id AND title LIKE :titlelike",
|
||||
|
|
Loading…
Reference in a new issue