[CalendarServer-changes] [8660] CalendarServer/branches/users/glyph/table-alias
source_changes at macosforge.org
source_changes at macosforge.org
Mon Feb 13 10:03:52 PST 2012
Revision: 8660
http://trac.macosforge.org/projects/calendarserver/changeset/8660
Author: glyph at apple.com
Date: 2012-02-13 10:03:52 -0800 (Mon, 13 Feb 2012)
Log Message:
-----------
Fix table aliasing naming to pass the new test, and work more or less for real.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/table-alias/twext/enterprise/dal/syntax.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/table-alias/
Modified: CalendarServer/branches/users/glyph/table-alias/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/branches/users/glyph/table-alias/twext/enterprise/dal/syntax.py 2012-02-13 18:03:49 UTC (rev 8659)
+++ CalendarServer/branches/users/glyph/table-alias/twext/enterprise/dal/syntax.py 2012-02-13 18:03:52 UTC (rev 8660)
@@ -547,13 +547,33 @@
"""
def subSQL(self, metadata, allTables):
+ """
+ Return an L{SQLFragment} with a string of the form C{'mytable myalias'}
+ suitable for use in a FROM clause.
+ """
result = super(TableAlias, self).subSQL(metadata, allTables)
- result.append(SQLFragment(" alias1"))
+ result.append(SQLFragment(" " + self._aliasName(allTables)))
return result
+ def _aliasName(self, allTables):
+ """
+ The alias under which this table will be known in the query.
+
+ @param allTables: a C{list}, as passed to a C{subSQL} method during SQL
+ generation.
+
+ @return: a string naming this alias, a unique identifier, albeit one
+ which is only stable within the query which populated C{allTables}.
+ @rtype: C{str}
+ """
+ anum = [t for t in allTables
+ if isinstance(t, TableAlias)].index(self) + 1
+ return 'alias%d' % (anum,)
+
+
def __getattr__(self, attr):
- return AliasedColumnSyntax(self.model.columnNamed(attr))
+ return AliasedColumnSyntax(self, self.model.columnNamed(attr))
@@ -661,7 +681,7 @@
qualified = True
break
if qualified:
- return SQLFragment(self._qualify(name))
+ return SQLFragment(self._qualify(name, allTables))
else:
return SQLFragment(name)
@@ -670,7 +690,7 @@
return hash(self.model) + 10
- def _qualify(self, name):
+ def _qualify(self, name, allTables):
return self.model.table.name + '.' + name
@@ -684,13 +704,20 @@
@see: L{TableSyntax.alias}
"""
+
_alwaysQualified = True
- def _qualify(self, name):
- return 'alias1.' + name
+ def __init__(self, tableAlias, model):
+ super(AliasedColumnSyntax, self).__init__(model)
+ self._tableAlias = tableAlias
+ def _qualify(self, name, allTables):
+ return self._tableAlias._aliasName(allTables) + '.' + name
+
+
+
class Comparison(ExpressionSyntax):
def __init__(self, a, op, b):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120213/a13635f6/attachment-0001.html>
More information about the calendarserver-changes
mailing list