[Modeling-cvs] ProjectModeling/Modeling CHANGES,1.86.2.2,1.86.2.3 SQLExpression.py,1.16,1.16.2.1
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2003-03-17 12:44:25
|
Update of /cvsroot/modeling/ProjectModeling/Modeling In directory sc8-pr-cvs1:/tmp/cvs-serv12693 Modified Files: Tag: brch-0_9pre5-SQL_SortOrdering_and_LIMIT CHANGES SQLExpression.py Log Message: SQLExpression: added support for FetchSpecification's sortOrderings() and fetchSlice() -- support for fetchSlice() depends on limitString() which has no default implementation and should be implemented by concrete AdaptorLayers willing to support it. Added: fetchSlice, limitString, setFetchSlice, Modified: __init__, addOrderByAttributeOrdering, assembleSelectStatementWithAttributes, orderByString, _prepareSelectExpressionWithAttributes, Index: CHANGES =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/CHANGES,v retrieving revision 1.86.2.2 retrieving revision 1.86.2.3 diff -C2 -d -r1.86.2.2 -r1.86.2.3 *** CHANGES 17 Mar 2003 12:32:06 -0000 1.86.2.2 --- CHANGES 17 Mar 2003 12:44:21 -0000 1.86.2.3 *************** *** 20,23 **** --- 20,32 ---- + * SQLExpression: added support for FetchSpecification's sortOrderings() and + fetchSlice() -- support for fetchSlice() depends on limitString() which + has no default implementation and should be implemented by concrete + AdaptorLayers willing to support it. + Added: fetchSlice, limitString, setFetchSlice, + Modified: __init__, addOrderByAttributeOrdering, + assembleSelectStatementWithAttributes, orderByString, + _prepareSelectExpressionWithAttributes, + * FetchSpecification: added (set)fetchSlice(), getNext/PreviousSlice() Index: SQLExpression.py =================================================================== RCS file: /cvsroot/modeling/ProjectModeling/Modeling/SQLExpression.py,v retrieving revision 1.16 retrieving revision 1.16.2.1 diff -C2 -d -r1.16 -r1.16.2.1 *** SQLExpression.py 14 Mar 2003 11:40:10 -0000 1.16 --- SQLExpression.py 17 Mar 2003 12:44:21 -0000 1.16.2.1 *************** *** 259,263 **** --- 259,265 ---- """ self._entity=anEntity + self._fetchSlice={'limit':0, 'offset':0} self._listString=StringIO() + self._orderByString=StringIO() self._valueList=StringIO() self._statement='' *************** *** 327,333 **** """ ! def addOrderByAttributeOrdering(self, sortOrdering): """ """ def addSelectListAttribute(self, attribute): --- 329,368 ---- """ ! def addOrderByAttributeOrdering(self, aSortOrdering): """ + + Parameter: + + aSortOrdering -- instance of SortOrdering + + Raises ValueError if aSortOrdering references an invalid key/keypath + + See also: orderByString(), + prepareSelectExpressionWithAttributes(), + sqlStringForAttributeNamed(), appendItemToListString(), + SortOrdering """ + from SortOrdering import \ + compareAscending, compareDescending,\ + compareCaseInsensitiveAscending, compareCaseInsensitiveDescending + + operator=aSortOrdering.operator() + if operator in (compareDescending, compareCaseInsensitiveDescending): + order='DESC' + else: + order='ASC' + + try: + attr=self.sqlStringForAttributeNamed(aSortOrdering.key()) + except ValueError: + raise ValueError, "The FetchSpecification has a SortOrdering referencing attribute '%s' but this attribute cannot be found"%(aSortOrdering.key(),) + + if operator in (compareCaseInsensitiveDescending, + compareCaseInsensitiveAscending): + orderStr='UPPER(%s) '%attr + else: + orderStr='(%s) '%attr + orderStr+=order + self.appendItemToListString(orderStr, self._orderByString) def addSelectListAttribute(self, attribute): *************** *** 476,480 **** columnList, tableList, whereClause, joinClause, orderByClause, ! lockClause): """ """ --- 511,515 ---- columnList, tableList, whereClause, joinClause, orderByClause, ! lockClause, limitClause): """ """ *************** *** 491,494 **** --- 526,533 ---- if orderByClause: statement+=' ORDER BY '+orderByClause + + if limitClause: + statement += ' '+limitClause + self._statement=statement *************** *** 578,581 **** --- 617,627 ---- __unimplemented__() + def fetchSlice(self): + """ + + See also: setFetchSlice(), FetchSpecification.fetchSlice() + """ + return self._fetchSlice + def formatSQLString(self, sqlString, format): """ *************** *** 637,640 **** --- 683,700 ---- __unimplemented__() + def limitString(self): + """ + Returns the SQL statement to be used to reflect + FetchSpecification.fetchSlice() in a SELECT statement + + By default the framework does not offer any support for this. It may or + may not be implemented by a given AdaptorLayer (those for Postgresql and + MySQL support the feature). + + """ + if self.fetchSlice()!={'limit':0, 'offset':0}: + raise NotImplementedError, 'You probably supplied a FetchSpecification where fetchSlice() is set, but the framework does not offer any default implementation for this. It is likely that the adaptor layer you are currently using does not support this feature ; please refer to its documenntation for more details' + return '' + def listString(self): """ *************** *** 664,669 **** def orderByString(self): """ """ ! __unimplemented__() def prepareConstraintStatementForRelationship(self, relationship, sourceColumns, destinationColumns): --- 724,736 ---- def orderByString(self): """ + Returns the part of the SQL statement used to order the result set. The + returned string only contains the SQL attribute and the corresponding + sorting scheme (ascending/descending, it is NOT prepended by the usual + 'ORDER BY' statement. + + See also: addOrderByAttributeOrdering(), + assembleSelectStatementWithAttributes() """ ! return self._orderByString.getvalue() def prepareConstraintStatementForRelationship(self, relationship, sourceColumns, destinationColumns): *************** *** 681,685 **** - the use of aliases is disabled (see setUseAliases()) ! - the whereClauseString() is compuuted ans set by calling 'sqlStringForQualifier(aQualifier)' on itself, --- 748,752 ---- - the use of aliases is disabled (see setUseAliases()) ! - the whereClauseString() is computed and set by calling 'sqlStringForQualifier(aQualifier)' on itself, *************** *** 741,744 **** --- 808,813 ---- prepareSelectExpressionWithAttributes(). + The object's fetchSlice() receives fetchSpec.fetchSlice() + Parameters: *************** *** 788,793 **** fetchOrder=None whereClause=self.whereClauseString() # orderBy: see fetchSpec... ! orderByClause='' if count: --- 857,871 ---- fetchOrder=None whereClause=self.whereClauseString() + + # LIMIT + ## TBD LIMIT: if limit -> add SortingOrdering('id',compareAscending) + ## TBD LIMIT: if isDeep=1 --> error + if fetchSpec: + self.setFetchSlice(fetchSpec.fetchSlice()) + # orderBy: see fetchSpec... ! for so in fetchSpec and fetchSpec.sortOrderings() or (): ! self.addOrderByAttributeOrdering(so) ! orderByClause=self.orderByString() if count: *************** *** 795,799 **** else: columnList=self.listString() ! self.assembleSelectStatementWithAttributes(attributes=attributes, lock=lock, --- 873,879 ---- else: columnList=self.listString() ! ! limitClause=self.limitString() ! self.assembleSelectStatementWithAttributes(attributes=attributes, lock=lock, *************** *** 806,810 **** joinClause=joinClause, orderByClause=orderByClause, ! lockClause=lockClause) --- 886,891 ---- joinClause=joinClause, orderByClause=orderByClause, ! lockClause=lockClause, ! limitClause=limitClause) *************** *** 851,854 **** --- 932,948 ---- updateList, self.whereClauseString()) + def setFetchSlice(self, slice): + """ + + Parameter: + + slice -- a mapping with both keys 'limit' and 'offset' + + See also: fetchSlice(), FetchSpecification.fetchSlice() + """ + if 'limit' not in slice.keys() or 'offset' not in slice.keys(): + raise ValueError, "Parameter slice should have keys 'limit' and 'offset'" + self._fetchSlice=slice + def setStatement(self, statement): """ *************** *** 945,948 **** --- 1039,1044 ---- description of what 'building the path' means). + Raises ValueError in case 'name' is not a valid attribute's name. + See also: sqlStringForAttribute, sqlStringForAttributePath() Attribute.isFlattened(), Attribute.relationshipPathObjects(), *************** *** 954,957 **** --- 1050,1055 ---- attribute=self.entity().attributeNamed(name) + if not attribute: + raise ValueError, "Unknown attribute '%s' for entity '%s'"%(name, self.entity().name()) if attribute.isDerived() and not attribute.isFlattened(): raise ValueError, "Error: attribute %s shouldn't be derived"%name |