[Cubicweb] Using only Yams and RQL with SQLite

Yann Cointepas yann at sapetnioc.org
Sat Feb 27 00:10:11 CET 2010

Sorry for my previous empty message. I still do not understand how I sent it
(I should go to sleep).

With Sylvain's advices, I have been able to load a schema and initialise a
database but when I try to convert an RQL query to SQL I have an exception
that is quite hard to track for me:

yann at petityann:~/cubicweb/embedded_cubicweb$ python embedded_cubicweb.py
Schema: <yams.schema.Schema object at 0x87877ac>
Traceback (most recent call last):
  File "embedded_cubicweb.py", line 47, in <module>
    print rql2sql( rql, {}, rql_helper, sql_generator )
  File "embedded_cubicweb.py", line 20, in rql2sql
    return sql_generator.generate( rqlst, args )
  File "/usr/local/cubicweb/cubicweb/server/sources/rql2sql.py", line 369,
in generate
    sql = self.union_sql(union)
  File "/usr/local/cubicweb/cubicweb/server/sources/rql2sql.py", line 389,
in noparen_union_sql
    return '\nUNION ALL\n'.join(sqls)
  File "/usr/local/cubicweb/cubicweb/server/sources/rql2sql.py", line 388,
in <genexpr>
    for i, select in enumerate(union.children))
  File "/usr/local/cubicweb/cubicweb/server/sources/rql2sql.py", line 401,
in select_sql
    distinct = selectsortterms = select.need_distinct
*AttributeError: 'VariableRef' object has no attribute 'need_distinct'
On Fri, Feb 26, 2010 at 2:52 PM, Sylvain Thénault <
sylvain.thenault at logilab.fr> wrote:

> Hello Yann,
> On 26 février 14:15, Yann Cointepas wrote:
> > I wonder if it is possible for a Python script (without server, user
> > authentication, etc.) to define a schema with Yams, create a database
> with
> > SQLite and use RQL for querying. My goal is to find a suitable file
> format
> > to store graphs, do queries on them and eventually put/pull them in/from
> > real databases. I was thinking to use directly SQLite but I would really
> > appreciate to have the power of RQL queries. And it would even make more
> > sense if our databases are based on CubicWeb.
> huumm, that looks like a very nice use case. We're very interested in
> such usage of yams/rql outside the cubicweb framework (well, the heavy
> part of it at list). Unfortunatly we've currently no time to do so but
> if you've some, we'll definitly help you to acheive this!
> > I looked at CubicWeb sources and test codes and I had been able to build
> an
> > incomplete schema (for instance it has no "is" relation) and to get SQL
> code
> > to generate some tables within a SQLite database but I did not find a way
> to
> > use RQL queries on it.
> Here are some guide lines:
> * build the schema from yams objects directly is too much pain. You should
>  be able to write it as usual with python files. If you don't want a whole
>  cubicweb schema, something like:
>    from yams.reader import SchemaLoader
>    schema = SchemaLoader().load([<directory where schema.py may be found>])
>  should load your schema.
> * to handle rql, something like:
>    from rql import RQLHelper
>    from cubicweb.server.sources.rql2sql import SQLGenerator
>    rqlh = RQLHelper(schema)
>    sqlgen = SQLGenerator(schema, dbms_helper) # get dbms_helper for sqlite
> from logilab.common.adbh
>    def rql2sql(rql, args):
>      """return sql query and args to give to sql cursor:
>      cu.execute(*rql2sql('Any X,Y WHERE X relation Y'))
>      """
>      rqlst = rqlh.parse(rql)
>      rqlh.compute_solutions(rqlst, kwargs=args)
>      return sqlgen.generate(rqlst, args)
> this is untested pseudo-code but it should put you on the right way. You'll
> probably encounter some problems due to missing cw specific stuff in the
> schema, but I don't think anything non tweakable. Don't hesitate to ask
> more question, and let us tuned about your progress!
> regards,
> --
> Sylvain Thénault                               LOGILAB, Paris (France)
> Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
> Développement logiciel sur mesure:       http://www.logilab.fr/services
> CubicWeb, the semantic web framework:    http://www.cubicweb.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20100227/947d5710/attachment-0187.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: embedded_cubicweb.py
Type: application/octet-stream
Size: 1525 bytes
Desc: not available
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20100227/947d5710/attachment-0548.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: schema.py
Type: application/octet-stream
Size: 92 bytes
Desc: not available
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20100227/947d5710/attachment-0549.obj>

More information about the Cubicweb mailing list