Commit acb77f27 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Enable answering RQL select queries with symbolic bindings

This introduces a version 2.0 of the rqlio protocol that is able to answer
select RQL queries with symbolic bindings (with the names of the selected
variables) instead of the positional rows. Because this breaks compatibility
with the 1.0 protocol, this change warrants a new version. The previous version
continues to work alongside the new one.

The end result is the ability to answer the query Any X WHERE X is CWEtype with
[ { 'rows': [ [101], [102], [103], ...],
  'variables': ['X'] } ]
instead of
[ [[101], [102], [103], ...] ]

In protocol version 2.0, when there are no variable names, the variables member
is simply empty. In addition, the value of the 'rows' member of the response
object is exactly the same as the total response in the previous protocol, which
should help write fallback code in client libraries.
parent 549b4c201031
......@@ -128,13 +128,13 @@ class RqlIOController(Controller):
self._cw.ajax_request = True
if self._cw.form['version'] != '1.0':
raise RemoteCallFailed('unknown rqlio version %r',
args = self.json()
version = self._cw.form['version']
if version not in ('1.0', '2.0'):
raise RemoteCallFailed('unknown rqlio version %r', version)
args = self.json()
result = self.rqlio(*args)
result = self.rqlio(version, *args)
except (RemoteCallFailed, DirectResponse):
except Exception as exc:
......@@ -143,7 +143,7 @@ class RqlIOController(Controller):
return b''
return json_dumps(result).encode(self._cw.encoding)
def rqlio(self, *rql_args):
def rqlio(self, version, *rql_args):
output = self._rqlio(rql_args)
except Exception:
......@@ -151,6 +151,8 @@ class RqlIOController(Controller):
if version == '2.0':
return [{'rows': o.rows, 'variables': o.variables} for o in output]
return [o.rows for o in output]
def _rqlio(self, rql_args):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment