summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy <jimmy@spalge.com>2021-12-31 14:15:32 +1300
committerJimmy <jimmy@spalge.com>2021-12-31 14:44:39 +1300
commit54b817898f212042386b602b25d23f66789399df (patch)
tree2414de2ed904e246f400315794d9372b8188ef12
parentc349fbd18084183d44f351af617f6ad5d16efabf (diff)
downloadqutebrowser-54b817898f212042386b602b25d23f66789399df.tar.gz
qutebrowser-54b817898f212042386b602b25d23f66789399df.zip
sql: Make Query.bound_values() return a dict again
SqlQuery.boundValues() changed in Qt6 from returning a map of placeholders -> values to just providing a list of values. We can either: 1. follow that change and always return a list * this has the effect of making the return value have more items if the caller uses a placeholder more than once in a query, like histcategory does 2. maintain the current return type Here I have chosen to do (2). Although (1) is an option since it looks like no caller actually cares about the contents of the response at this point (apart from tests), just that it is Truthy/Falsy and the right length (if Truthy). And callers should know how many times they re-used placeholders so should be able to adjust their length comparison themselves. There is no API for enumerating placeholder labels anymore, if we want to maintain our API we must either 1) store the placeholders so we can look them up based on label later, 2) guess what they are (eg assume the caller always used sequential integers starting at 0), or 3) always return the dict keys as the positional indexes instead of labels (and return a larger dict if the caller used single placeholders multiple times). I've chosen to do 3 which should have the same result as the 5.15 implementation, at the cost of some more list allocations. So now we store the placeholders so we can query for them directly later. And the existing tests should all pass, if you can get them to run. This approach works on both 5.15 and 6.2, so no version checks necessary.
-rw-r--r--qutebrowser/misc/sql.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/qutebrowser/misc/sql.py b/qutebrowser/misc/sql.py
index ea3c93703..aebeb0f23 100644
--- a/qutebrowser/misc/sql.py
+++ b/qutebrowser/misc/sql.py
@@ -299,6 +299,7 @@ class Query:
ok = self.query.prepare(querystr)
self._check_ok('prepare', ok)
self.query.setForwardOnly(forward_only)
+ self.placeholders = []
def __iter__(self) -> Iterator[Any]:
if not self.query.isActive():
@@ -320,6 +321,7 @@ class Query:
raise_sqlite_error(msg, error)
def _bind_values(self, values: Mapping[str, Any]) -> Dict[str, Any]:
+ self.placeholders = list(values)
for key, val in values.items():
self.query.bindValue(f':{key}', val)
@@ -378,7 +380,12 @@ class Query:
return rows
def bound_values(self) -> Dict[str, Any]:
- return self.query.boundValues()
+ binds = {}
+ for key in self.placeholders:
+ key_s = f":{key}"
+ val = self.query.boundValue(key_s)
+ binds[key_s] = val
+ return binds
class SqlTable(QObject):