[CalendarServer-changes] [7138] CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/ syntax.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 7 19:04:37 PST 2011


Revision: 7138
          http://trac.macosforge.org/projects/calendarserver/changeset/7138
Author:   glyph at apple.com
Date:     2011-03-07 19:04:37 -0800 (Mon, 07 Mar 2011)
Log Message:
-----------
Move _returningClause onto _DMLStatement superclass, since .on() will need some behavior for this as well.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py	2011-03-08 03:04:21 UTC (rev 7137)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py	2011-03-08 03:04:37 UTC (rev 7138)
@@ -730,33 +730,39 @@
                             for f in self.subfragments)
 
 
-def _returningClause(metadata, stmt, retclause, allTables):
+
+class _DMLStatement(_Statement):
     """
-    Add a dialect-appropriate 'returning' clause to the end of the given SQL
-    statement.
+    Common functionality of Insert/Update/Delete statements.
+    """
 
-    @param metadata: describes the database we are generating the statement for.
-    @type metadata: L{ConnectionMetadata}
+    def _returningClause(self, metadata, stmt, allTables):
+        """
+        Add a dialect-appropriate 'returning' clause to the end of the given SQL
+        statement.
 
-    @param stmt: the SQL fragment generated without the 'returning' clause
-    @type stmt: L{SQLFragment}
+        @param metadata: describes the database we are generating the statement for.
+        @type metadata: L{ConnectionMetadata}
 
-    @param retclause: the C{Return} argument from the current statement.
-    @type retclause: an object with a C{subSQL} method, or a C{tuple} or C{list}
-        of same.
+        @param stmt: the SQL fragment generated without the 'returning' clause
+        @type stmt: L{SQLFragment}
 
-    @return: the C{stmt} parameter.
-    """
-    if isinstance(retclause, (tuple, list)):
-        retclause = _CommaList(retclause)
-    if retclause is not None:
-        stmt.text += ' returning '
-        stmt.append(retclause.subSQL(metadata, allTables))
-    return stmt
+        @param allTables: all tables involved in the query; see any C{subSQL}
+            method.
 
+        @return: the C{stmt} parameter.
+        """
+        retclause = self.Return
+        if isinstance(retclause, (tuple, list)):
+            retclause = _CommaList(retclause)
+        if retclause is not None:
+            stmt.text += ' returning '
+            stmt.append(retclause.subSQL(metadata, allTables))
+        return stmt
 
 
-class Insert(_Statement):
+
+class Insert(_DMLStatement):
     """
     'insert' statement.
     """
@@ -805,7 +811,7 @@
         stmt.append(_inParens(_commaJoined(
             [_convert(v).subSQL(metadata, allTables)
              for (c, v) in sortedColumns])))
-        return _returningClause(metadata, stmt, self.Return, allTables)
+        return self._returningClause(metadata, stmt, allTables)
 
 
 
@@ -821,7 +827,7 @@
 
 
 
-class Update(_Statement):
+class Update(_DMLStatement):
     """
     'update' statement
     """
@@ -859,11 +865,11 @@
         )
         result.append(SQLFragment( ' where '))
         result.append(self.Where.subSQL(metadata, allTables))
-        return _returningClause(metadata, result, self.Return, allTables)
+        return self._returningClause(metadata, result, allTables)
 
 
 
-class Delete(_Statement):
+class Delete(_DMLStatement):
     """
     'delete' statement.
     """
@@ -881,7 +887,7 @@
         result.append(self.From.subSQL(metadata, allTables))
         result.text += ' where '
         result.append(self.Where.subSQL(metadata, allTables))
-        return _returningClause(metadata, result, self.Return, allTables)
+        return self._returningClause(metadata, result, allTables)
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110307/79c9a919/attachment-0001.html>


More information about the calendarserver-changes mailing list