Update of /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer
In directory sc8-pr-cvs1:/tmp/cvs-serv21866/DatabaseAdaptors/MySQLAdaptorLayer
Modified Files:
MySQLSQLExpression.py
Log Message:
Fixed bug #780495: when ec.fetch() is joining two tables or more, the
returned set of objects could have duplicates.
Index: MySQLSQLExpression.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** MySQLSQLExpression.py 31 May 2003 15:12:24 -0000 1.5
--- MySQLSQLExpression.py 3 Aug 2003 10:34:14 -0000 1.6
***************
*** 173,174 ****
--- 173,272 ----
return (str, aliases)
+
+ def prepareSelectCountExpressionWithAttributes(self,
+ attributes,lock,fetchSpec):
+ """
+ Overrides the default method and prepares a SQL expression suitable for
+ MySQL, counting the rows qualified by 'fetchSpec'.
+
+ The SQL statement depends on whether 'fetchSpec' implies joining two or
+ more tables:
+
+ - if at least a join is needed, the statement is like::
+
+ SELECT COUNT(DISTINCT t0.pk1, t0.pk2, ...) FROM ...
+ INNER JOIN ...
+ [WHERE <fetchSpec's condition>]
+
+ where pk1, pk2 are the primary keys in the fetchSpec's entity,
+
+ - otherwise, it is like:
+
+ SELECT COUNT(*) FROM <table> [WHERE <fetchSpec's condition>]
+
+ Parameters:
+
+ attributes -- the attributes to fetch (they do not appear in the sql)
+
+ lock -- Unimplemented, should be false
+
+ fetchSpec -- the FetchSpecification qualifying the rows to be counted
+
+ """
+ self.setUseAliases('Yep')
+ lockClause=''
+ if lock:
+ raise NotImplementedError, 'lock is not implemented yet'
+
+ for attribute in attributes:
+ self.addSelectListAttribute(attribute)
+
+ # fetchSpec
+ if fetchSpec is not None and \
+ self._entity.restrictingQualifier() is not None: # TBD
+ raise 'Unimplemented', \
+ "fetchSpec and/or entity's restrictingQualifier is not None"
+
+ # qualifier: to be mixed w/ entity's restrictingQualifier if necessary
+ fullQualifier=None
+
+ fsQualifier=fetchSpec and fetchSpec.qualifier() or None
+ entityQual=self._entity.restrictingQualifier()
+ if fsQualifier:
+ if entityQual:
+ fullQualifier=AndQualifier([fsQualifier, entityQual])
+ else:
+ fullQualifier=fsQualifier
+ elif entityQual:
+ fullQualifier=entityQual
+
+ # clause: WHERE
+ self._whereClauseString=self.sqlStringForQualifier(fullQualifier)
+
+ joinClause=''
+
+ # Do we join some tables?
+ multiple_tables_joined=len(self.entityExternalNamesByAliases())>1
+ selectString=''
+
+ columnList=' COUNT(*) '
+ if multiple_tables_joined:
+ columnList='COUNT(DISTINCT '
+ # TBD: cf. test_14: if we use this:
+ #self._internals.aliasForEntityExternalName(self._entity.externalName())
+ # then we select from the wrong table (t3 instead of t0)
+ entity_alias='t0'
+ for pk in self._entity.primaryKeyAttributes():
+ columnList+=entity_alias+'.'+pk.columnName()+', '
+ columnList=columnList[:-2]+') '
+ else:
+ columnList=' COUNT(*) '
+
+ fetchOrder=None
+ whereClause=self.whereClauseString()
+ # orderBy: see fetchSpec...
+ orderByClause=''
+
+ #
+ tableList=self.tableListWithRootEntity(self.entity())
+ self.assembleSelectStatementWithAttributes(attributes=attributes,
+ lock=lock,
+ qualifier=fullQualifier,
+ fetchOrder=fetchOrder,
+ selectString=selectString,
+ columnList=columnList,
+ tableList=tableList,
+ whereClause=whereClause,
+ joinClause=joinClause,
+ orderByClause=orderByClause,
+ lockClause=lockClause)
|