# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1239027526 -7200 # Node ID af40e615dc8981d1d10461494a9e8a0c1ffb7834 # Parent 5c20a7f13c84ce9f29fb80d4fb7c7d20cd350090 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords diff -r 5c20a7f13c84 -r af40e615dc89 server/checkintegrity.py --- a/server/checkintegrity.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/checkintegrity.py Mon Apr 06 16:18:46 2009 +0200 @@ -2,7 +2,7 @@ is checked. :organization: Logilab -:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" @@ -12,6 +12,8 @@ from mx.DateTime import now from logilab.common.shellutils import ProgressBar +from cubicweb.server.sqlutils import SQL_PREFIX + def has_eid(sqlcursor, eid, eids): """return true if the eid is a valid eid""" if eids.has_key(eid): @@ -26,7 +28,8 @@ # XXX what to do... eids[eid] = True return True - sqlcursor.execute('SELECT * FROM %s WHERE eid=%s' % (etype, eid)) + sqlcursor.execute('SELECT * FROM %s%s WHERE %seid=%s' % (SQL_PREFIX, etype, + SQL_PREFIX, eid)) result = sqlcursor.fetchall() if len(result) == 0: eids[eid] = False @@ -154,7 +157,9 @@ for eschema in schema.entities(): if eschema.is_final(): continue - cursor = session.system_sql('SELECT eid FROM %s;' % eschema.type) + table = SQL_PREFIX + eschema.type + column = SQL_PREFIX + 'eid' + cursor = session.system_sql('SELECT %s FROM %s;' % (column, table)) for row in cursor.fetchall(): eid = row[0] # eids is full since we have fetched everyting from the entities table, @@ -163,7 +168,7 @@ msg = ' Entity with eid %s exists in the %s table but not in the system table' print >> sys.stderr, msg % (eid, eschema.type), if fix: - session.system_sql('DELETE FROM %s WHERE eid=%s;' % (eschema.type, eid)) + session.system_sql('DELETE FROM %s WHERE %s=%s;' % (table, column, eid)) print >> sys.stderr, ' [FIXED]' else: print >> sys.stderr @@ -184,40 +189,41 @@ for rschema in schema.relations(): if rschema.is_final(): continue - rtype = rschema.type - if rtype == 'identity': + if rschema == 'identity': continue if rschema.inlined: for subjtype in rschema.subjects(): + table = SQL_PREFIX + str(subjtype) + column = SQL_PREFIX + str(rschema) sql = 'SELECT %s FROM %s WHERE %s IS NOT NULL;' % ( - rtype, subjtype, rtype) + column, table, column) cursor = session.system_sql(sql) for row in cursor.fetchall(): eid = row[0] if not has_eid(cursor, eid, eids): - bad_related_msg(rtype, 'object', eid, fix) + bad_related_msg(rschema, 'object', eid, fix) if fix: - sql = 'UPDATE %s SET %s = NULL WHERE eid=%s;' % ( - subjtype, rtype, eid) + sql = 'UPDATE %s SET %s = NULL WHERE %seid=%s;' % ( + table, column, SQL_PREFIX, eid) session.system_sql(sql) continue - cursor = session.system_sql('SELECT eid_from FROM %s_relation;' % rtype) + cursor = session.system_sql('SELECT eid_from FROM %s_relation;' % rschema) for row in cursor.fetchall(): eid = row[0] if not has_eid(cursor, eid, eids): - bad_related_msg(rtype, 'subject', eid, fix) + bad_related_msg(rschema, 'subject', eid, fix) if fix: sql = 'DELETE FROM %s_relation WHERE eid_from=%s;' % ( - rtype, eid) + rschema, eid) session.system_sql(sql) - cursor = session.system_sql('SELECT eid_to FROM %s_relation;' % rtype) + cursor = session.system_sql('SELECT eid_to FROM %s_relation;' % rschema) for row in cursor.fetchall(): eid = row[0] if not has_eid(cursor, eid, eids): - bad_related_msg(rtype, 'object', eid, fix) + bad_related_msg(rschema, 'object', eid, fix) if fix: sql = 'DELETE FROM %s_relation WHERE eid_to=%s;' % ( - rtype, eid) + rschema, eid) session.system_sql(sql) @@ -228,21 +234,26 @@ """ print 'Checking metadata' cursor = session.system_sql("SELECT DISTINCT type FROM entities;") + eidcolumn = SQL_PREFIX + 'eid' for etype, in cursor.fetchall(): + table = SQL_PREFIX + etype for rel, default in ( ('creation_date', now()), ('modification_date', now()), ): - cursor = session.system_sql("SELECT eid FROM %s " - "WHERE %s is NULL" % (etype, rel)) + column = SQL_PREFIX + rel + cursor = session.system_sql("SELECT %s FROM %s WHERE %s is NULL" + % (eidcolumn, table, column)) for eid, in cursor.fetchall(): msg = ' %s with eid %s has no %s' print >> sys.stderr, msg % (etype, eid, rel), if fix: - session.system_sql("UPDATE %s SET %s=%(default)s WHERE eid=%s ;" - % (etype, rel, eid), {'default': default}) + session.system_sql("UPDATE %s SET %s=%%(v)s WHERE %s=%s ;" + % (table, column, eidcolumn, eid), + {'v': default}) print >> sys.stderr, ' [FIXED]' else: print >> sys.stderr - cursor = session.system_sql('SELECT MIN(eid) FROM euser;') + cursor = session.system_sql('SELECT MIN(%s) FROM %sEUser;' % (eidcolumn, + SQL_PREFIX)) default_user_eid = cursor.fetchone()[0] assert default_user_eid is not None, 'no user defined !' for rel, default in ( ('owned_by', default_user_eid), ): diff -r 5c20a7f13c84 -r af40e615dc89 server/migractions.py --- a/server/migractions.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/migractions.py Mon Apr 06 16:18:46 2009 +0200 @@ -34,10 +34,55 @@ try: from cubicweb.server import schemaserial as ss from cubicweb.server.utils import manager_userpasswd - from cubicweb.server.sqlutils import sqlexec + from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX except ImportError: # LAX pass +def set_sql_prefix(prefix): + """3.1.5 migration function: allow to unset/reset SQL_PREFIX""" + for module in ('checkintegrity', 'migractions', 'schemahooks', + 'sources.rql2sql', 'sources.native'): + try: + sys.modules['cubicweb.server.%s' % module].SQL_PREFIX = prefix + print 'changed SQL_PREFIX for %s' % module + except KeyError: + pass + +def update_database(repo): + """3.1.3 migration function: update database schema by adding SQL_PREFIX to + entity type tables and columns + """ + pool = repo._get_pool() + source = repo.system_source + sqlcu = pool['system'] + for etype in repo.schema.entities(): + if etype.is_final(): + continue + try: + sqlcu.execute('ALTER TABLE %s RENAME TO cw_%s' % (etype, etype)) + print 'renamed %s table for source %s' % (etype, uri) + except: + pass + for rschema in etype.subject_relations(): + if rschema == 'has_text': + continue + if rschema.is_final() or rschema.inlined: + if isinstance(source, SQLiteAbstractSource): + sqlcu.execute('ALTER TABLE cw_%s ADD COLUMN cw_%s' + % (etype, rschema)) + sqlcu.execute('UPDATE cw_%s SET %s=cw_%s' + % (etype, rschema, rschema)) + print 'added %s.cw_%s column for source %s' % ( + etype, rschema, uri) + else: + sqlcu.execute('ALTER TABLE cw_%s RENAME %s TO cw_%s' + % (etype, rschema, rschema)) + print 'renamed %s.%s column for source %s' % ( + etype, rschema, uri) + pool.commit() + repo._free_pool(pool) + + class ServerMigrationHelper(MigrationHelper): """specific migration helper for server side migration scripts, providind actions related to schema/data migration @@ -62,7 +107,17 @@ @cached def repo_connect(self): - self.repo = get_repository(method='inmemory', config=self.config) + try: + self.repo = get_repository(method='inmemory', config=self.config) + except: + import traceback + traceback.print_exc() + print '3.1.5 migration' + # XXX 3.1.5 migration + set_sql_prefix('') + self.repo = get_repository(method='inmemory', config=self.config) + update_database(self.repo) + set_sql_prefix('cw_') return self.repo def shutdown(self): @@ -1034,7 +1089,8 @@ and a sql database """ dbhelper = self.repo.system_source.dbhelper - tablesql = eschema2sql(dbhelper, self.repo.schema.eschema(etype)) + tablesql = eschema2sql(dbhelper, self.repo.schema.eschema(etype), + prefix=SQL_PREFIX) for sql in tablesql.split(';'): if sql.strip(): self.sqlexec(sql) diff -r 5c20a7f13c84 -r af40e615dc89 server/schemahooks.py --- a/server/schemahooks.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/schemahooks.py Mon Apr 06 16:18:46 2009 +0200 @@ -6,7 +6,7 @@ checking for schema consistency is done in hooks.py :organization: Logilab -:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" @@ -17,6 +17,7 @@ from cubicweb import ValidationError, RepositoryError from cubicweb.server import schemaserial as ss +from cubicweb.server.sqlutils import SQL_PREFIX from cubicweb.server.pool import Operation, SingleLastOperation, PreCommitOperation from cubicweb.server.hookhelper import (entity_attr, entity_name, check_internal_entity) @@ -44,19 +45,22 @@ def add_inline_relation_column(session, etype, rtype): """add necessary column and index for an inlined relation""" + table = SQL_PREFIX + etype + column = SQL_PREFIX + rtype try: session.system_sql(str('ALTER TABLE %s ADD COLUMN %s integer' - % (etype, rtype))) - session.info('added column %s to table %s', rtype, etype) + % (table, column))) + session.info('added column %s to table %s', column, table) except: # silent exception here, if this error has not been raised because the # column already exists, index creation will fail anyway - session.exception('error while adding column %s to table %s', etype, rtype) + session.exception('error while adding column %s to table %s', + table, column) # create index before alter table which may expectingly fail during test # (sqlite) while index creation should never fail (test for index existence # is done by the dbhelper) - session.pool.source('system').create_index(session, etype, rtype) - session.info('added index on %s(%s)', etype, rtype) + session.pool.source('system').create_index(session, table, column) + session.info('added index on %s(%s)', table, column) session.add_query_data('createdattrs', '%s.%s' % (etype, rtype)) @@ -148,7 +152,7 @@ name = check_internal_entity(session, eid, CORE_ETYPES) # delete every entities of this type session.unsafe_execute('DELETE %s X' % name) - DropTableOp(session, table=name) + DropTableOp(session, table=SQL_PREFIX + name) DeleteEETypeOp(session, name) def after_del_eetype(session, eid): @@ -223,7 +227,8 @@ 'R eid %%(x)s, X from_entity E, E name %%(name)s' % rdeftype, {'x': rteid, 'name': str(subjschema)}) if rset[0][0] == 0 and not subjschema.eid in pendings: - DropColumnOp(session, table=subjschema.type, column=rschema.type) + DropColumnOp(session, table=SQL_PREFIX + subjschema.type, + column=SQL_PREFIX + rschema.type) elif lastrel: DropTableOp(session, table='%s_relation' % rschema.type) # if this is the last instance, drop associated relation type @@ -270,7 +275,8 @@ eschema = schema.add_entity_type(etype) eschema.set_default_groups() # generate table sql and rql to add metadata - tablesql = eschema2sql(session.pool.source('system').dbhelper, eschema) + tablesql = eschema2sql(session.pool.source('system').dbhelper, eschema, + prefix=SQL_PREFIX) relrqls = [] for rtype in ('is', 'is_instance_of', 'creation_date', 'modification_date', 'created_by', 'owned_by'): @@ -393,22 +399,24 @@ extra_unique_index = False # added some str() wrapping query since some backend (eg psycopg) don't # allow unicode queries + table = SQL_PREFIX + subj + column = SQL_PREFIX + rtype try: session.system_sql(str('ALTER TABLE %s ADD COLUMN %s %s' - % (subj, rtype, attrtype))) - self.info('added column %s to table %s', rtype, subj) + % (table, column, attrtype))) + self.info('added column %s to table %s', table, column) except Exception, ex: # the column probably already exists. this occurs when # the entity's type has just been added or if the column # has not been previously dropped - self.error('error while altering table %s: %s', subj, ex) + self.error('error while altering table %s: %s', table, ex) if extra_unique_index or entity.indexed: try: - sysource.create_index(session, subj, rtype, + sysource.create_index(session, table, column, unique=extra_unique_index) except Exception, ex: self.error('error while creating index for %s.%s: %s', - subj, rtype, ex) + table, column, ex) # postgres doesn't implement, so do it in two times # ALTER TABLE %s ADD COLUMN %s %s SET DEFAULT %s if default is not None: @@ -416,12 +424,12 @@ default = default.encode(sysource.encoding) try: session.system_sql('ALTER TABLE %s ALTER COLUMN %s SET DEFAULT ' - '%%(default)s' % (subj, rtype), + '%%(default)s' % (table, column), {'default': default}) except Exception, ex: # not supported by sqlite for instance - self.error('error while altering table %s: %s', subj, ex) - session.system_sql('UPDATE %s SET %s=%%(default)s' % (subj, rtype), + self.error('error while altering table %s: %s', table, ex) + session.system_sql('UPDATE %s SET %s=%%(default)s' % (table, column), {'default': default}) AddErdefOp(session, rdef) @@ -534,7 +542,8 @@ def precommit_event(self): # we need sql to operate physical changes on the system database sqlexec = self.session.system_sql - sqlexec('ALTER TABLE %s RENAME TO %s' % (self.oldname, self.newname)) + sqlexec('ALTER TABLE %s%s RENAME TO %s%s' % (SQL_PREFIX, self.oldname, + SQL_PREFIX, self.newname)) self.info('renamed table %s to %s', self.oldname, self.newname) sqlexec('UPDATE entities SET type=%s WHERE type=%s', (self.newname, self.oldname)) @@ -551,7 +560,9 @@ def precommit_event(self): if 'indexed' in self.values: sysource = self.session.pool.source('system') - table, column = self.kobj[0], self.rschema.type + etype, rtype = self.kobj[0], self.rschema.type + table = SQL_PREFIX + etype + column = SQL_PREFIX + rtype if self.values['indexed']: sysource.create_index(self.session, table, column) else: @@ -561,6 +572,7 @@ # structure should be clean, not need to remove entity's relations # at this point self.rschema._rproperties[self.kobj].update(self.values) + def after_update_erdef(session, entity): desttype = entity.to_entity[0].name @@ -593,6 +605,7 @@ # inlined changed, make necessary physical changes! sqlexec = self.session.system_sql rtype = rschema.type + eidcolumn = SQL_PREFIX + 'eid' if not inlined: # need to create the relation if it has not been already done by another # event of the same transaction @@ -604,12 +617,15 @@ sqlexec(sql) session.add_query_data('createdtables', rschema.type) # copy existant data + column = SQL_PREFIX + rtype for etype in rschema.subjects(): - sqlexec('INSERT INTO %s_relation SELECT eid, %s FROM %s WHERE NOT %s IS NULL' - % (rtype, rtype, etype, rtype)) + table = SQL_PREFIX + str(etype) + sqlexec('INSERT INTO %s_relation SELECT %s, %s FROM %s WHERE NOT %s IS NULL' + % (rtype, eidcolumn, column, table, column)) # drop existant columns for etype in rschema.subjects(): - DropColumnOp(session, table=str(etype), column=rtype) + DropColumnOp(session, table=SQL_PREFIX + str(etype), + column=SQL_PREFIX + rtype) else: for etype in rschema.subjects(): try: @@ -625,13 +641,15 @@ # 'FROM %(rtype)s_relation ' # 'WHERE %(etype)s.eid=%(rtype)s_relation.eid_from' # % locals()) - cursor = sqlexec('SELECT eid_from, eid_to FROM %(etype)s, ' - '%(rtype)s_relation WHERE %(etype)s.eid=' + table = SQL_PREFIX + str(etype) + cursor = sqlexec('SELECT eid_from, eid_to FROM %(table)s, ' + '%(rtype)s_relation WHERE %(table)s.%(eidcolumn)s=' '%(rtype)s_relation.eid_from' % locals()) args = [{'val': eid_to, 'x': eid} for eid, eid_to in cursor.fetchall()] if args: - cursor.executemany('UPDATE %s SET %s=%%(val)s WHERE eid=%%(x)s' - % (etype, rtype), args) + column = SQL_PREFIX + rtype + cursor.executemany('UPDATE %s SET %s=%%(val)s WHERE %s=%%(x)s' + % (table, column, eidcolumn), args) # drop existant table DropTableOp(session, table='%s_relation' % rtype) @@ -677,20 +695,22 @@ self.cstr = rtype.constraint_by_type(subjtype, objtype, cstrtype) self._cstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value) self._cstr.eid = self.entity.eid + table = SQL_PREFIX + str(subjtype) + column = SQL_PREFIX + str(rtype) # alter the physical schema on size constraint changes if self._cstr.type() == 'SizeConstraint' and ( self.cstr is None or self.cstr.max != self._cstr.max): try: session.system_sql('ALTER TABLE %s ALTER COLUMN %s TYPE VARCHAR(%s)' - % (subjtype, rtype, self._cstr.max)) + % (table, column, self._cstr.max)) self.info('altered column %s of table %s: now VARCHAR(%s)', - rtype, subjtype, self._cstr.max) + column, table, self._cstr.max) except Exception, ex: # not supported by sqlite for instance - self.error('error while altering table %s: %s', subjtype, ex) + self.error('error while altering table %s: %s', table, ex) elif cstrtype == 'UniqueConstraint': session.pool.source('system').create_index( - self.session, str(subjtype), str(rtype), unique=True) + self.session, table, column, unique=True) def commit_event(self): if self.cancelled: @@ -700,32 +720,35 @@ self.constraints.remove(self.cstr) self.constraints.append(self._cstr) + def after_add_econstraint(session, entity): ConstraintOp(session, entity=entity) def after_update_econstraint(session, entity): ConstraintOp(session, entity=entity) + class DelConstraintOp(ConstraintOp): """actually remove a constraint of a relation definition""" def precommit_event(self): self.prepare_constraints(self.rtype, self.subjtype, self.objtype) cstrtype = self.cstr.type() + table = SQL_PREFIX + str(self.subjtype) + column = SQL_PREFIX + str(self.rtype) # alter the physical schema on size/unique constraint changes if cstrtype == 'SizeConstraint': try: self.session.system_sql('ALTER TABLE %s ALTER COLUMN %s TYPE TEXT' - % (self.subjtype, self.rtype)) + % (table, column)) self.info('altered column %s of table %s: now TEXT', - self.rtype, self.subjtype) + column, table) except Exception, ex: # not supported by sqlite for instance - self.error('error while altering table %s: %s', - self.subjtype, ex) + self.error('error while altering table %s: %s', table, ex) elif cstrtype == 'UniqueConstraint': self.session.pool.source('system').drop_index( - self.session, str(self.subjtype), str(self.rtype), unique=True) + self.session, table, column, unique=True) def commit_event(self): self.constraints.remove(self.cstr) diff -r 5c20a7f13c84 -r af40e615dc89 server/serverctl.py --- a/server/serverctl.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/serverctl.py Mon Apr 06 16:18:46 2009 +0200 @@ -475,7 +475,8 @@ raise ExecutionError('Error while retrieving the dump') rmcmd = 'ssh -t %s "rm -f /tmp/%s.dump"' % (host, appid) print rmcmd - if os.system(rmcmd) and not confirm('an error occured while deleting remote dump. Continue anyway?'): + if os.system(rmcmd) and not confirm( + 'an error occured while deleting remote dump. Continue anyway?'): raise ExecutionError('Error while deleting remote dump') def _local_dump(appid, output): diff -r 5c20a7f13c84 -r af40e615dc89 server/sources/__init__.py --- a/server/sources/__init__.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/sources/__init__.py Mon Apr 06 16:18:46 2009 +0200 @@ -11,6 +11,8 @@ from mx.DateTime import now, DateTimeDelta from cubicweb import set_log_methods +from cubicweb.server.sqlutils import SQL_PREFIX + class TimedCache(dict): def __init__(self, ttlm, ttls=0): @@ -78,7 +80,7 @@ pass def __repr__(self): - return '<%s source>' % self.uri + return '<%s source @%#x>' % (self.uri, id(self)) def __cmp__(self, other): """simple comparison function to get predictable source order, with the @@ -159,15 +161,18 @@ if not myeids: return # delete relations referencing one of those eids + eidcolum = SQL_PREFIX + 'eid' for rschema in self.schema.relations(): if rschema.is_final() or rschema.type == 'identity': continue if rschema.inlined: + column = SQL_PREFIX + rschema.type for subjtype in rschema.subjects(): + table = SQL_PREFIX + str(subjtype) for objtype in rschema.objects(subjtype): if self.support_entity(objtype): - sql = 'UPDATE %s SET %s = NULL WHERE eid IN (%s);' % ( - subjtype, rschema.type, myeids) + sql = 'UPDATE %s SET %s=NULL WHERE %s IN (%s);' % ( + table, column, eidcolum, myeids) session.system_sql(sql) break continue diff -r 5c20a7f13c84 -r af40e615dc89 server/sources/extlite.py --- a/server/sources/extlite.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/sources/extlite.py Mon Apr 06 16:18:46 2009 +0200 @@ -1,7 +1,7 @@ """provide an abstract class for external sources using a sqlite database helper :organization: Logilab -:copyright: 2007-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" @@ -12,7 +12,7 @@ from os.path import join, exists from cubicweb import server -from cubicweb.server.sqlutils import sqlexec, SQLAdapterMixIn +from cubicweb.server.sqlutils import SQL_PREFIX, sqlexec, SQLAdapterMixIn from cubicweb.server.sources import AbstractSource, native from cubicweb.server.sources.rql2sql import SQLGenerator @@ -122,7 +122,7 @@ for etype in self.support_entities: eschema = schema.eschema(etype) createsqls = eschema2sql(self.sqladapter.dbhelper, eschema, - skip_relations=('data',)) + skip_relations=('data',), prefix=SQL_PREFIX) sqlexec(createsqls, cu, withpb=False) for rtype in self.support_relations: rschema = schema.rschema(rtype) @@ -196,7 +196,7 @@ """ cu = session.pool[self.uri] attrs = self.sqladapter.preprocess_entity(entity) - sql = self.sqladapter.sqlgen.insert(str(entity.e_schema), attrs) + sql = self.sqladapter.sqlgen.insert(SQL_PREFIX + str(entity.e_schema), attrs) cu.execute(sql, attrs) def add_entity(self, session, entity): @@ -212,7 +212,7 @@ """ cu = session.pool[self.uri] attrs = self.sqladapter.preprocess_entity(entity) - sql = self.sqladapter.sqlgen.update(str(entity.e_schema), attrs, ['eid']) + sql = self.sqladapter.sqlgen.update(SQL_PREFIX + str(entity.e_schema), attrs, ['eid']) cu.execute(sql, attrs) def update_entity(self, session, entity): @@ -227,8 +227,8 @@ entity is deleted. """ sqlcursor = session.pool[self.uri] - attrs = {'eid': eid} - sql = self.sqladapter.sqlgen.delete(etype, attrs) + attrs = {SQL_PREFIX + 'eid': eid} + sql = self.sqladapter.sqlgen.delete(SQL_PREFIX + etype, attrs) sqlcursor.execute(sql, attrs) def delete_relation(self, session, subject, rtype, object): @@ -237,8 +237,9 @@ if rschema.inlined: if subject in session.query_data('pendingeids', ()): return - etype = session.describe(subject)[0] - sql = 'UPDATE %s SET %s=NULL WHERE eid=%%(eid)s' % (etype, rtype) + table = SQL_PREFIX + session.describe(subject)[0] + column = SQL_PREFIX + rtype + sql = 'UPDATE %s SET %s=NULL WHERE %seid=%%(eid)s' % (table, column, SQL_PREFIX) attrs = {'eid' : subject} else: attrs = {'eid_from': subject, 'eid_to': object} diff -r 5c20a7f13c84 -r af40e615dc89 server/sources/native.py --- a/server/sources/native.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/sources/native.py Mon Apr 06 16:18:46 2009 +0200 @@ -1,7 +1,7 @@ """Adapters for native cubicweb sources. :organization: Logilab -:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" @@ -18,7 +18,7 @@ from cubicweb import UnknownEid, AuthenticationError, Binary, server from cubicweb.server.utils import crypt_password -from cubicweb.server.sqlutils import SQLAdapterMixIn +from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn from cubicweb.server.rqlannotation import set_qdata from cubicweb.server.sources import AbstractSource from cubicweb.server.sources.rql2sql import SQLGenerator @@ -367,19 +367,19 @@ def add_entity(self, session, entity): """add a new entity to the source""" attrs = self.preprocess_entity(entity) - sql = self.sqlgen.insert(str(entity.e_schema), attrs) + sql = self.sqlgen.insert(SQL_PREFIX + str(entity.e_schema), attrs) self.doexec(session.pool[self.uri], sql, attrs) def update_entity(self, session, entity): """replace an entity in the source""" attrs = self.preprocess_entity(entity) - sql = self.sqlgen.update(str(entity.e_schema), attrs, ['eid']) + sql = self.sqlgen.update(SQL_PREFIX + str(entity.e_schema), attrs, [SQL_PREFIX + 'eid']) self.doexec(session.pool[self.uri], sql, attrs) def delete_entity(self, session, etype, eid): """delete an entity from the source""" - attrs = {'eid': eid} - sql = self.sqlgen.delete(etype, attrs) + attrs = {SQL_PREFIX + 'eid': eid} + sql = self.sqlgen.delete(SQL_PREFIX + etype, attrs) self.doexec(session.pool[self.uri], sql, attrs) def add_relation(self, session, subject, rtype, object): @@ -392,8 +392,10 @@ """delete a relation from the source""" rschema = self.schema.rschema(rtype) if rschema.inlined: - etype = session.describe(subject)[0] - sql = 'UPDATE %s SET %s=NULL WHERE eid=%%(eid)s' % (etype, rtype) + table = SQL_PREFIX + session.describe(subject)[0] + column = SQL_PREFIX + rtype + sql = 'UPDATE %s SET %s=NULL WHERE %seid=%%(eid)s' % (table, column, + SQL_PREFIX) attrs = {'eid' : subject} else: attrs = {'eid_from': subject, 'eid_to': object} diff -r 5c20a7f13c84 -r af40e615dc89 server/sources/rql2sql.py --- a/server/sources/rql2sql.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/sources/rql2sql.py Mon Apr 06 16:18:46 2009 +0200 @@ -38,6 +38,7 @@ Variable, ColumnAlias, Relation, SubQuery, Exists) from cubicweb import server +from cubicweb.server.sqlutils import SQL_PREFIX from cubicweb.server.utils import cleanup_solutions def _new_var(select, varname): @@ -765,7 +766,7 @@ if '%s.%s' % (lhs.name, attr) in self._varmap: lhssql = self._varmap['%s.%s' % (lhs.name, attr)] else: - lhssql = '%s.%s' % (self._var_table(lhs.variable), attr) + lhssql = '%s.%s%s' % (self._var_table(lhs.variable), SQL_PREFIX, attr) if not rhsvar is None: t2 = self._var_table(rhsvar) if t2 is None: @@ -806,7 +807,8 @@ if rhstable: assert rhstable is not None, rhsvar join += ' %s OUTER JOIN %s ON (%s.%s=%s)' % ( - outertype, self._state.tables[rhstable][1], rid, restrattr, rhssql) + outertype, self._state.tables[rhstable][1], rid, restrattr, + rhssql) toreplace.append(rhstable) self.replace_tables_by_outer_join(join, maintable, *toreplace) return '' @@ -846,7 +848,10 @@ try: lhssql = self._varmap['%s.%s' % (lhs.name, relation.r_type)] except KeyError: - lhssql = '%s.%s' % (table, relation.r_type) + if relation.r_type == 'eid': + lhssql = lhs.variable._q_sql + else: + lhssql = '%s.%s%s' % (table, SQL_PREFIX, relation.r_type) try: if relation._q_needcast == 'TODAY': sql = 'DATE(%s)%s' % (lhssql, rhssql) @@ -993,7 +998,7 @@ principal = variable.stinfo['principal'] if principal is None: vtablename = variable.name - self.add_table('entities AS %s' % variable.name, vtablename) + self.add_table('entities AS %s' % vtablename, vtablename) sql = '%s.eid' % vtablename if variable.stinfo['typerels']: # add additional restriction on entities.type column @@ -1058,8 +1063,8 @@ if self.schema.eschema(etype).is_final(): raise BadRQLQuery(var.stmt.root) table = var.name - sql = '%s.eid' % table - self.add_table('%s AS %s' % (etype, table), table, scope=scope) + sql = '%s.%seid' % (table, SQL_PREFIX) + self.add_table('%s%s AS %s' % (SQL_PREFIX, etype, table), table, scope=scope) return sql, table def _inlined_var_sql(self, var, rtype): @@ -1068,7 +1073,7 @@ scope = var.sqlscope is var.stmt and 0 or -1 self.add_table(sql.split('.', 1)[0], scope=scope) except KeyError: - sql = '%s.%s' % (self._var_table(var), rtype) + sql = '%s.%s%s' % (self._var_table(var), SQL_PREFIX, rtype) #self._state.done.add(var.name) return sql @@ -1091,7 +1096,7 @@ sql = self._varmap['%s.%s' % (linkedvar.name, rel.r_type)] except KeyError: linkedvar.accept(self) - sql = '%s.%s' % (linkedvar._q_sqltable, rel.r_type) + sql = '%s.%s%s' % (linkedvar._q_sqltable, SQL_PREFIX, rel.r_type) return sql # tables handling ######################################################### diff -r 5c20a7f13c84 -r af40e615dc89 server/sqlutils.py --- a/server/sqlutils.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/sqlutils.py Mon Apr 06 16:18:46 2009 +0200 @@ -1,7 +1,7 @@ """SQL utilities functions and classes. :organization: Logilab -:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" @@ -18,6 +18,7 @@ from cubicweb.server import SQL_CONNECT_HOOKS from cubicweb.server.utils import crypt_password, cartesian_product +SQL_PREFIX = 'cw_' def sqlexec(sqlstmts, cursor_or_execute, withpb=True, delimiter=';'): """execute sql statements ignoring DROP/ CREATE GROUP or USER statements @@ -58,7 +59,7 @@ indexer = get_indexer(driver) w(indexer.sql_grant_user(user)) w('') - w(grant_schema(schema, user, set_owner, skip_entities=skip_entities)) + w(grant_schema(schema, user, set_owner, skip_entities=skip_entities, prefix=SQL_PREFIX)) return '\n'.join(output) @@ -79,7 +80,7 @@ w(indexer.sql_init_fti()) w('') dbhelper = get_adv_func_helper(driver) - w(schema2sql(dbhelper, schema, + w(schema2sql(dbhelper, schema, prefix=SQL_PREFIX, skip_entities=skip_entities, skip_relations=skip_relations)) if dbhelper.users_support and user: w('') @@ -101,7 +102,7 @@ indexer = get_indexer(driver) w(indexer.sql_drop_fti()) w('') - w(dropschema2sql(schema, + w(dropschema2sql(schema, prefix=SQL_PREFIX, skip_entities=skip_entities, skip_relations=skip_relations)) return '\n'.join(output) @@ -179,7 +180,7 @@ def preprocess_entity(self, entity): """return a dictionary to use as extra argument to cursor.execute - to insert/update an entity + to insert/update an entity into a SQL database """ attrs = {} eschema = entity.e_schema @@ -198,7 +199,7 @@ value = crypt_password(value) elif isinstance(value, Binary): value = self.binary(value.getvalue()) - attrs[str(attr)] = value + attrs[SQL_PREFIX+str(attr)] = value return attrs diff -r 5c20a7f13c84 -r af40e615dc89 server/test/unittest_hooks.py --- a/server/test/unittest_hooks.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/test/unittest_hooks.py Mon Apr 06 16:18:46 2009 +0200 @@ -7,8 +7,9 @@ from logilab.common.testlib import TestCase, unittest_main from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions -from cubicweb.common import ConnectionError, RepositoryError, ValidationError -from cubicweb.server.repository import * +from cubicweb import ConnectionError, RepositoryError, ValidationError, AuthenticationError, BadConnectionId +from cubicweb.server.sqlutils import SQL_PREFIX +from cubicweb.server.repository import Repository orig_get_versions = Repository.get_versions @@ -250,7 +251,12 @@ repo.config._cubes = None repo.fill_schema() RepositoryBasedTC.setUp(self) - + + def index_exists(self, etype, attr, unique=False): + dbhelper = self.session.pool.source('system').dbhelper + sqlcursor = self.session.pool['system'] + return dbhelper.index_exists(sqlcursor, SQL_PREFIX + etype, SQL_PREFIX + attr, unique=unique) + def test_base(self): schema = self.repo.schema dbhelper = self.session.pool.source('system').dbhelper @@ -281,11 +287,11 @@ 'WHERE RT name "comments", E name "Societe2", C name "Comment"') self.failIf('nom' in schema['Societe2'].subject_relations()) self.failIf('concerne2' in schema['Societe2'].subject_relations()) - self.failIf(dbhelper.index_exists(sqlcursor, 'Societe2', 'nom')) + self.failIf(self.index_exists('Societe2', 'nom')) self.commit() self.failUnless('nom' in schema['Societe2'].subject_relations()) self.failUnless('concerne2' in schema['Societe2'].subject_relations()) - self.failUnless(dbhelper.index_exists(sqlcursor, 'Societe2', 'nom')) + self.failUnless(self.index_exists('Societe2', 'nom')) # now we should be able to insert and query Societe2 s2eid = self.execute('INSERT Societe2 X: X nom "logilab"')[0][0] self.execute('Societe2 X WHERE X nom "logilab"') @@ -304,11 +310,11 @@ # schema should be cleaned on delete (after commit) self.execute('DELETE EEType X WHERE X name "Societe2"') self.execute('DELETE ERType X WHERE X name "concerne2"') - self.failUnless(dbhelper.index_exists(sqlcursor, 'Societe2', 'nom')) + self.failUnless(self.index_exists('Societe2', 'nom')) self.failUnless(schema.has_entity('Societe2')) self.failUnless(schema.has_relation('concerne2')) self.commit() - self.failIf(dbhelper.index_exists(sqlcursor, 'Societe2', 'nom')) + self.failIf(self.index_exists('Societe2', 'nom')) self.failIf(schema.has_entity('Societe2')) self.failIf(schema.has_entity('concerne2')) @@ -385,7 +391,7 @@ self.failUnless(self.schema['inline2'].inlined) self.commit() self.failIf(self.schema['inline2'].inlined) - self.failIf(dbhelper.index_exists(sqlcursor, 'Personne', 'inline2')) + self.failIf(self.index_exists('Personne', 'inline2')) rset = self.execute('Any X, Y WHERE X inline2 Y') self.assertEquals(len(rset), 1) self.assertEquals(rset.rows[0], [peid, aeid]) @@ -398,7 +404,7 @@ self.failIf(self.schema['inline2'].inlined) self.commit() self.failUnless(self.schema['inline2'].inlined) - self.failUnless(dbhelper.index_exists(sqlcursor, 'Personne', 'inline2')) + self.failUnless(self.index_exists('Personne', 'inline2')) rset = self.execute('Any X, Y WHERE X inline2 Y') self.assertEquals(len(rset), 1) self.assertEquals(rset.rows[0], [peid, aeid]) @@ -409,39 +415,44 @@ try: self.execute('SET X indexed TRUE WHERE X relation_type R, R name "sujet"') self.failIf(self.schema['sujet'].rproperty('Affaire', 'String', 'indexed')) - self.failIf(dbhelper.index_exists(sqlcursor, 'Affaire', 'sujet')) + self.failIf(self.index_exists('Affaire', 'sujet')) self.commit() self.failUnless(self.schema['sujet'].rproperty('Affaire', 'String', 'indexed')) - self.failUnless(dbhelper.index_exists(sqlcursor, 'Affaire', 'sujet')) + self.failUnless(self.index_exists('Affaire', 'sujet')) finally: self.execute('SET X indexed FALSE WHERE X relation_type R, R name "sujet"') self.failUnless(self.schema['sujet'].rproperty('Affaire', 'String', 'indexed')) - self.failUnless(dbhelper.index_exists(sqlcursor, 'Affaire', 'sujet')) + self.failUnless(self.index_exists('Affaire', 'sujet')) self.commit() self.failIf(self.schema['sujet'].rproperty('Affaire', 'String', 'indexed')) - self.failIf(dbhelper.index_exists(sqlcursor, 'Affaire', 'sujet')) + self.failIf(self.index_exists('Affaire', 'sujet')) def test_unique_change(self): dbhelper = self.session.pool.source('system').dbhelper sqlcursor = self.session.pool['system'] try: - self.execute('INSERT EConstraint X: X cstrtype CT, DEF constrained_by X ' - 'WHERE CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,' - 'RT name "sujet", E name "Affaire"') - self.failIf(self.schema['Affaire'].has_unique_values('sujet')) - self.failIf(dbhelper.index_exists(sqlcursor, 'Affaire', 'sujet', unique=True)) - self.commit() - self.failUnless(self.schema['Affaire'].has_unique_values('sujet')) - self.failUnless(dbhelper.index_exists(sqlcursor, 'Affaire', 'sujet', unique=True)) + try: + self.execute('INSERT EConstraint X: X cstrtype CT, DEF constrained_by X ' + 'WHERE CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,' + 'RT name "sujet", E name "Affaire"') + self.failIf(self.schema['Affaire'].has_unique_values('sujet')) + self.failIf(self.index_exists('Affaire', 'sujet', unique=True)) + self.commit() + self.failUnless(self.schema['Affaire'].has_unique_values('sujet')) + self.failUnless(self.index_exists('Affaire', 'sujet', unique=True)) + except: + import traceback + traceback.print_exc() + raise finally: self.execute('DELETE DEF constrained_by X WHERE X cstrtype CT, ' 'CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,' 'RT name "sujet", E name "Affaire"') self.failUnless(self.schema['Affaire'].has_unique_values('sujet')) - self.failUnless(dbhelper.index_exists(sqlcursor, 'Affaire', 'sujet', unique=True)) + self.failUnless(self.index_exists('Affaire', 'sujet', unique=True)) self.commit() self.failIf(self.schema['Affaire'].has_unique_values('sujet')) - self.failIf(dbhelper.index_exists(sqlcursor, 'Affaire', 'sujet', unique=True)) + self.failIf(self.index_exists('Affaire', 'sujet', unique=True)) class WorkflowHooksTC(RepositoryBasedTC): diff -r 5c20a7f13c84 -r af40e615dc89 server/test/unittest_migractions.py --- a/server/test/unittest_migractions.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/test/unittest_migractions.py Mon Apr 06 16:18:46 2009 +0200 @@ -6,6 +6,8 @@ from logilab.common.testlib import TestCase, unittest_main from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions +from cubicweb.schema import CubicWebSchemaLoader +from cubicweb.server.sqlutils import SQL_PREFIX from cubicweb.server.repository import Repository from cubicweb.server.migractions import * @@ -29,7 +31,6 @@ repo.config._cubes = None repo.fill_schema() # hack to read the schema from data/migrschema - from cubicweb.schema import CubicWebSchemaLoader CubicWebSchemaLoader.main_schema_directory = 'migrschema' global migrschema migrschema = self.repo.config.load_schema() @@ -68,9 +69,9 @@ self.assertEquals(self.schema['shortpara'].subjects(), ('Note', )) self.assertEquals(self.schema['shortpara'].objects(), ('String', )) # test created column is actually a varchar(64) - notesql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' and name='Note'")[0][0] + notesql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' and name='%sNote'" % SQL_PREFIX)[0][0] fields = dict(x.strip().split()[:2] for x in notesql.split('(', 1)[1].rsplit(')', 1)[0].split(',')) - self.assertEquals(fields['shortpara'], 'varchar(64)') + self.assertEquals(fields['%sshortpara' % SQL_PREFIX], 'varchar(64)') self.mh.rollback() def test_add_datetime_with_default_value_attribute(self): diff -r 5c20a7f13c84 -r af40e615dc89 server/test/unittest_querier.py --- a/server/test/unittest_querier.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/test/unittest_querier.py Mon Apr 06 16:18:46 2009 +0200 @@ -9,7 +9,9 @@ from mx.DateTime import today, now, DateTimeType from rql import BadRQLQuery, RQLSyntaxError + from cubicweb import QueryError, Unauthorized +from cubicweb.server.sqlutils import SQL_PREFIX from cubicweb.server.utils import crypt_password from cubicweb.server.sources.native import make_schema @@ -468,6 +470,7 @@ self.assertEquals(rset.rows[0][0], self.ueid) def test_select_complex_sort(self): + self.skip('retry me once http://www.sqlite.org/cvstrac/tktview?tn=3773 is fixed') rset = self.execute('Any X ORDERBY X,D LIMIT 5 WHERE X creation_date D') result = rset.rows result.sort() @@ -1072,7 +1075,8 @@ self.assertRaises(Unauthorized, self.execute, "Any P WHERE X is EUser, X login 'bob', X upassword P") cursor = self.pool['system'] - cursor.execute("SELECT upassword from EUser WHERE login='bob'") + cursor.execute("SELECT %supassword from %sEUser WHERE %slogin='bob'" + % (SQL_PREFIX, SQL_PREFIX, SQL_PREFIX)) passwd = cursor.fetchone()[0].getvalue() self.assertEquals(passwd, crypt_password('toto', passwd[:2])) rset = self.execute("Any X WHERE X is EUser, X login 'bob', X upassword '%s'" % passwd) @@ -1085,7 +1089,8 @@ self.assertEquals(rset.description[0][0], 'EUser') rset = self.execute("SET X upassword %(pwd)s WHERE X is EUser, X login 'bob'", {'pwd': 'tutu'}) - cursor.execute("SELECT upassword from EUser WHERE login='bob'") + cursor.execute("SELECT %supassword from %sEUser WHERE %slogin='bob'" + % (SQL_PREFIX, SQL_PREFIX, SQL_PREFIX)) passwd = cursor.fetchone()[0].getvalue() self.assertEquals(passwd, crypt_password('tutu', passwd[:2])) rset = self.execute("Any X WHERE X is EUser, X login 'bob', X upassword '%s'" % passwd) @@ -1212,6 +1217,7 @@ cause: old variable ref inserted into a fresh rqlst copy (in RQLSpliter._complex_select_plan) """ + self.skip('retry me once http://www.sqlite.org/cvstrac/tktview?tn=3773 is fixed') self.execute('Any X ORDERBY D DESC WHERE X creation_date D') def test_nonregr_extra_joins(self): diff -r 5c20a7f13c84 -r af40e615dc89 server/test/unittest_repository.py --- a/server/test/unittest_repository.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/test/unittest_repository.py Mon Apr 06 16:18:46 2009 +0200 @@ -8,17 +8,18 @@ from copy import deepcopy from mx.DateTime import DateTimeType, now + from logilab.common.testlib import TestCase, unittest_main -from cubicweb.devtools.apptest import RepositoryBasedTC -from cubicweb.devtools.repotest import tuplify from yams.constraints import UniqueConstraint from cubicweb import BadConnectionId, RepositoryError, ValidationError, UnknownEid, AuthenticationError from cubicweb.schema import CubicWebSchema, RQLConstraint from cubicweb.dbapi import connect, repo_connect - +from cubicweb.devtools.apptest import RepositoryBasedTC +from cubicweb.devtools.repotest import tuplify from cubicweb.server import repository +from cubicweb.server.sqlutils import SQL_PREFIX # start name server anyway, process will fail if already running @@ -46,11 +47,16 @@ self.repo.config._cubes = None # avoid assertion error self.repo.fill_schema() pool = self.repo._get_pool() + table = SQL_PREFIX + 'EEType' + namecol = SQL_PREFIX + 'name' + finalcol = SQL_PREFIX + 'final' try: sqlcursor = pool['system'] - sqlcursor.execute('SELECT name FROM EEType WHERE final is NULL') + sqlcursor.execute('SELECT %s FROM %s WHERE %s is NULL' % ( + namecol, table, finalcol)) self.assertEquals(sqlcursor.fetchall(), []) - sqlcursor.execute('SELECT name FROM EEType WHERE final=%(final)s ORDER BY name', {'final': 'TRUE'}) + sqlcursor.execute('SELECT %s FROM %s WHERE %s=%%(final)s ORDER BY %s' + % (namecol, table, finalcol, namecol), {'final': 'TRUE'}) self.assertEquals(sqlcursor.fetchall(), [(u'Boolean',), (u'Bytes',), (u'Date',), (u'Datetime',), (u'Decimal',),(u'Float',), diff -r 5c20a7f13c84 -r af40e615dc89 server/test/unittest_rql2sql.py --- a/server/test/unittest_rql2sql.py Mon Apr 06 16:11:38 2009 +0200 +++ b/server/test/unittest_rql2sql.py Mon Apr 06 16:18:46 2009 +0200 @@ -31,111 +31,111 @@ PARSER = [ (r"Personne P WHERE P nom 'Zig\'oto';", - '''SELECT P.eid -FROM Personne AS P -WHERE P.nom=Zig\'oto'''), + '''SELECT P.cw_eid +FROM cw_Personne AS P +WHERE P.cw_nom=Zig\'oto'''), (r'Personne P WHERE P nom ~= "Zig\"oto%";', - '''SELECT P.eid -FROM Personne AS P -WHERE P.nom ILIKE Zig"oto%'''), + '''SELECT P.cw_eid +FROM cw_Personne AS P +WHERE P.cw_nom ILIKE Zig"oto%'''), ] BASIC = [ - + ("Any X WHERE X is Affaire", - '''SELECT X.eid -FROM Affaire AS X'''), + '''SELECT X.cw_eid +FROM cw_Affaire AS X'''), ("Any X WHERE X eid 0", '''SELECT 0'''), ("Personne P", - '''SELECT P.eid -FROM Personne AS P'''), + '''SELECT P.cw_eid +FROM cw_Personne AS P'''), ("Personne P WHERE P test TRUE", - '''SELECT P.eid -FROM Personne AS P -WHERE P.test=True'''), + '''SELECT P.cw_eid +FROM cw_Personne AS P +WHERE P.cw_test=True'''), ("Personne P WHERE P test false", - '''SELECT P.eid -FROM Personne AS P -WHERE P.test=False'''), + '''SELECT P.cw_eid +FROM cw_Personne AS P +WHERE P.cw_test=False'''), ("Personne P WHERE P eid -1", '''SELECT -1'''), ("Personne P LIMIT 20 OFFSET 10", - '''SELECT P.eid -FROM Personne AS P + '''SELECT P.cw_eid +FROM cw_Personne AS P LIMIT 20 OFFSET 10'''), ("Personne P WHERE S is Societe, P travaille S, S nom 'Logilab';", '''SELECT rel_travaille0.eid_from -FROM Societe AS S, travaille_relation AS rel_travaille0 -WHERE rel_travaille0.eid_to=S.eid AND S.nom=Logilab'''), +FROM cw_Societe AS S, travaille_relation AS rel_travaille0 +WHERE rel_travaille0.eid_to=S.cw_eid AND S.cw_nom=Logilab'''), ("Personne P WHERE P concerne A, A concerne S, S nom 'Logilab', S is Societe;", '''SELECT rel_concerne0.eid_from -FROM Societe AS S, concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1 -WHERE rel_concerne0.eid_to=rel_concerne1.eid_from AND rel_concerne1.eid_to=S.eid AND S.nom=Logilab'''), +FROM concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1, cw_Societe AS S +WHERE rel_concerne0.eid_to=rel_concerne1.eid_from AND rel_concerne1.eid_to=S.cw_eid AND S.cw_nom=Logilab'''), ("Note N WHERE X evaluee N, X nom 'Logilab';", '''SELECT rel_evaluee0.eid_to -FROM Division AS X, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=X.eid AND X.nom=Logilab +FROM cw_Division AS X, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=X.cw_eid AND X.cw_nom=Logilab UNION ALL SELECT rel_evaluee0.eid_to -FROM Personne AS X, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=X.eid AND X.nom=Logilab +FROM cw_Personne AS X, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=X.cw_eid AND X.cw_nom=Logilab UNION ALL SELECT rel_evaluee0.eid_to -FROM Societe AS X, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=X.eid AND X.nom=Logilab +FROM cw_Societe AS X, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=X.cw_eid AND X.cw_nom=Logilab UNION ALL SELECT rel_evaluee0.eid_to -FROM SubDivision AS X, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=X.eid AND X.nom=Logilab'''), +FROM cw_SubDivision AS X, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=X.cw_eid AND X.cw_nom=Logilab'''), ("Note N WHERE X evaluee N, X nom in ('Logilab', 'Caesium');", '''SELECT rel_evaluee0.eid_to -FROM Division AS X, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=X.eid AND X.nom IN(Logilab, Caesium) +FROM cw_Division AS X, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=X.cw_eid AND X.cw_nom IN(Logilab, Caesium) UNION ALL SELECT rel_evaluee0.eid_to -FROM Personne AS X, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=X.eid AND X.nom IN(Logilab, Caesium) +FROM cw_Personne AS X, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=X.cw_eid AND X.cw_nom IN(Logilab, Caesium) UNION ALL SELECT rel_evaluee0.eid_to -FROM Societe AS X, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=X.eid AND X.nom IN(Logilab, Caesium) +FROM cw_Societe AS X, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=X.cw_eid AND X.cw_nom IN(Logilab, Caesium) UNION ALL SELECT rel_evaluee0.eid_to -FROM SubDivision AS X, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=X.eid AND X.nom IN(Logilab, Caesium)'''), +FROM cw_SubDivision AS X, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=X.cw_eid AND X.cw_nom IN(Logilab, Caesium)'''), ("Any X WHERE X creation_date TODAY, X is Affaire", - '''SELECT X.eid -FROM Affaire AS X -WHERE DATE(X.creation_date)=CURRENT_DATE'''), + '''SELECT X.cw_eid +FROM cw_Affaire AS X +WHERE DATE(X.cw_creation_date)=CURRENT_DATE'''), ("Any N WHERE G is EGroup, G name N, E eid 12, E read_permission G", - '''SELECT G.name -FROM EGroup AS G, read_permission_relation AS rel_read_permission0 -WHERE rel_read_permission0.eid_from=12 AND rel_read_permission0.eid_to=G.eid'''), + '''SELECT G.cw_name +FROM cw_EGroup AS G, read_permission_relation AS rel_read_permission0 +WHERE rel_read_permission0.eid_from=12 AND rel_read_permission0.eid_to=G.cw_eid'''), ('Any Y WHERE U login "admin", U login Y', # stupid but valid... - """SELECT U.login -FROM EUser AS U -WHERE U.login=admin"""), + """SELECT U.cw_login +FROM cw_EUser AS U +WHERE U.cw_login=admin"""), ('Any T WHERE T tags X, X is State', '''SELECT rel_tags0.eid_from -FROM State AS X, tags_relation AS rel_tags0 -WHERE rel_tags0.eid_to=X.eid'''), +FROM cw_State AS X, tags_relation AS rel_tags0 +WHERE rel_tags0.eid_to=X.cw_eid'''), ('Any X,Y WHERE X eid 0, Y eid 1, X concerne Y', '''SELECT 0, 1 @@ -144,40 +144,40 @@ ("Any X WHERE X prenom 'lulu'," "EXISTS(X owned_by U, U in_group G, G name 'lulufanclub' OR G name 'managers');", - '''SELECT X.eid -FROM Personne AS X -WHERE X.prenom=lulu AND EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, in_group_relation AS rel_in_group1, EGroup AS G WHERE rel_owned_by0.eid_from=X.eid AND rel_in_group1.eid_from=rel_owned_by0.eid_to AND rel_in_group1.eid_to=G.eid AND ((G.name=lulufanclub) OR (G.name=managers)))'''), + '''SELECT X.cw_eid +FROM cw_Personne AS X +WHERE X.cw_prenom=lulu AND EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, in_group_relation AS rel_in_group1, cw_EGroup AS G WHERE rel_owned_by0.eid_from=X.cw_eid AND rel_in_group1.eid_from=rel_owned_by0.eid_to AND rel_in_group1.eid_to=G.cw_eid AND ((G.cw_name=lulufanclub) OR (G.cw_name=managers)))'''), ("Any X WHERE X prenom 'lulu'," "NOT EXISTS(X owned_by U, U in_group G, G name 'lulufanclub' OR G name 'managers');", - '''SELECT X.eid -FROM Personne AS X -WHERE X.prenom=lulu AND NOT EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, in_group_relation AS rel_in_group1, EGroup AS G WHERE rel_owned_by0.eid_from=X.eid AND rel_in_group1.eid_from=rel_owned_by0.eid_to AND rel_in_group1.eid_to=G.eid AND ((G.name=lulufanclub) OR (G.name=managers)))'''), + '''SELECT X.cw_eid +FROM cw_Personne AS X +WHERE X.cw_prenom=lulu AND NOT EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, in_group_relation AS rel_in_group1, cw_EGroup AS G WHERE rel_owned_by0.eid_from=X.cw_eid AND rel_in_group1.eid_from=rel_owned_by0.eid_to AND rel_in_group1.eid_to=G.cw_eid AND ((G.cw_name=lulufanclub) OR (G.cw_name=managers)))'''), ] ADVANCED= [ ("Societe S WHERE S nom 'Logilab' OR S nom 'Caesium'", - '''SELECT S.eid -FROM Societe AS S -WHERE ((S.nom=Logilab) OR (S.nom=Caesium))'''), + '''SELECT S.cw_eid +FROM cw_Societe AS S +WHERE ((S.cw_nom=Logilab) OR (S.cw_nom=Caesium))'''), ('Any X WHERE X nom "toto", X eid IN (9700, 9710, 1045, 674)', - '''SELECT X.eid -FROM Division AS X -WHERE X.nom=toto AND X.eid IN(9700, 9710, 1045, 674) + '''SELECT X.cw_eid +FROM cw_Division AS X +WHERE X.cw_nom=toto AND X.cw_eid IN(9700, 9710, 1045, 674) UNION ALL -SELECT X.eid -FROM Personne AS X -WHERE X.nom=toto AND X.eid IN(9700, 9710, 1045, 674) +SELECT X.cw_eid +FROM cw_Personne AS X +WHERE X.cw_nom=toto AND X.cw_eid IN(9700, 9710, 1045, 674) UNION ALL -SELECT X.eid -FROM Societe AS X -WHERE X.nom=toto AND X.eid IN(9700, 9710, 1045, 674) +SELECT X.cw_eid +FROM cw_Societe AS X +WHERE X.cw_nom=toto AND X.cw_eid IN(9700, 9710, 1045, 674) UNION ALL -SELECT X.eid -FROM SubDivision AS X -WHERE X.nom=toto AND X.eid IN(9700, 9710, 1045, 674)'''), +SELECT X.cw_eid +FROM cw_SubDivision AS X +WHERE X.cw_nom=toto AND X.cw_eid IN(9700, 9710, 1045, 674)'''), ('Any Y, COUNT(N) GROUPBY Y WHERE Y evaluee N;', '''SELECT rel_evaluee0.eid_from, COUNT(rel_evaluee0.eid_to) @@ -185,34 +185,34 @@ GROUP BY rel_evaluee0.eid_from'''), ("Any X WHERE X concerne B or C concerne X", - '''SELECT X.eid -FROM Affaire AS X, concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1 -WHERE ((rel_concerne0.eid_from=X.eid) OR (rel_concerne1.eid_to=X.eid))'''), + '''SELECT X.cw_eid +FROM concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1, cw_Affaire AS X +WHERE ((rel_concerne0.eid_from=X.cw_eid) OR (rel_concerne1.eid_to=X.cw_eid))'''), ("Any X WHERE X travaille S or X concerne A", - '''SELECT X.eid -FROM Personne AS X, concerne_relation AS rel_concerne1, travaille_relation AS rel_travaille0 -WHERE ((rel_travaille0.eid_from=X.eid) OR (rel_concerne1.eid_from=X.eid))'''), + '''SELECT X.cw_eid +FROM concerne_relation AS rel_concerne1, cw_Personne AS X, travaille_relation AS rel_travaille0 +WHERE ((rel_travaille0.eid_from=X.cw_eid) OR (rel_concerne1.eid_from=X.cw_eid))'''), ("Any N WHERE A evaluee N or N ecrit_par P", - '''SELECT N.eid -FROM Note AS N, evaluee_relation AS rel_evaluee0 -WHERE ((rel_evaluee0.eid_to=N.eid) OR (N.ecrit_par IS NOT NULL))'''), + '''SELECT N.cw_eid +FROM cw_Note AS N, evaluee_relation AS rel_evaluee0 +WHERE ((rel_evaluee0.eid_to=N.cw_eid) OR (N.cw_ecrit_par IS NOT NULL))'''), ("Any N WHERE A evaluee N or EXISTS(N todo_by U)", - '''SELECT N.eid -FROM Note AS N, evaluee_relation AS rel_evaluee0 -WHERE ((rel_evaluee0.eid_to=N.eid) OR (EXISTS(SELECT 1 FROM todo_by_relation AS rel_todo_by1 WHERE rel_todo_by1.eid_from=N.eid)))'''), + '''SELECT N.cw_eid +FROM cw_Note AS N, evaluee_relation AS rel_evaluee0 +WHERE ((rel_evaluee0.eid_to=N.cw_eid) OR (EXISTS(SELECT 1 FROM todo_by_relation AS rel_todo_by1 WHERE rel_todo_by1.eid_from=N.cw_eid)))'''), ("Any N WHERE A evaluee N or N todo_by U", - '''SELECT N.eid -FROM Note AS N, evaluee_relation AS rel_evaluee0, todo_by_relation AS rel_todo_by1 -WHERE ((rel_evaluee0.eid_to=N.eid) OR (rel_todo_by1.eid_from=N.eid))'''), + '''SELECT N.cw_eid +FROM cw_Note AS N, evaluee_relation AS rel_evaluee0, todo_by_relation AS rel_todo_by1 +WHERE ((rel_evaluee0.eid_to=N.cw_eid) OR (rel_todo_by1.eid_from=N.cw_eid))'''), ("Any X WHERE X concerne B or C concerne X, B eid 12, C eid 13", - '''SELECT X.eid -FROM Affaire AS X, concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1 -WHERE ((rel_concerne0.eid_from=X.eid AND rel_concerne0.eid_to=12) OR (rel_concerne1.eid_from=13 AND rel_concerne1.eid_to=X.eid))'''), + '''SELECT X.cw_eid +FROM concerne_relation AS rel_concerne0, concerne_relation AS rel_concerne1, cw_Affaire AS X +WHERE ((rel_concerne0.eid_from=X.cw_eid AND rel_concerne0.eid_to=12) OR (rel_concerne1.eid_from=13 AND rel_concerne1.eid_to=X.cw_eid))'''), ('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13', '''SELECT rel_created_by0.eid_from @@ -220,9 +220,9 @@ WHERE ((rel_concerne1.eid_from=rel_created_by0.eid_from AND rel_concerne1.eid_to=12) OR (rel_concerne2.eid_from=13 AND rel_concerne2.eid_to=rel_created_by0.eid_from))'''), ('Any P WHERE P travaille_subdivision S1 OR P travaille_subdivision S2, S1 nom "logilab", S2 nom "caesium"', - '''SELECT P.eid -FROM Personne AS P, SubDivision AS S1, SubDivision AS S2, travaille_subdivision_relation AS rel_travaille_subdivision0, travaille_subdivision_relation AS rel_travaille_subdivision1 -WHERE ((rel_travaille_subdivision0.eid_from=P.eid AND rel_travaille_subdivision0.eid_to=S1.eid) OR (rel_travaille_subdivision1.eid_from=P.eid AND rel_travaille_subdivision1.eid_to=S2.eid)) AND S1.nom=logilab AND S2.nom=caesium'''), + '''SELECT P.cw_eid +FROM cw_Personne AS P, cw_SubDivision AS S1, cw_SubDivision AS S2, travaille_subdivision_relation AS rel_travaille_subdivision0, travaille_subdivision_relation AS rel_travaille_subdivision1 +WHERE ((rel_travaille_subdivision0.eid_from=P.cw_eid AND rel_travaille_subdivision0.eid_to=S1.cw_eid) OR (rel_travaille_subdivision1.eid_from=P.cw_eid AND rel_travaille_subdivision1.eid_to=S2.cw_eid)) AND S1.cw_nom=logilab AND S2.cw_nom=caesium'''), ('Any X WHERE T tags X', '''SELECT rel_tags0.eid_to @@ -234,31 +234,31 @@ WHERE rel_in_basket0.eid_to=12'''), ('Any SEN,RN,OEN WHERE X from_entity SE, SE eid 44, X relation_type R, R eid 139, X to_entity OE, OE eid 42, R name RN, SE name SEN, OE name OEN', - '''SELECT SE.name, R.name, OE.name -FROM EEType AS OE, EEType AS SE, EFRDef AS X, ERType AS R -WHERE X.from_entity=44 AND SE.eid=44 AND X.relation_type=139 AND R.eid=139 AND X.to_entity=42 AND OE.eid=42 + '''SELECT SE.cw_name, R.cw_name, OE.cw_name +FROM cw_EEType AS OE, cw_EEType AS SE, cw_EFRDef AS X, cw_ERType AS R +WHERE X.cw_from_entity=44 AND SE.cw_eid=44 AND X.cw_relation_type=139 AND R.cw_eid=139 AND X.cw_to_entity=42 AND OE.cw_eid=42 UNION ALL -SELECT SE.name, R.name, OE.name -FROM EEType AS OE, EEType AS SE, ENFRDef AS X, ERType AS R -WHERE X.from_entity=44 AND SE.eid=44 AND X.relation_type=139 AND R.eid=139 AND X.to_entity=42 AND OE.eid=42'''), +SELECT SE.cw_name, R.cw_name, OE.cw_name +FROM cw_EEType AS OE, cw_EEType AS SE, cw_ENFRDef AS X, cw_ERType AS R +WHERE X.cw_from_entity=44 AND SE.cw_eid=44 AND X.cw_relation_type=139 AND R.cw_eid=139 AND X.cw_to_entity=42 AND OE.cw_eid=42'''), # Any O WHERE NOT S corrected_in O, S eid %(x)s, S concerns P, O version_of P, O in_state ST, NOT ST name "published", O modification_date MTIME ORDERBY MTIME DESC LIMIT 9 ('Any O WHERE NOT S ecrit_par O, S eid 1, S inline1 P, O inline2 P', - '''SELECT DISTINCT O.eid -FROM Note AS S, Personne AS O -WHERE (S.ecrit_par IS NULL OR S.ecrit_par!=O.eid) AND S.eid=1 AND O.inline2=S.inline1'''), + '''SELECT DISTINCT O.cw_eid +FROM cw_Note AS S, cw_Personne AS O +WHERE (S.cw_ecrit_par IS NULL OR S.cw_ecrit_par!=O.cw_eid) AND S.cw_eid=1 AND O.cw_inline2=S.cw_inline1'''), ('DISTINCT Any S ORDERBY stockproc(SI) WHERE NOT S ecrit_par O, S para SI', - '''SELECT T1.C0 FROM (SELECT DISTINCT S.eid AS C0, STOCKPROC(S.para) AS C1 -FROM Note AS S -WHERE S.ecrit_par IS NULL + '''SELECT T1.C0 FROM (SELECT DISTINCT S.cw_eid AS C0, STOCKPROC(S.cw_para) AS C1 +FROM cw_Note AS S +WHERE S.cw_ecrit_par IS NULL ORDER BY 2) AS T1'''), ('Any N WHERE N todo_by U, N is Note, U eid 2, N filed_under T, T eid 3', # N would actually be invarient if U eid 2 had given a specific type to U - '''SELECT N.eid -FROM Note AS N, filed_under_relation AS rel_filed_under1, todo_by_relation AS rel_todo_by0 -WHERE rel_todo_by0.eid_from=N.eid AND rel_todo_by0.eid_to=2 AND rel_filed_under1.eid_from=N.eid AND rel_filed_under1.eid_to=3'''), + '''SELECT N.cw_eid +FROM cw_Note AS N, filed_under_relation AS rel_filed_under1, todo_by_relation AS rel_todo_by0 +WHERE rel_todo_by0.eid_from=N.cw_eid AND rel_todo_by0.eid_to=2 AND rel_filed_under1.eid_from=N.cw_eid AND rel_filed_under1.eid_to=3'''), ('Any N WHERE N todo_by U, U eid 2, P evaluee N, P eid 3', '''SELECT rel_evaluee1.eid_to @@ -272,103 +272,103 @@ WHERE rel_owned_by0.eid_from=1 AND NOT EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by1 WHERE rel_owned_by1.eid_from=2 AND rel_owned_by0.eid_to=rel_owned_by1.eid_to)'''), ('Any GN WHERE X in_group G, G name GN, (G name "managers" OR EXISTS(X copain T, T login in ("comme", "cochon")))', - '''SELECT G.name -FROM EGroup AS G, in_group_relation AS rel_in_group0 -WHERE rel_in_group0.eid_to=G.eid AND ((G.name=managers) OR (EXISTS(SELECT 1 FROM copain_relation AS rel_copain1, EUser AS T WHERE rel_copain1.eid_from=rel_in_group0.eid_from AND rel_copain1.eid_to=T.eid AND T.login IN(comme, cochon))))'''), + '''SELECT G.cw_name +FROM cw_EGroup AS G, in_group_relation AS rel_in_group0 +WHERE rel_in_group0.eid_to=G.cw_eid AND ((G.cw_name=managers) OR (EXISTS(SELECT 1 FROM copain_relation AS rel_copain1, cw_EUser AS T WHERE rel_copain1.eid_from=rel_in_group0.eid_from AND rel_copain1.eid_to=T.cw_eid AND T.cw_login IN(comme, cochon))))'''), ('Any C WHERE C is Card, EXISTS(X documented_by C)', - """SELECT C.eid -FROM Card AS C -WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_to=C.eid)"""), + """SELECT C.cw_eid +FROM cw_Card AS C +WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_to=C.cw_eid)"""), ('Any C WHERE C is Card, EXISTS(X documented_by C, X eid 12)', - """SELECT C.eid -FROM Card AS C -WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_from=12 AND rel_documented_by0.eid_to=C.eid)"""), + """SELECT C.cw_eid +FROM cw_Card AS C +WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_from=12 AND rel_documented_by0.eid_to=C.cw_eid)"""), ('Any T WHERE C is Card, C title T, EXISTS(X documented_by C, X eid 12)', - """SELECT C.title -FROM Card AS C -WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_from=12 AND rel_documented_by0.eid_to=C.eid)"""), + """SELECT C.cw_title +FROM cw_Card AS C +WHERE EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by0 WHERE rel_documented_by0.eid_from=12 AND rel_documented_by0.eid_to=C.cw_eid)"""), ('Any GN,L WHERE X in_group G, X login L, G name GN, EXISTS(X copain T, T login L, T login IN("comme", "cochon"))', - '''SELECT G.name, X.login -FROM EGroup AS G, EUser AS X, in_group_relation AS rel_in_group0 -WHERE rel_in_group0.eid_from=X.eid AND rel_in_group0.eid_to=G.eid AND EXISTS(SELECT 1 FROM copain_relation AS rel_copain1, EUser AS T WHERE rel_copain1.eid_from=X.eid AND rel_copain1.eid_to=T.eid AND T.login=X.login AND T.login IN(comme, cochon))'''), + '''SELECT G.cw_name, X.cw_login +FROM cw_EGroup AS G, cw_EUser AS X, in_group_relation AS rel_in_group0 +WHERE rel_in_group0.eid_from=X.cw_eid AND rel_in_group0.eid_to=G.cw_eid AND EXISTS(SELECT 1 FROM copain_relation AS rel_copain1, cw_EUser AS T WHERE rel_copain1.eid_from=X.cw_eid AND rel_copain1.eid_to=T.cw_eid AND T.cw_login=X.cw_login AND T.cw_login IN(comme, cochon))'''), ('Any X,S, MAX(T) GROUPBY X,S ORDERBY S WHERE X is EUser, T tags X, S eid IN(32), X in_state S', - '''SELECT X.eid, 32, MAX(rel_tags0.eid_from) -FROM EUser AS X, tags_relation AS rel_tags0 -WHERE rel_tags0.eid_to=X.eid AND X.in_state=32 -GROUP BY X.eid'''), + '''SELECT X.cw_eid, 32, MAX(rel_tags0.eid_from) +FROM cw_EUser AS X, tags_relation AS rel_tags0 +WHERE rel_tags0.eid_to=X.cw_eid AND X.cw_in_state=32 +GROUP BY X.cw_eid'''), ('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 WHERE S is Affaire, C is Societe, S concerne C, C nom CS, (EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))', - '''SELECT COUNT(rel_concerne0.eid_from), C.nom -FROM Societe AS C, concerne_relation AS rel_concerne0 -WHERE rel_concerne0.eid_to=C.eid AND ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by1 WHERE rel_concerne0.eid_from=rel_owned_by1.eid_from AND rel_owned_by1.eid_to=1)) OR (EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by2, Card AS N WHERE rel_concerne0.eid_from=rel_documented_by2.eid_from AND rel_documented_by2.eid_to=N.eid AND N.title=published))) -GROUP BY C.nom + '''SELECT COUNT(rel_concerne0.eid_from), C.cw_nom +FROM concerne_relation AS rel_concerne0, cw_Societe AS C +WHERE rel_concerne0.eid_to=C.cw_eid AND ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by1 WHERE rel_concerne0.eid_from=rel_owned_by1.eid_from AND rel_owned_by1.eid_to=1)) OR (EXISTS(SELECT 1 FROM documented_by_relation AS rel_documented_by2, cw_Card AS N WHERE rel_concerne0.eid_from=rel_documented_by2.eid_from AND rel_documented_by2.eid_to=N.cw_eid AND N.cw_title=published))) +GROUP BY C.cw_nom ORDER BY 1 DESC LIMIT 10'''), ('Any X WHERE Y evaluee X, Y is EUser', '''SELECT rel_evaluee0.eid_to -FROM EUser AS Y, evaluee_relation AS rel_evaluee0 -WHERE rel_evaluee0.eid_from=Y.eid'''), +FROM cw_EUser AS Y, evaluee_relation AS rel_evaluee0 +WHERE rel_evaluee0.eid_from=Y.cw_eid'''), ('Any L WHERE X login "admin", X identity Y, Y login L', - '''SELECT Y.login -FROM EUser AS X, EUser AS Y -WHERE X.login=admin AND X.eid=Y.eid'''), + '''SELECT Y.cw_login +FROM cw_EUser AS X, cw_EUser AS Y +WHERE X.cw_login=admin AND X.cw_eid=Y.cw_eid'''), ('Any L WHERE X login "admin", NOT X identity Y, Y login L', - '''SELECT Y.login -FROM EUser AS X, EUser AS Y -WHERE X.login=admin AND NOT X.eid=Y.eid'''), + '''SELECT Y.cw_login +FROM cw_EUser AS X, cw_EUser AS Y +WHERE X.cw_login=admin AND NOT X.cw_eid=Y.cw_eid'''), ('Any L WHERE X login "admin", X identity Y?, Y login L', - '''SELECT Y.login -FROM EUser AS X LEFT OUTER JOIN EUser AS Y ON (X.eid=Y.eid) -WHERE X.login=admin'''), + '''SELECT Y.cw_login +FROM cw_EUser AS X LEFT OUTER JOIN cw_EUser AS Y ON (X.cw_eid=Y.cw_eid) +WHERE X.cw_login=admin'''), ('Any XN ORDERBY XN WHERE X name XN', - '''SELECT X.name -FROM Basket AS X + '''SELECT X.cw_name +FROM cw_Basket AS X UNION ALL -SELECT X.name -FROM ECache AS X +SELECT X.cw_name +FROM cw_ECache AS X UNION ALL -SELECT X.name -FROM EConstraintType AS X +SELECT X.cw_name +FROM cw_EConstraintType AS X UNION ALL -SELECT X.name -FROM EEType AS X +SELECT X.cw_name +FROM cw_EEType AS X UNION ALL -SELECT X.name -FROM EGroup AS X +SELECT X.cw_name +FROM cw_EGroup AS X UNION ALL -SELECT X.name -FROM EPermission AS X +SELECT X.cw_name +FROM cw_EPermission AS X UNION ALL -SELECT X.name -FROM ERType AS X +SELECT X.cw_name +FROM cw_ERType AS X UNION ALL -SELECT X.name -FROM File AS X +SELECT X.cw_name +FROM cw_File AS X UNION ALL -SELECT X.name -FROM Folder AS X +SELECT X.cw_name +FROM cw_Folder AS X UNION ALL -SELECT X.name -FROM Image AS X +SELECT X.cw_name +FROM cw_Image AS X UNION ALL -SELECT X.name -FROM State AS X +SELECT X.cw_name +FROM cw_State AS X UNION ALL -SELECT X.name -FROM Tag AS X +SELECT X.cw_name +FROM cw_Tag AS X UNION ALL -SELECT X.name -FROM Transition AS X +SELECT X.cw_name +FROM cw_Transition AS X ORDER BY 1'''), # ('Any XN WHERE X name XN GROUPBY XN', @@ -378,180 +378,180 @@ # DISTINCT, can use relatin under exists scope as principal ('DISTINCT Any X,Y WHERE X name "EGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)', - '''SELECT DISTINCT X.eid, rel_read_permission0.eid_to -FROM EEType AS X, read_permission_relation AS rel_read_permission0 -WHERE X.name=EGroup AND rel_read_permission0.eid_to IN(1, 2, 3) AND EXISTS(SELECT 1 WHERE rel_read_permission0.eid_from=X.eid) + '''SELECT DISTINCT X.cw_eid, rel_read_permission0.eid_to +FROM cw_EEType AS X, read_permission_relation AS rel_read_permission0 +WHERE X.cw_name=EGroup AND rel_read_permission0.eid_to IN(1, 2, 3) AND EXISTS(SELECT 1 WHERE rel_read_permission0.eid_from=X.cw_eid) UNION -SELECT DISTINCT X.eid, rel_read_permission0.eid_to -FROM ERType AS X, read_permission_relation AS rel_read_permission0 -WHERE X.name=EGroup AND rel_read_permission0.eid_to IN(1, 2, 3) AND EXISTS(SELECT 1 WHERE rel_read_permission0.eid_from=X.eid)'''), +SELECT DISTINCT X.cw_eid, rel_read_permission0.eid_to +FROM cw_ERType AS X, read_permission_relation AS rel_read_permission0 +WHERE X.cw_name=EGroup AND rel_read_permission0.eid_to IN(1, 2, 3) AND EXISTS(SELECT 1 WHERE rel_read_permission0.eid_from=X.cw_eid)'''), # no distinct, Y can't be invariant ('Any X,Y WHERE X name "EGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)', - '''SELECT X.eid, Y.eid -FROM EEType AS X, EGroup AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) + '''SELECT X.cw_eid, Y.cw_eid +FROM cw_EEType AS X, cw_EGroup AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION ALL -SELECT X.eid, Y.eid -FROM EEType AS X, RQLExpression AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) +SELECT X.cw_eid, Y.cw_eid +FROM cw_EEType AS X, cw_RQLExpression AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION ALL -SELECT X.eid, Y.eid -FROM EGroup AS Y, ERType AS X -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) +SELECT X.cw_eid, Y.cw_eid +FROM cw_EGroup AS Y, cw_ERType AS X +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION ALL -SELECT X.eid, Y.eid -FROM ERType AS X, RQLExpression AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid)'''), +SELECT X.cw_eid, Y.cw_eid +FROM cw_ERType AS X, cw_RQLExpression AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid)'''), # DISTINCT but NEGED exists, can't be invariant ('DISTINCT Any X,Y WHERE X name "EGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)', - '''SELECT DISTINCT X.eid, Y.eid -FROM EEType AS X, EGroup AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) + '''SELECT DISTINCT X.cw_eid, Y.cw_eid +FROM cw_EEType AS X, cw_EGroup AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION -SELECT DISTINCT X.eid, Y.eid -FROM EEType AS X, RQLExpression AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) +SELECT DISTINCT X.cw_eid, Y.cw_eid +FROM cw_EEType AS X, cw_RQLExpression AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION -SELECT DISTINCT X.eid, Y.eid -FROM EGroup AS Y, ERType AS X -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) +SELECT DISTINCT X.cw_eid, Y.cw_eid +FROM cw_EGroup AS Y, cw_ERType AS X +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION -SELECT DISTINCT X.eid, Y.eid -FROM ERType AS X, RQLExpression AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid)'''), +SELECT DISTINCT X.cw_eid, Y.cw_eid +FROM cw_ERType AS X, cw_RQLExpression AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid)'''), # should generate the same query as above ('DISTINCT Any X,Y WHERE X name "EGroup", Y eid IN(1, 2, 3), NOT X read_permission Y', - '''SELECT DISTINCT X.eid, Y.eid -FROM EEType AS X, EGroup AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) + '''SELECT DISTINCT X.cw_eid, Y.cw_eid +FROM cw_EEType AS X, cw_EGroup AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION -SELECT DISTINCT X.eid, Y.eid -FROM EEType AS X, RQLExpression AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) +SELECT DISTINCT X.cw_eid, Y.cw_eid +FROM cw_EEType AS X, cw_RQLExpression AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION -SELECT DISTINCT X.eid, Y.eid -FROM EGroup AS Y, ERType AS X -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) +SELECT DISTINCT X.cw_eid, Y.cw_eid +FROM cw_EGroup AS Y, cw_ERType AS X +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION -SELECT DISTINCT X.eid, Y.eid -FROM ERType AS X, RQLExpression AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid)'''), +SELECT DISTINCT X.cw_eid, Y.cw_eid +FROM cw_ERType AS X, cw_RQLExpression AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid)'''), # neged relation, can't be inveriant ('Any X,Y WHERE X name "EGroup", Y eid IN(1, 2, 3), NOT X read_permission Y', - '''SELECT X.eid, Y.eid -FROM EEType AS X, EGroup AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) + '''SELECT X.cw_eid, Y.cw_eid +FROM cw_EEType AS X, cw_EGroup AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION ALL -SELECT X.eid, Y.eid -FROM EEType AS X, RQLExpression AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) +SELECT X.cw_eid, Y.cw_eid +FROM cw_EEType AS X, cw_RQLExpression AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION ALL -SELECT X.eid, Y.eid -FROM EGroup AS Y, ERType AS X -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid) +SELECT X.cw_eid, Y.cw_eid +FROM cw_EGroup AS Y, cw_ERType AS X +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid) UNION ALL -SELECT X.eid, Y.eid -FROM ERType AS X, RQLExpression AS Y -WHERE X.name=EGroup AND Y.eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.eid AND rel_read_permission0.eid_to=Y.eid)'''), +SELECT X.cw_eid, Y.cw_eid +FROM cw_ERType AS X, cw_RQLExpression AS Y +WHERE X.cw_name=EGroup AND Y.cw_eid IN(1, 2, 3) AND NOT EXISTS(SELECT 1 FROM read_permission_relation AS rel_read_permission0 WHERE rel_read_permission0.eid_from=X.cw_eid AND rel_read_permission0.eid_to=Y.cw_eid)'''), ('Any MAX(X)+MIN(X), N GROUPBY N WHERE X name N;', - '''SELECT (MAX(T1.C0) + MIN(T1.C0)), T1.C1 FROM (SELECT X.eid AS C0, X.name AS C1 -FROM Basket AS X + '''SELECT (MAX(T1.C0) + MIN(T1.C0)), T1.C1 FROM (SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_Basket AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM ECache AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_ECache AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM EConstraintType AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_EConstraintType AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM EEType AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_EEType AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM EGroup AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_EGroup AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM EPermission AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_EPermission AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM ERType AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_ERType AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM File AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_File AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM Folder AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_Folder AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM Image AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_Image AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM State AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_State AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM Tag AS X +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_Tag AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM Transition AS X) AS T1 +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_Transition AS X) AS T1 GROUP BY T1.C1'''), ('Any MAX(X)+MIN(LENGTH(D)), N GROUPBY N ORDERBY 1, N, DF WHERE X name N, X data D, X data_format DF;', - '''SELECT (MAX(T1.C1) + MIN(LENGTH(T1.C0))), T1.C2 FROM (SELECT X.data AS C0, X.eid AS C1, X.name AS C2, X.data_format AS C3 -FROM File AS X + '''SELECT (MAX(T1.C1) + MIN(LENGTH(T1.C0))), T1.C2 FROM (SELECT X.cw_data AS C0, X.cw_eid AS C1, X.cw_name AS C2, X.cw_data_format AS C3 +FROM cw_File AS X UNION ALL -SELECT X.data AS C0, X.eid AS C1, X.name AS C2, X.data_format AS C3 -FROM Image AS X) AS T1 +SELECT X.cw_data AS C0, X.cw_eid AS C1, X.cw_name AS C2, X.cw_data_format AS C3 +FROM cw_Image AS X) AS T1 GROUP BY T1.C2 ORDER BY 1,2,T1.C3'''), ('DISTINCT Any S ORDERBY R WHERE A is Affaire, A sujet S, A ref R', - '''SELECT T1.C0 FROM (SELECT DISTINCT A.sujet AS C0, A.ref AS C1 -FROM Affaire AS A + '''SELECT T1.C0 FROM (SELECT DISTINCT A.cw_sujet AS C0, A.cw_ref AS C1 +FROM cw_Affaire AS A ORDER BY 2) AS T1'''), ('DISTINCT Any MAX(X)+MIN(LENGTH(D)), N GROUPBY N ORDERBY 2, DF WHERE X name N, X data D, X data_format DF;', - '''SELECT T1.C0,T1.C1 FROM (SELECT DISTINCT (MAX(T1.C1) + MIN(LENGTH(T1.C0))) AS C0, T1.C2 AS C1, T1.C3 AS C2 FROM (SELECT DISTINCT X.data AS C0, X.eid AS C1, X.name AS C2, X.data_format AS C3 -FROM File AS X + '''SELECT T1.C0,T1.C1 FROM (SELECT DISTINCT (MAX(T1.C1) + MIN(LENGTH(T1.C0))) AS C0, T1.C2 AS C1, T1.C3 AS C2 FROM (SELECT DISTINCT X.cw_data AS C0, X.cw_eid AS C1, X.cw_name AS C2, X.cw_data_format AS C3 +FROM cw_File AS X UNION -SELECT DISTINCT X.data AS C0, X.eid AS C1, X.name AS C2, X.data_format AS C3 -FROM Image AS X) AS T1 +SELECT DISTINCT X.cw_data AS C0, X.cw_eid AS C1, X.cw_name AS C2, X.cw_data_format AS C3 +FROM cw_Image AS X) AS T1 GROUP BY T1.C2,T1.C3 ORDER BY 2,3) AS T1 '''), # ambiguity in EXISTS() -> should union the sub-query ('Any T WHERE T is Tag, NOT T name in ("t1", "t2"), EXISTS(T tags X, X is IN (EUser, EGroup))', - '''SELECT T.eid -FROM Tag AS T -WHERE NOT (T.name IN(t1, t2)) AND EXISTS(SELECT 1 FROM tags_relation AS rel_tags0, EGroup AS X WHERE rel_tags0.eid_from=T.eid AND rel_tags0.eid_to=X.eid UNION SELECT 1 FROM tags_relation AS rel_tags1, EUser AS X WHERE rel_tags1.eid_from=T.eid AND rel_tags1.eid_to=X.eid)'''), + '''SELECT T.cw_eid +FROM cw_Tag AS T +WHERE NOT (T.cw_name IN(t1, t2)) AND EXISTS(SELECT 1 FROM tags_relation AS rel_tags0, cw_EGroup AS X WHERE rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=X.cw_eid UNION SELECT 1 FROM tags_relation AS rel_tags1, cw_EUser AS X WHERE rel_tags1.eid_from=T.cw_eid AND rel_tags1.eid_to=X.cw_eid)'''), # must not use a relation in EXISTS scope to inline a variable ('Any U WHERE U eid IN (1,2), EXISTS(X owned_by U)', - '''SELECT U.eid -FROM EUser AS U -WHERE U.eid IN(1, 2) AND EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_to=U.eid)'''), + '''SELECT U.cw_eid +FROM cw_EUser AS U +WHERE U.cw_eid IN(1, 2) AND EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_to=U.cw_eid)'''), ('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)', - '''SELECT U.eid -FROM EUser AS U -WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE U.eid IN(1, 2) AND rel_owned_by0.eid_to=U.eid)'''), + '''SELECT U.cw_eid +FROM cw_EUser AS U +WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE U.cw_eid IN(1, 2) AND rel_owned_by0.eid_to=U.cw_eid)'''), ('Any COUNT(U) WHERE EXISTS (P owned_by U, P is IN (Note, Affaire))', - '''SELECT COUNT(U.eid) -FROM EUser AS U -WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, Affaire AS P WHERE rel_owned_by0.eid_from=P.eid AND rel_owned_by0.eid_to=U.eid UNION SELECT 1 FROM owned_by_relation AS rel_owned_by1, Note AS P WHERE rel_owned_by1.eid_from=P.eid AND rel_owned_by1.eid_to=U.eid)'''), + '''SELECT COUNT(U.cw_eid) +FROM cw_EUser AS U +WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, cw_Affaire AS P WHERE rel_owned_by0.eid_from=P.cw_eid AND rel_owned_by0.eid_to=U.cw_eid UNION SELECT 1 FROM owned_by_relation AS rel_owned_by1, cw_Note AS P WHERE rel_owned_by1.eid_from=P.cw_eid AND rel_owned_by1.eid_to=U.cw_eid)'''), ('Any MAX(X)', '''SELECT MAX(X.eid) FROM entities AS X'''), ('Any MAX(X) WHERE X is Note', - '''SELECT MAX(X.eid) -FROM Note AS X'''), + '''SELECT MAX(X.cw_eid) +FROM cw_Note AS X'''), ('Any X WHERE X eid > 12', '''SELECT X.eid @@ -564,17 +564,17 @@ WHERE X.type='Note' AND X.eid>12"""), ('Any X, T WHERE X eid > 12, X title T', - """SELECT X.eid, X.title -FROM Bookmark AS X -WHERE X.eid>12 + """SELECT X.cw_eid, X.cw_title +FROM cw_Bookmark AS X +WHERE X.cw_eid>12 UNION ALL -SELECT X.eid, X.title -FROM Card AS X -WHERE X.eid>12 +SELECT X.cw_eid, X.cw_title +FROM cw_Card AS X +WHERE X.cw_eid>12 UNION ALL -SELECT X.eid, X.title -FROM EmailThread AS X -WHERE X.eid>12"""), +SELECT X.cw_eid, X.cw_title +FROM cw_EmailThread AS X +WHERE X.cw_eid>12"""), ('Any X', '''SELECT X.eid @@ -584,11 +584,11 @@ '''SELECT 12'''), ('Any X GROUPBY X ORDERBY Y WHERE X eid 12, X login Y', - '''SELECT X.eid -FROM EUser AS X -WHERE X.eid=12 -GROUP BY X.eid -ORDER BY X.login'''), + '''SELECT X.cw_eid +FROM cw_EUser AS X +WHERE X.cw_eid=12 +GROUP BY X.cw_eid +ORDER BY X.cw_login'''), ('Any U,COUNT(X) GROUPBY U WHERE U eid 12, X owned_by U HAVING COUNT(X) > 10', '''SELECT rel_owned_by0.eid_to, COUNT(rel_owned_by0.eid_from) @@ -598,80 +598,80 @@ HAVING COUNT(rel_owned_by0.eid_from)>10'''), ('DISTINCT Any X ORDERBY stockproc(X) WHERE U login X', - '''SELECT T1.C0 FROM (SELECT DISTINCT U.login AS C0, STOCKPROC(U.login) AS C1 -FROM EUser AS U + '''SELECT T1.C0 FROM (SELECT DISTINCT U.cw_login AS C0, STOCKPROC(U.cw_login) AS C1 +FROM cw_EUser AS U ORDER BY 2) AS T1'''), ('DISTINCT Any X ORDERBY Y WHERE B bookmarked_by X, X login Y', - '''SELECT T1.C0 FROM (SELECT DISTINCT X.eid AS C0, X.login AS C1 -FROM EUser AS X, bookmarked_by_relation AS rel_bookmarked_by0 -WHERE rel_bookmarked_by0.eid_to=X.eid + '''SELECT T1.C0 FROM (SELECT DISTINCT X.cw_eid AS C0, X.cw_login AS C1 +FROM bookmarked_by_relation AS rel_bookmarked_by0, cw_EUser AS X +WHERE rel_bookmarked_by0.eid_to=X.cw_eid ORDER BY 2) AS T1'''), ('DISTINCT Any X ORDERBY SN WHERE X in_state S, S name SN', - '''SELECT T1.C0 FROM (SELECT DISTINCT X.eid AS C0, S.name AS C1 -FROM Affaire AS X, State AS S -WHERE X.in_state=S.eid + '''SELECT T1.C0 FROM (SELECT DISTINCT X.cw_eid AS C0, S.cw_name AS C1 +FROM cw_Affaire AS X, cw_State AS S +WHERE X.cw_in_state=S.cw_eid UNION -SELECT DISTINCT X.eid AS C0, S.name AS C1 -FROM EUser AS X, State AS S -WHERE X.in_state=S.eid +SELECT DISTINCT X.cw_eid AS C0, S.cw_name AS C1 +FROM cw_EUser AS X, cw_State AS S +WHERE X.cw_in_state=S.cw_eid UNION -SELECT DISTINCT X.eid AS C0, S.name AS C1 -FROM Note AS X, State AS S -WHERE X.in_state=S.eid +SELECT DISTINCT X.cw_eid AS C0, S.cw_name AS C1 +FROM cw_Note AS X, cw_State AS S +WHERE X.cw_in_state=S.cw_eid ORDER BY 2) AS T1'''), ] MULTIPLE_SEL = [ ("DISTINCT Any X,Y where P is Personne, P nom X , P prenom Y;", - '''SELECT DISTINCT P.nom, P.prenom -FROM Personne AS P'''), + '''SELECT DISTINCT P.cw_nom, P.cw_prenom +FROM cw_Personne AS P'''), ("Any X,Y where P is Personne, P nom X , P prenom Y, not P nom NULL;", - '''SELECT P.nom, P.prenom -FROM Personne AS P -WHERE NOT (P.nom IS NULL)'''), + '''SELECT P.cw_nom, P.cw_prenom +FROM cw_Personne AS P +WHERE NOT (P.cw_nom IS NULL)'''), ("Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE", - '''SELECT X.eid, Y.eid -FROM Personne AS X, Personne AS Y -WHERE Y.nom=X.nom AND NOT (Y.eid=X.eid)''') + '''SELECT X.cw_eid, Y.cw_eid +FROM cw_Personne AS X, cw_Personne AS Y +WHERE Y.cw_nom=X.cw_nom AND NOT (Y.cw_eid=X.cw_eid)''') ] NEGATIONS = [ ("Personne X WHERE NOT X evaluee Y;", - '''SELECT X.eid -FROM Personne AS X -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=X.eid)'''), + '''SELECT X.cw_eid +FROM cw_Personne AS X +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=X.cw_eid)'''), ("Note N WHERE NOT X evaluee N, X eid 0", - '''SELECT N.eid -FROM Note AS N -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=0 AND rel_evaluee0.eid_to=N.eid)'''), + '''SELECT N.cw_eid +FROM cw_Note AS N +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=0 AND rel_evaluee0.eid_to=N.cw_eid)'''), ('Any X WHERE NOT X travaille S, X is Personne', - '''SELECT X.eid -FROM Personne AS X -WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=X.eid)'''), + '''SELECT X.cw_eid +FROM cw_Personne AS X +WHERE NOT EXISTS(SELECT 1 FROM travaille_relation AS rel_travaille0 WHERE rel_travaille0.eid_from=X.cw_eid)'''), ("Personne P where not P datenaiss TODAY", - '''SELECT P.eid -FROM Personne AS P -WHERE NOT (DATE(P.datenaiss)=CURRENT_DATE)'''), + '''SELECT P.cw_eid +FROM cw_Personne AS P +WHERE NOT (DATE(P.cw_datenaiss)=CURRENT_DATE)'''), ("Personne P where NOT P concerne A", - '''SELECT P.eid -FROM Personne AS P -WHERE NOT EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_from=P.eid)'''), + '''SELECT P.cw_eid +FROM cw_Personne AS P +WHERE NOT EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_from=P.cw_eid)'''), ("Affaire A where not P concerne A", - '''SELECT A.eid -FROM Affaire AS A -WHERE NOT EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_to=A.eid)'''), + '''SELECT A.cw_eid +FROM cw_Affaire AS A +WHERE NOT EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_to=A.cw_eid)'''), ("Personne P where not P concerne A, A sujet ~= 'TEST%'", - '''SELECT P.eid -FROM Affaire AS A, Personne AS P -WHERE NOT EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_from=P.eid AND rel_concerne0.eid_to=A.eid) AND A.sujet ILIKE TEST%'''), + '''SELECT P.cw_eid +FROM cw_Affaire AS A, cw_Personne AS P +WHERE NOT EXISTS(SELECT 1 FROM concerne_relation AS rel_concerne0 WHERE rel_concerne0.eid_from=P.cw_eid AND rel_concerne0.eid_to=A.cw_eid) AND A.cw_sujet ILIKE TEST%'''), ('Any S WHERE NOT T eid 28258, T tags S', '''SELECT rel_tags0.eid_to @@ -679,17 +679,17 @@ WHERE NOT (rel_tags0.eid_from=28258)'''), ('Any S WHERE T is Tag, T name TN, NOT T eid 28258, T tags S, S name SN', - '''SELECT S.eid -FROM EGroup AS S, Tag AS T, tags_relation AS rel_tags0 -WHERE NOT (T.eid=28258) AND rel_tags0.eid_from=T.eid AND rel_tags0.eid_to=S.eid + '''SELECT S.cw_eid +FROM cw_EGroup AS S, cw_Tag AS T, tags_relation AS rel_tags0 +WHERE NOT (T.cw_eid=28258) AND rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=S.cw_eid UNION ALL -SELECT S.eid -FROM State AS S, Tag AS T, tags_relation AS rel_tags0 -WHERE NOT (T.eid=28258) AND rel_tags0.eid_from=T.eid AND rel_tags0.eid_to=S.eid +SELECT S.cw_eid +FROM cw_State AS S, cw_Tag AS T, tags_relation AS rel_tags0 +WHERE NOT (T.cw_eid=28258) AND rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=S.cw_eid UNION ALL -SELECT S.eid -FROM Tag AS S, Tag AS T, tags_relation AS rel_tags0 -WHERE NOT (T.eid=28258) AND rel_tags0.eid_from=T.eid AND rel_tags0.eid_to=S.eid'''), +SELECT S.cw_eid +FROM cw_Tag AS S, cw_Tag AS T, tags_relation AS rel_tags0 +WHERE NOT (T.cw_eid=28258) AND rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=S.cw_eid'''), ('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid 6', @@ -698,260 +698,260 @@ WHERE rel_created_by0.eid_from=5 AND NOT (rel_created_by0.eid_to=6)'''), ('Note X WHERE NOT Y evaluee X', - '''SELECT X.eid -FROM Note AS X -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_to=X.eid)'''), + '''SELECT X.cw_eid +FROM cw_Note AS X +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_to=X.cw_eid)'''), ('Any Y WHERE NOT Y evaluee X', - '''SELECT Y.eid -FROM Division AS Y -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.eid) + '''SELECT Y.cw_eid +FROM cw_Division AS Y +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.cw_eid) UNION ALL -SELECT Y.eid -FROM EUser AS Y -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.eid) +SELECT Y.cw_eid +FROM cw_EUser AS Y +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.cw_eid) UNION ALL -SELECT Y.eid -FROM Personne AS Y -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.eid) +SELECT Y.cw_eid +FROM cw_Personne AS Y +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.cw_eid) UNION ALL -SELECT Y.eid -FROM Societe AS Y -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.eid) +SELECT Y.cw_eid +FROM cw_Societe AS Y +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.cw_eid) UNION ALL -SELECT Y.eid -FROM SubDivision AS Y -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.eid)'''), +SELECT Y.cw_eid +FROM cw_SubDivision AS Y +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0 WHERE rel_evaluee0.eid_from=Y.cw_eid)'''), ('Any X WHERE NOT Y evaluee X, Y is EUser', - '''SELECT X.eid -FROM Note AS X -WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0,EUser AS Y WHERE rel_evaluee0.eid_from=Y.eid AND rel_evaluee0.eid_to=X.eid)'''), + '''SELECT X.cw_eid +FROM cw_Note AS X +WHERE NOT EXISTS(SELECT 1 FROM evaluee_relation AS rel_evaluee0,cw_EUser AS Y WHERE rel_evaluee0.eid_from=Y.cw_eid AND rel_evaluee0.eid_to=X.cw_eid)'''), ('Any X,T WHERE X title T, NOT X is Bookmark', - '''SELECT DISTINCT X.eid, X.title -FROM Card AS X + '''SELECT DISTINCT X.cw_eid, X.cw_title +FROM cw_Card AS X UNION -SELECT DISTINCT X.eid, X.title -FROM EmailThread AS X'''), +SELECT DISTINCT X.cw_eid, X.cw_title +FROM cw_EmailThread AS X'''), ('Any K,V WHERE P is EProperty, P pkey K, P value V, NOT P for_user U', - '''SELECT DISTINCT P.pkey, P.value -FROM EProperty AS P -WHERE P.for_user IS NULL'''), + '''SELECT DISTINCT P.cw_pkey, P.cw_value +FROM cw_EProperty AS P +WHERE P.cw_for_user IS NULL'''), ('Any S WHERE NOT X in_state S, X is IN(Affaire, EUser)', - '''SELECT DISTINCT S.eid -FROM Affaire AS X, State AS S -WHERE (X.in_state IS NULL OR X.in_state!=S.eid) + '''SELECT DISTINCT S.cw_eid +FROM cw_Affaire AS X, cw_State AS S +WHERE (X.cw_in_state IS NULL OR X.cw_in_state!=S.cw_eid) INTERSECT -SELECT DISTINCT S.eid -FROM EUser AS X, State AS S -WHERE (X.in_state IS NULL OR X.in_state!=S.eid)'''), +SELECT DISTINCT S.cw_eid +FROM cw_EUser AS X, cw_State AS S +WHERE (X.cw_in_state IS NULL OR X.cw_in_state!=S.cw_eid)'''), ] OUTER_JOIN = [ ('Any X,S WHERE X travaille S?', - '''SELECT X.eid, rel_travaille0.eid_to -FROM Personne AS X LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=X.eid)''' -#SELECT X.eid, S.eid -#FROM Personne AS X LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=X.eid) LEFT OUTER JOIN Societe AS S ON (rel_travaille0.eid_to=S.eid)''' + '''SELECT X.cw_eid, rel_travaille0.eid_to +FROM cw_Personne AS X LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=X.cw_eid)''' +#SELECT X.cw_eid, S.cw_eid +#FROM cw_Personne AS X LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=X.cw_eid) LEFT OUTER JOIN cw_Societe AS S ON (rel_travaille0.eid_to=S.cw_eid)''' ), ('Any S,X WHERE X? travaille S, S is Societe', - '''SELECT S.eid, rel_travaille0.eid_from -FROM Societe AS S LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_to=S.eid)''' -#SELECT S.eid, X.eid -#FROM Societe AS S LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_to=S.eid) LEFT OUTER JOIN Personne AS X ON (rel_travaille0.eid_from=X.eid)''' + '''SELECT S.cw_eid, rel_travaille0.eid_from +FROM cw_Societe AS S LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_to=S.cw_eid)''' +#SELECT S.cw_eid, X.cw_eid +#FROM cw_Societe AS S LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_to=S.cw_eid) LEFT OUTER JOIN cw_Personne AS X ON (rel_travaille0.eid_from=X.cw_eid)''' ), ('Any N,A WHERE N inline1 A?', - '''SELECT N.eid, N.inline1 -FROM Note AS N'''), + '''SELECT N.cw_eid, N.cw_inline1 +FROM cw_Note AS N'''), ('Any SN WHERE X from_state S?, S name SN', - '''SELECT S.name -FROM TrInfo AS X LEFT OUTER JOIN State AS S ON (X.from_state=S.eid)''' + '''SELECT S.cw_name +FROM cw_TrInfo AS X LEFT OUTER JOIN cw_State AS S ON (X.cw_from_state=S.cw_eid)''' ), ('Any A,N WHERE N? inline1 A', - '''SELECT A.eid, N.eid -FROM Affaire AS A LEFT OUTER JOIN Note AS N ON (N.inline1=A.eid)''' + '''SELECT A.cw_eid, N.cw_eid +FROM cw_Affaire AS A LEFT OUTER JOIN cw_Note AS N ON (N.cw_inline1=A.cw_eid)''' ), ('Any A,B,C,D,E,F,G WHERE A eid 12,A creation_date B,A modification_date C,A comment D,A from_state E?,A to_state F?,A wf_info_for G?', - '''SELECT A.eid, A.creation_date, A.modification_date, A.comment, A.from_state, A.to_state, A.wf_info_for -FROM TrInfo AS A -WHERE A.eid=12'''), + '''SELECT A.cw_eid, A.cw_creation_date, A.cw_modification_date, A.cw_comment, A.cw_from_state, A.cw_to_state, A.cw_wf_info_for +FROM cw_TrInfo AS A +WHERE A.cw_eid=12'''), ('Any FS,TS,C,D,U ORDERBY D DESC WHERE WF wf_info_for X,WF from_state FS?, WF to_state TS, WF comment C,WF creation_date D, WF owned_by U, X eid 1', - '''SELECT WF.from_state, WF.to_state, WF.comment, WF.creation_date, rel_owned_by0.eid_to -FROM TrInfo AS WF, owned_by_relation AS rel_owned_by0 -WHERE WF.wf_info_for=1 AND WF.to_state IS NOT NULL AND rel_owned_by0.eid_from=WF.eid + '''SELECT WF.cw_from_state, WF.cw_to_state, WF.cw_comment, WF.cw_creation_date, rel_owned_by0.eid_to +FROM cw_TrInfo AS WF, owned_by_relation AS rel_owned_by0 +WHERE WF.cw_wf_info_for=1 AND WF.cw_to_state IS NOT NULL AND rel_owned_by0.eid_from=WF.cw_eid ORDER BY 4 DESC'''), ('Any X WHERE X is Affaire, S is Societe, EXISTS(X owned_by U OR (X concerne S?, S owned_by U))', - '''SELECT X.eid -FROM Affaire AS X -WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, EUser AS U, Affaire AS A LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_from=A.eid) LEFT OUTER JOIN Societe AS S ON (rel_concerne1.eid_to=S.eid), owned_by_relation AS rel_owned_by2 WHERE ((rel_owned_by0.eid_from=A.eid AND rel_owned_by0.eid_to=U.eid) OR (rel_owned_by2.eid_from=S.eid AND rel_owned_by2.eid_to=U.eid)) AND X.eid=A.eid)'''), + '''SELECT X.cw_eid +FROM cw_Affaire AS X +WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, cw_EUser AS U, cw_Affaire AS A LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_from=A.cw_eid) LEFT OUTER JOIN cw_Societe AS S ON (rel_concerne1.eid_to=S.cw_eid), owned_by_relation AS rel_owned_by2 WHERE ((rel_owned_by0.eid_from=A.cw_eid AND rel_owned_by0.eid_to=U.cw_eid) OR (rel_owned_by2.eid_from=S.cw_eid AND rel_owned_by2.eid_to=U.cw_eid)) AND X.cw_eid=A.cw_eid)'''), ('Any C,M WHERE C travaille G?, G evaluee M?, G is Societe', - '''SELECT C.eid, rel_evaluee1.eid_to -FROM Personne AS C LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=C.eid) LEFT OUTER JOIN Societe AS G ON (rel_travaille0.eid_to=G.eid) LEFT OUTER JOIN evaluee_relation AS rel_evaluee1 ON (rel_evaluee1.eid_from=G.eid)''' -#SELECT C.eid, M.eid -#FROM Personne AS C LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=C.eid) LEFT OUTER JOIN Societe AS G ON (rel_travaille0.eid_to=G.eid) LEFT OUTER JOIN evaluee_relation AS rel_evaluee1 ON (rel_evaluee1.eid_from=G.eid) LEFT OUTER JOIN Note AS M ON (rel_evaluee1.eid_to=M.eid)''' + '''SELECT C.cw_eid, rel_evaluee1.eid_to +FROM cw_Personne AS C LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=C.cw_eid) LEFT OUTER JOIN cw_Societe AS G ON (rel_travaille0.eid_to=G.cw_eid) LEFT OUTER JOIN evaluee_relation AS rel_evaluee1 ON (rel_evaluee1.eid_from=G.cw_eid)''' +#SELECT C.cw_eid, M.cw_eid +#FROM cw_Personne AS C LEFT OUTER JOIN travaille_relation AS rel_travaille0 ON (rel_travaille0.eid_from=C.cw_eid) LEFT OUTER JOIN cw_Societe AS G ON (rel_travaille0.eid_to=G.cw_eid) LEFT OUTER JOIN evaluee_relation AS rel_evaluee1 ON (rel_evaluee1.eid_from=G.cw_eid) LEFT OUTER JOIN cw_Note AS M ON (rel_evaluee1.eid_to=M.cw_eid)''' ), ('Any A,C WHERE A documented_by C?, (C is NULL) OR (EXISTS(C require_permission F, ' 'F name "read", F require_group E, U in_group E)), U eid 1', - '''SELECT A.eid, rel_documented_by0.eid_to -FROM Affaire AS A LEFT OUTER JOIN documented_by_relation AS rel_documented_by0 ON (rel_documented_by0.eid_from=A.eid) -WHERE ((rel_documented_by0.eid_to IS NULL) OR (EXISTS(SELECT 1 FROM require_permission_relation AS rel_require_permission1, EPermission AS F, require_group_relation AS rel_require_group2, in_group_relation AS rel_in_group3 WHERE rel_documented_by0.eid_to=rel_require_permission1.eid_from AND rel_require_permission1.eid_to=F.eid AND F.name=read AND rel_require_group2.eid_from=F.eid AND rel_in_group3.eid_to=rel_require_group2.eid_to AND rel_in_group3.eid_from=1)))'''), + '''SELECT A.cw_eid, rel_documented_by0.eid_to +FROM cw_Affaire AS A LEFT OUTER JOIN documented_by_relation AS rel_documented_by0 ON (rel_documented_by0.eid_from=A.cw_eid) +WHERE ((rel_documented_by0.eid_to IS NULL) OR (EXISTS(SELECT 1 FROM require_permission_relation AS rel_require_permission1, cw_EPermission AS F, require_group_relation AS rel_require_group2, in_group_relation AS rel_in_group3 WHERE rel_documented_by0.eid_to=rel_require_permission1.eid_from AND rel_require_permission1.eid_to=F.cw_eid AND F.cw_name=read AND rel_require_group2.eid_from=F.cw_eid AND rel_in_group3.eid_to=rel_require_group2.eid_to AND rel_in_group3.eid_from=1)))'''), ("Any X WHERE X eid 12, P? connait X", - '''SELECT X.eid -FROM Personne AS X LEFT OUTER JOIN connait_relation AS rel_connait0 ON (rel_connait0.eid_to=12) -WHERE X.eid=12''' + '''SELECT X.cw_eid +FROM cw_Personne AS X LEFT OUTER JOIN connait_relation AS rel_connait0 ON (rel_connait0.eid_to=12) +WHERE X.cw_eid=12''' #SELECT 12 -#FROM Personne AS X LEFT OUTER JOIN connait_relation AS rel_connait0 ON (rel_connait0.eid_to=12) LEFT OUTER JOIN Personne AS P ON (rel_connait0.eid_from=P.eid) -#WHERE X.eid=12''' +#FROM cw_Personne AS X LEFT OUTER JOIN connait_relation AS rel_connait0 ON (rel_connait0.eid_to=12) LEFT OUTER JOIN Personne AS P ON (rel_connait0.eid_from=P.cw_eid) +#WHERE X.cw_eid=12''' ), ('Any GN, TN ORDERBY GN WHERE T tags G?, T name TN, G name GN', - '''SELECT _T0.C1, T.name -FROM Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.eid) LEFT OUTER JOIN (SELECT G.eid AS C0, G.name AS C1 -FROM EGroup AS G + '''SELECT _T0.C1, T.cw_name +FROM cw_Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.cw_eid) LEFT OUTER JOIN (SELECT G.cw_eid AS C0, G.cw_name AS C1 +FROM cw_EGroup AS G UNION ALL -SELECT G.eid AS C0, G.name AS C1 -FROM State AS G +SELECT G.cw_eid AS C0, G.cw_name AS C1 +FROM cw_State AS G UNION ALL -SELECT G.eid AS C0, G.name AS C1 -FROM Tag AS G) AS _T0 ON (rel_tags0.eid_to=_T0.C0) +SELECT G.cw_eid AS C0, G.cw_name AS C1 +FROM cw_Tag AS G) AS _T0 ON (rel_tags0.eid_to=_T0.C0) ORDER BY 1'''), # optional variable with additional restriction ('Any T,G WHERE T tags G?, G name "hop", G is EGroup', - '''SELECT T.eid, G.eid -FROM Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.eid) LEFT OUTER JOIN EGroup AS G ON (rel_tags0.eid_to=G.eid AND G.name=hop)'''), + '''SELECT T.cw_eid, G.cw_eid +FROM cw_Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.cw_eid) LEFT OUTER JOIN cw_EGroup AS G ON (rel_tags0.eid_to=G.cw_eid AND G.cw_name=hop)'''), # optional variable with additional invariant restriction ('Any T,G WHERE T tags G?, G eid 12', - '''SELECT T.eid, rel_tags0.eid_to -FROM Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.eid AND rel_tags0.eid_to=12)'''), + '''SELECT T.cw_eid, rel_tags0.eid_to +FROM cw_Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.cw_eid AND rel_tags0.eid_to=12)'''), # optional variable with additional restriction appearing before the relation ('Any T,G WHERE G name "hop", T tags G?, G is EGroup', - '''SELECT T.eid, G.eid -FROM Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.eid) LEFT OUTER JOIN EGroup AS G ON (rel_tags0.eid_to=G.eid AND G.name=hop)'''), + '''SELECT T.cw_eid, G.cw_eid +FROM cw_Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.cw_eid) LEFT OUTER JOIN cw_EGroup AS G ON (rel_tags0.eid_to=G.cw_eid AND G.cw_name=hop)'''), # optional variable with additional restriction on inlined relation # XXX the expected result should be as the query below. So what, raise BadRQLQuery ? ('Any T,G,S WHERE T tags G?, G in_state S, S name "hop", G is EUser', - '''SELECT T.eid, G.eid, S.eid -FROM State AS S, Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.eid) LEFT OUTER JOIN EUser AS G ON (rel_tags0.eid_to=G.eid) -WHERE G.in_state=S.eid AND S.name=hop + '''SELECT T.cw_eid, G.cw_eid, S.cw_eid +FROM cw_State AS S, cw_Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.cw_eid) LEFT OUTER JOIN cw_EUser AS G ON (rel_tags0.eid_to=G.cw_eid) +WHERE G.cw_in_state=S.cw_eid AND S.cw_name=hop '''), # optional variable with additional invariant restriction on an inlined relation ('Any T,G,S WHERE T tags G, G in_state S?, S eid 1, G is EUser', - '''SELECT rel_tags0.eid_from, G.eid, G.in_state -FROM EUser AS G, tags_relation AS rel_tags0 -WHERE rel_tags0.eid_to=G.eid AND (G.in_state=1 OR G.in_state IS NULL)'''), + '''SELECT rel_tags0.eid_from, G.cw_eid, G.cw_in_state +FROM cw_EUser AS G, tags_relation AS rel_tags0 +WHERE rel_tags0.eid_to=G.cw_eid AND (G.cw_in_state=1 OR G.cw_in_state IS NULL)'''), # two optional variables with additional invariant restriction on an inlined relation ('Any T,G,S WHERE T tags G?, G in_state S?, S eid 1, G is EUser', - '''SELECT T.eid, G.eid, G.in_state -FROM Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.eid) LEFT OUTER JOIN EUser AS G ON (rel_tags0.eid_to=G.eid AND (G.in_state=1 OR G.in_state IS NULL))'''), + '''SELECT T.cw_eid, G.cw_eid, G.cw_in_state +FROM cw_Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.cw_eid) LEFT OUTER JOIN cw_EUser AS G ON (rel_tags0.eid_to=G.cw_eid AND (G.cw_in_state=1 OR G.cw_in_state IS NULL))'''), # two optional variables with additional restriction on an inlined relation ('Any T,G,S WHERE T tags G?, G in_state S?, S name "hop", G is EUser', - '''SELECT T.eid, G.eid, S.eid -FROM Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.eid) LEFT OUTER JOIN EUser AS G ON (rel_tags0.eid_to=G.eid) LEFT OUTER JOIN State AS S ON (G.in_state=S.eid AND S.name=hop)'''), + '''SELECT T.cw_eid, G.cw_eid, S.cw_eid +FROM cw_Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.cw_eid) LEFT OUTER JOIN cw_EUser AS G ON (rel_tags0.eid_to=G.cw_eid) LEFT OUTER JOIN cw_State AS S ON (G.cw_in_state=S.cw_eid AND S.cw_name=hop)'''), # two optional variables with additional restriction on an ambigous inlined relation ('Any T,G,S WHERE T tags G?, G in_state S?, S name "hop"', - '''SELECT T.eid, _T0.C0, _T0.C1 -FROM Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.eid) LEFT OUTER JOIN (SELECT G.eid AS C0, S.eid AS C1 -FROM Affaire AS G LEFT OUTER JOIN State AS S ON (G.in_state=S.eid AND S.name=hop) + '''SELECT T.cw_eid, _T0.C0, _T0.C1 +FROM cw_Tag AS T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_from=T.cw_eid) LEFT OUTER JOIN (SELECT G.cw_eid AS C0, S.cw_eid AS C1 +FROM cw_Affaire AS G LEFT OUTER JOIN cw_State AS S ON (G.cw_in_state=S.cw_eid AND S.cw_name=hop) UNION ALL -SELECT G.eid AS C0, S.eid AS C1 -FROM EUser AS G LEFT OUTER JOIN State AS S ON (G.in_state=S.eid AND S.name=hop) +SELECT G.cw_eid AS C0, S.cw_eid AS C1 +FROM cw_EUser AS G LEFT OUTER JOIN cw_State AS S ON (G.cw_in_state=S.cw_eid AND S.cw_name=hop) UNION ALL -SELECT G.eid AS C0, S.eid AS C1 -FROM Note AS G LEFT OUTER JOIN State AS S ON (G.in_state=S.eid AND S.name=hop) ) AS _T0 ON (rel_tags0.eid_to=_T0.C0)'''), +SELECT G.cw_eid AS C0, S.cw_eid AS C1 +FROM cw_Note AS G LEFT OUTER JOIN cw_State AS S ON (G.cw_in_state=S.cw_eid AND S.cw_name=hop) ) AS _T0 ON (rel_tags0.eid_to=_T0.C0)'''), ] VIRTUAL_VARS = [ ("Personne P WHERE P travaille S, S tel T, S fax T, S is Societe;", '''SELECT rel_travaille0.eid_from -FROM Societe AS S, travaille_relation AS rel_travaille0 -WHERE rel_travaille0.eid_to=S.eid AND S.fax=S.tel'''), +FROM cw_Societe AS S, travaille_relation AS rel_travaille0 +WHERE rel_travaille0.eid_to=S.cw_eid AND S.cw_fax=S.cw_tel'''), ("Personne P where X eid 0, X creation_date D, P datenaiss < D, X is Affaire", - '''SELECT P.eid -FROM Affaire AS X, Personne AS P -WHERE X.eid=0 AND P.datenaiss1))', '''SELECT _T0.C0, _T0.C1 -FROM ((SELECT X.name AS C0, COUNT(X.eid) AS C1 -FROM State AS X -GROUP BY X.name -HAVING COUNT(X.eid)>1) +FROM ((SELECT X.cw_name AS C0, COUNT(X.cw_eid) AS C1 +FROM cw_State AS X +GROUP BY X.cw_name +HAVING COUNT(X.cw_eid)>1) UNION ALL -(SELECT X.name AS C0, COUNT(X.eid) AS C1 -FROM Transition AS X -GROUP BY X.name -HAVING COUNT(X.eid)>1)) AS _T0 +(SELECT X.cw_name AS C0, COUNT(X.cw_eid) AS C1 +FROM cw_Transition AS X +GROUP BY X.cw_name +HAVING COUNT(X.cw_eid)>1)) AS _T0 ORDER BY 2'''), ('Any N,COUNT(X) GROUPBY N HAVING COUNT(X)>1 ' 'WITH X, N BEING ((Any X, N WHERE X name N, X is State) UNION ' ' (Any X, N WHERE X name N, X is Transition))', '''SELECT _T0.C1, COUNT(_T0.C0) -FROM ((SELECT X.eid AS C0, X.name AS C1 -FROM State AS X) +FROM ((SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_State AS X) UNION ALL -(SELECT X.eid AS C0, X.name AS C1 -FROM Transition AS X)) AS _T0 +(SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_Transition AS X)) AS _T0 GROUP BY _T0.C1 HAVING COUNT(_T0.C0)>1'''), ('Any ETN,COUNT(X) GROUPBY ETN WHERE X is ET, ET name ETN ' 'WITH X BEING ((Any X WHERE X is Societe) UNION (Any X WHERE X is Affaire, (EXISTS(X owned_by 1)) OR ((EXISTS(D concerne B?, B owned_by 1, X identity D, B is Note)) OR (EXISTS(F concerne E?, E owned_by 1, E is Societe, X identity F)))))', - '''SELECT ET.name, COUNT(_T0.C0) -FROM ((SELECT X.eid AS C0 -FROM Societe AS X) + '''SELECT ET.cw_name, COUNT(_T0.C0) +FROM ((SELECT X.cw_eid AS C0 +FROM cw_Societe AS X) UNION ALL -(SELECT X.eid AS C0 -FROM Affaire AS X -WHERE ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=X.eid AND rel_owned_by0.eid_to=1)) OR (((EXISTS(SELECT 1 FROM Affaire AS D LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_from=D.eid) LEFT OUTER JOIN Note AS B ON (rel_concerne1.eid_to=B.eid), owned_by_relation AS rel_owned_by2 WHERE rel_owned_by2.eid_from=B.eid AND rel_owned_by2.eid_to=1 AND X.eid=D.eid)) OR (EXISTS(SELECT 1 FROM Affaire AS F LEFT OUTER JOIN concerne_relation AS rel_concerne3 ON (rel_concerne3.eid_from=F.eid) LEFT OUTER JOIN Societe AS E ON (rel_concerne3.eid_to=E.eid), owned_by_relation AS rel_owned_by4 WHERE rel_owned_by4.eid_from=E.eid AND rel_owned_by4.eid_to=1 AND X.eid=F.eid))))))) AS _T0, EEType AS ET, is_relation AS rel_is0 -WHERE rel_is0.eid_from=_T0.C0 AND rel_is0.eid_to=ET.eid -GROUP BY ET.name'''), +(SELECT X.cw_eid AS C0 +FROM cw_Affaire AS X +WHERE ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=X.cw_eid AND rel_owned_by0.eid_to=1)) OR (((EXISTS(SELECT 1 FROM cw_Affaire AS D LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_from=D.cw_eid) LEFT OUTER JOIN cw_Note AS B ON (rel_concerne1.eid_to=B.cw_eid), owned_by_relation AS rel_owned_by2 WHERE rel_owned_by2.eid_from=B.cw_eid AND rel_owned_by2.eid_to=1 AND X.cw_eid=D.cw_eid)) OR (EXISTS(SELECT 1 FROM cw_Affaire AS F LEFT OUTER JOIN concerne_relation AS rel_concerne3 ON (rel_concerne3.eid_from=F.cw_eid) LEFT OUTER JOIN cw_Societe AS E ON (rel_concerne3.eid_to=E.cw_eid), owned_by_relation AS rel_owned_by4 WHERE rel_owned_by4.eid_from=E.cw_eid AND rel_owned_by4.eid_to=1 AND X.cw_eid=F.cw_eid))))))) AS _T0, cw_EEType AS ET, is_relation AS rel_is0 +WHERE rel_is0.eid_from=_T0.C0 AND rel_is0.eid_to=ET.cw_eid +GROUP BY ET.cw_name'''), )): yield t @@ -1353,33 +1353,33 @@ WHERE appears0.words @@ to_tsquery('default', 'hip&hop&momo') AND appears0.uid=X.eid AND X.type='Personne'"""), ('Any X WHERE X has_text "toto tata", X name "tutu"', - """SELECT X.eid -FROM Basket AS X, appears AS appears0 -WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.eid AND X.name=tutu + """SELECT X.cw_eid +FROM appears AS appears0, cw_Basket AS X +WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM File AS X, appears AS appears0 -WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_File AS X +WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Folder AS X, appears AS appears0 -WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Folder AS X +WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Image AS X, appears AS appears0 -WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Image AS X +WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM State AS X, appears AS appears0 -WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_State AS X +WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Tag AS X, appears AS appears0 -WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Tag AS X +WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Transition AS X, appears AS appears0 -WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.eid AND X.name=tutu"""), +SELECT X.cw_eid +FROM appears AS appears0, cw_Transition AS X +WHERE appears0.words @@ to_tsquery('default', 'toto&tata') AND appears0.uid=X.cw_eid AND X.cw_name=tutu"""), ('Personne X where X has_text %(text)s, X travaille S, S has_text %(text)s', """SELECT X.eid @@ -1392,7 +1392,7 @@ def test_from_clause_needed(self): queries = [("Any 1 WHERE EXISTS(T is EGroup, T name 'managers')", '''SELECT 1 -WHERE EXISTS(SELECT 1 FROM EGroup AS T WHERE T.name=managers)'''), +WHERE EXISTS(SELECT 1 FROM cw_EGroup AS T WHERE T.cw_name=managers)'''), ('Any X,Y WHERE NOT X created_by Y, X eid 5, Y eid 6', '''SELECT 5, 6 WHERE NOT EXISTS(SELECT 1 FROM created_by_relation AS rel_created_by0 WHERE rel_created_by0.eid_from=5 AND rel_created_by0.eid_to=6)'''), @@ -1403,7 +1403,7 @@ def test_ambigous_exists_no_from_clause(self): self._check('Any COUNT(U) WHERE U eid 1, EXISTS (P owned_by U, P is IN (Note, Affaire))', '''SELECT COUNT(1) -WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, Affaire AS P WHERE rel_owned_by0.eid_from=P.eid AND rel_owned_by0.eid_to=1 UNION SELECT 1 FROM owned_by_relation AS rel_owned_by1, Note AS P WHERE rel_owned_by1.eid_from=P.eid AND rel_owned_by1.eid_to=1)''') +WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, cw_Affaire AS P WHERE rel_owned_by0.eid_from=P.cw_eid AND rel_owned_by0.eid_to=1 UNION SELECT 1 FROM owned_by_relation AS rel_owned_by1, cw_Note AS P WHERE rel_owned_by1.eid_from=P.cw_eid AND rel_owned_by1.eid_to=1)''') class SqliteSQLGeneratorTC(PostgresSQLGeneratorTC): @@ -1426,12 +1426,12 @@ ('(Any N ORDERBY 1 WHERE X name N, X is State)' ' UNION ' '(Any NN ORDERBY 1 WHERE XX name NN, XX is Transition)', - '''SELECT X.name -FROM State AS X + '''SELECT X.cw_name +FROM cw_State AS X ORDER BY 1 UNION ALL -SELECT XX.name -FROM Transition AS XX +SELECT XX.cw_name +FROM cw_Transition AS XX ORDER BY 1'''), )): yield t @@ -1446,11 +1446,11 @@ ' UNION ' '(Any NN WHERE XX name NN, XX is Transition))', '''SELECT _T0.C0 -FROM (SELECT X.name AS C0 -FROM State AS X +FROM (SELECT X.cw_name AS C0 +FROM cw_State AS X UNION ALL -SELECT XX.name AS C0 -FROM Transition AS XX) AS _T0 +SELECT XX.cw_name AS C0 +FROM cw_Transition AS XX) AS _T0 ORDER BY 1'''), ('Any N,NX ORDERBY NX WITH N,NX BEING ' @@ -1458,26 +1458,26 @@ ' UNION ' '(Any N,COUNT(X) GROUPBY N WHERE X name N, X is Transition HAVING COUNT(X)>1))', '''SELECT _T0.C0, _T0.C1 -FROM (SELECT X.name AS C0, COUNT(X.eid) AS C1 -FROM State AS X -GROUP BY X.name -HAVING COUNT(X.eid)>1 +FROM (SELECT X.cw_name AS C0, COUNT(X.cw_eid) AS C1 +FROM cw_State AS X +GROUP BY X.cw_name +HAVING COUNT(X.cw_eid)>1 UNION ALL -SELECT X.name AS C0, COUNT(X.eid) AS C1 -FROM Transition AS X -GROUP BY X.name -HAVING COUNT(X.eid)>1) AS _T0 +SELECT X.cw_name AS C0, COUNT(X.cw_eid) AS C1 +FROM cw_Transition AS X +GROUP BY X.cw_name +HAVING COUNT(X.cw_eid)>1) AS _T0 ORDER BY 2'''), ('Any N,COUNT(X) GROUPBY N HAVING COUNT(X)>1 ' 'WITH X, N BEING ((Any X, N WHERE X name N, X is State) UNION ' ' (Any X, N WHERE X name N, X is Transition))', '''SELECT _T0.C1, COUNT(_T0.C0) -FROM (SELECT X.eid AS C0, X.name AS C1 -FROM State AS X +FROM (SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_State AS X UNION ALL -SELECT X.eid AS C0, X.name AS C1 -FROM Transition AS X) AS _T0 +SELECT X.cw_eid AS C0, X.cw_name AS C1 +FROM cw_Transition AS X) AS _T0 GROUP BY _T0.C1 HAVING COUNT(_T0.C0)>1'''), )): @@ -1501,33 +1501,33 @@ WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.type='Personne'"""), ('Any X WHERE X has_text "toto tata", X name "tutu"', - """SELECT X.eid -FROM Basket AS X, appears AS appears0 -WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.name=tutu + """SELECT X.cw_eid +FROM appears AS appears0, cw_Basket AS X +WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM File AS X, appears AS appears0 -WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_File AS X +WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Folder AS X, appears AS appears0 -WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Folder AS X +WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Image AS X, appears AS appears0 -WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Image AS X +WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM State AS X, appears AS appears0 -WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_State AS X +WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Tag AS X, appears AS appears0 -WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Tag AS X +WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Transition AS X, appears AS appears0 -WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.eid AND X.name=tutu"""), +SELECT X.cw_eid +FROM appears AS appears0, cw_Transition AS X +WHERE appears0.word_id IN (SELECT word_id FROM word WHERE word in ('toto', 'tata')) AND appears0.uid=X.cw_eid AND X.cw_name=tutu"""), )): yield t @@ -1552,7 +1552,7 @@ queries = [("Any 1 WHERE EXISTS(T is EGroup, T name 'managers')", '''SELECT 1 FROM (SELECT 1) AS _T -WHERE EXISTS(SELECT 1 FROM EGroup AS T WHERE T.name=managers)'''), +WHERE EXISTS(SELECT 1 FROM cw_EGroup AS T WHERE T.cw_name=managers)'''), ('Any X,Y WHERE NOT X created_by Y, X eid 5, Y eid 6', '''SELECT 5, 6 FROM (SELECT 1) AS _T @@ -1577,33 +1577,33 @@ FROM appears AS appears0, entities AS X WHERE MATCH (appears0.words) AGAINST ('hip hop momo' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.type='Personne'"""), ('Any X WHERE X has_text "toto tata", X name "tutu"', - """SELECT X.eid -FROM Basket AS X, appears AS appears0 -WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.name=tutu + """SELECT X.cw_eid +FROM appears AS appears0, cw_Basket AS X +WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM File AS X, appears AS appears0 -WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_File AS X +WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Folder AS X, appears AS appears0 -WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Folder AS X +WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Image AS X, appears AS appears0 -WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Image AS X +WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM State AS X, appears AS appears0 -WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_State AS X +WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Tag AS X, appears AS appears0 -WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.name=tutu +SELECT X.cw_eid +FROM appears AS appears0, cw_Tag AS X +WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu UNION ALL -SELECT X.eid -FROM Transition AS X, appears AS appears0 -WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.eid AND X.name=tutu""") +SELECT X.cw_eid +FROM appears AS appears0, cw_Transition AS X +WHERE MATCH (appears0.words) AGAINST ('toto tata' IN BOOLEAN MODE) AND appears0.uid=X.cw_eid AND X.cw_name=tutu""") ] for t in self._parse(queries): yield t @@ -1613,7 +1613,7 @@ self._check('Any COUNT(U) WHERE U eid 1, EXISTS (P owned_by U, P is IN (Note, Affaire))', '''SELECT COUNT(1) FROM (SELECT 1) AS _T -WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, Affaire AS P WHERE rel_owned_by0.eid_from=P.eid AND rel_owned_by0.eid_to=1 UNION SELECT 1 FROM owned_by_relation AS rel_owned_by1, Note AS P WHERE rel_owned_by1.eid_from=P.eid AND rel_owned_by1.eid_to=1)''') +WHERE EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, cw_Affaire AS P WHERE rel_owned_by0.eid_from=P.cw_eid AND rel_owned_by0.eid_to=1 UNION SELECT 1 FROM owned_by_relation AS rel_owned_by1, cw_Note AS P WHERE rel_owned_by1.eid_from=P.cw_eid AND rel_owned_by1.eid_to=1)''')