[CalendarServer-changes] [7141] CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 7 19:05:16 PST 2011


Revision: 7141
          http://trac.macosforge.org/projects/calendarserver/changeset/7141
Author:   glyph at apple.com
Date:     2011-03-07 19:05:16 -0800 (Mon, 07 Mar 2011)
Log Message:
-----------
'ACCESS' is an SQL keyword, and we have a column with that name, so use double-quotes to explicitly frame it.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_sqlsyntax.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:05:04 UTC (rev 7140)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py	2011-03-08 03:05:16 UTC (rev 7141)
@@ -430,6 +430,7 @@
         return Join(self, type, otherTable, on)
 
 
+_KEYWORDS = ["access"]
 
 
 class ColumnSyntax(ExpressionSyntax):
@@ -447,13 +448,16 @@
     def subSQL(self, metadata, allTables):
         # XXX This, and 'model', could in principle conflict with column names.
         # Maybe do something about that.
+        name = self.model.name
+        if name.lower() in _KEYWORDS:
+            name = '"%s"' % (name,)
+
         for tableSyntax in allTables:
             if self.model.table is not tableSyntax.model:
                 if self.model.name in (c.name for c in
                                                tableSyntax.model.columns):
-                    return SQLFragment((self.model.table.name + '.' +
-                                         self.model.name))
-        return SQLFragment(self.model.name)
+                    return SQLFragment((self.model.table.name + '.' + name))
+        return SQLFragment(name)
 
 
 

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_sqlsyntax.py	2011-03-08 03:05:04 UTC (rev 7140)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_sqlsyntax.py	2011-03-08 03:05:16 UTC (rev 7141)
@@ -63,6 +63,7 @@
                        create table OTHER (BAR integer,
                                            FOO_BAR integer not null);
                        create table TEXTUAL (MYTEXT varchar(255));
+                       create table LEVELS (ACCESS integer, USERNAME varchar(255));
                        """)
         self.schema = SchemaSyntax(s)
 
@@ -555,6 +556,20 @@
         )
 
 
+    def test_quotingOnKeywordConflict(self):
+        """
+        'access' is a keyword, so although our schema parser will leniently
+        accept it, it must be quoted in any outgoing SQL.
+        """
+        self.assertEquals(
+            Insert({self.schema.LEVELS.ACCESS: 1,
+                    self.schema.LEVELS.USERNAME: "hi"}).toSQL(),
+            SQLFragment(
+                'insert into LEVELS ("ACCESS", USERNAME) values (?, ?)',
+                [1, "hi"])
+        )
+
+
     def test_updateReturning(self):
         """
         L{update}'s C{Return} argument will update an SQL 'returning' clause.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110307/60f56aea/attachment.html>


More information about the calendarserver-changes mailing list