A relative bound has to be datetime('now', '-24 hours'); datetime('-24 hours')
returns NULL, so the comparison was false for every row and --since silently
reported nothing rather than erroring. Caught when a --since '-10 minutes'
came back empty for queries that had demonstrably just happened.
Absolute forms ('2026-09-13') still take the single-argument path.
This commit is contained in:
1 parent
1bfbcfdac3
commit
37feb109b3
1 file changed
+15
-3
@@ -92,6 +92,18 @@ def limited(sql):
|
|||||||
return sql if limit == "all" else f"{sql} LIMIT {int(limit)}"
|
return sql if limit == "all" else f"{sql} LIMIT {int(limit)}"
|
||||||
|
|
||||||
|
|
||||||
|
def since_expr(column):
|
||||||
|
"""SQL for the --since bound.
|
||||||
|
|
||||||
|
A leading +/- means "relative to now" — sqlite needs that spelled
|
||||||
|
datetime('now', '-24 hours'), NOT datetime('-24 hours'), which returns
|
||||||
|
NULL and silently matches no rows.
|
||||||
|
"""
|
||||||
|
if since.startswith(("+", "-")):
|
||||||
|
return f"{column} >= datetime('now', ?)"
|
||||||
|
return f"{column} >= datetime(?)"
|
||||||
|
|
||||||
|
|
||||||
def tables_exist():
|
def tables_exist():
|
||||||
names = {r[0] for r in conn.execute(
|
names = {r[0] for r in conn.execute(
|
||||||
"SELECT name FROM sqlite_master WHERE type = 'table'")}
|
"SELECT name FROM sqlite_master WHERE type = 'table'")}
|
||||||
@@ -106,7 +118,7 @@ if not tables_exist():
|
|||||||
if mode == "stats":
|
if mode == "stats":
|
||||||
where, params = [], []
|
where, params = [], []
|
||||||
if since:
|
if since:
|
||||||
where.append("queried_at >= datetime(?)")
|
where.append(since_expr("queried_at"))
|
||||||
params.append(since)
|
params.append(since)
|
||||||
clause = (" WHERE " + " AND ".join(where)) if where else ""
|
clause = (" WHERE " + " AND ".join(where)) if where else ""
|
||||||
row = conn.execute(
|
row = conn.execute(
|
||||||
@@ -150,7 +162,7 @@ if mode == "blocks":
|
|||||||
where.append("kind = ?")
|
where.append("kind = ?")
|
||||||
params.append(kind)
|
params.append(kind)
|
||||||
if since:
|
if since:
|
||||||
where.append("first_blocked_at >= datetime(?)")
|
where.append(since_expr("first_blocked_at"))
|
||||||
params.append(since)
|
params.append(since)
|
||||||
clause = (" WHERE " + " AND ".join(where)) if where else ""
|
clause = (" WHERE " + " AND ".join(where)) if where else ""
|
||||||
rows = conn.execute(limited(
|
rows = conn.execute(limited(
|
||||||
@@ -179,7 +191,7 @@ if kind:
|
|||||||
where.append("kind = ?")
|
where.append("kind = ?")
|
||||||
params.append(kind)
|
params.append(kind)
|
||||||
if since:
|
if since:
|
||||||
where.append("queried_at >= datetime(?)")
|
where.append(since_expr("queried_at"))
|
||||||
params.append(since)
|
params.append(since)
|
||||||
clause = (" WHERE " + " AND ".join(where)) if where else ""
|
clause = (" WHERE " + " AND ".join(where)) if where else ""
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user