]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
cleanup
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Nov 2011 03:10:49 +0000 (22:10 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 22 Nov 2011 03:10:49 +0000 (22:10 -0500)
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/sql/compiler.py

index 2433d24522e1a1a458799d1cedc25ea831235af3..226180247368f95fbdd526e872bd46f7dbe89c2c 100644 (file)
@@ -1180,6 +1180,9 @@ class MySQLExecutionContext(default.DefaultExecutionContext):
 
 class MySQLCompiler(compiler.SQLCompiler):
 
+    render_table_with_column_in_update_from = True
+    """Overridden from base SQLCompiler value"""
+
     extract_map = compiler.SQLCompiler.extract_map.copy()
     extract_map.update ({
         'milliseconds': 'millisecond',
@@ -1329,8 +1332,6 @@ class MySQLCompiler(compiler.SQLCompiler):
     def update_from_clause(self, update_stmt, from_table, extra_froms, **kw):
         return None
 
-    render_table_with_column_in_update = True
-
 
 # ug.  "InnoDB needs indexes on foreign keys and referenced keys [...].
 #       Starting with MySQL 4.1.2, these indexes are created automatically.
index 92c0c7b38de8771614e8e32ab814056f95681d87..24c3687e9bc12200b94f76e998b8e874f291f75d 100644 (file)
@@ -177,26 +177,36 @@ class SQLCompiler(engine.Compiled):
 
     compound_keywords = COMPOUND_KEYWORDS
 
-    # class-level defaults which can be set at the instance
-    # level to define if this Compiled instance represents
-    # INSERT/UPDATE/DELETE
     isdelete = isinsert = isupdate = False
+    """class-level defaults which can be set at the instance
+    level to define if this Compiled instance represents
+    INSERT/UPDATE/DELETE
+    """
 
-    # holds the "returning" collection of columns if
-    # the statement is CRUD and defines returning columns
-    # either implicitly or explicitly
     returning = None
+    """holds the "returning" collection of columns if
+    the statement is CRUD and defines returning columns
+    either implicitly or explicitly
+    """
 
-    # set to True classwide to generate RETURNING
-    # clauses before the VALUES or WHERE clause (i.e. MSSQL)
     returning_precedes_values = False
+    """set to True classwide to generate RETURNING
+    clauses before the VALUES or WHERE clause (i.e. MSSQL)
+    """
+
+    render_table_with_column_in_update_from = False
+    """set to True classwide to indicate the SET clause
+    in a multi-table UPDATE statement should qualify
+    columns with the table name (i.e. MySQL only)
+    """
 
-    # SQL 92 doesn't allow bind parameters to be used
-    # in the columns clause of a SELECT, nor does it allow
-    # ambiguous expressions like "? = ?".  A compiler
-    # subclass can set this flag to False if the target
-    # driver/DB enforces this
     ansi_bind_rules = False
+    """SQL 92 doesn't allow bind parameters to be used
+    in the columns clause of a SELECT, nor does it allow
+    ambiguous expressions like "? = ?".  A compiler
+    subclass can set this flag to False if the target
+    driver/DB enforces this
+    """
 
     def __init__(self, dialect, statement, column_keys=None, 
                     inline=False, **kwargs):
@@ -986,15 +996,29 @@ class SQLCompiler(engine.Compiled):
         return text
 
     def update_limit_clause(self, update_stmt):
+        """Provide a hook for MySQL to add LIMIT to the UPDATE"""
         return None
 
-    def update_tables_clause(self, update_stmt, from_table, extra_froms, **kw):
+    def update_tables_clause(self, update_stmt, from_table, 
+                                            extra_froms, **kw):
+        """Provide a hook to override the initial table clause
+        in an UPDATE statement.
+        
+        MySQL overrides this.
+
+        """
         return self.preparer.format_table(from_table)
 
     def update_from_clause(self, update_stmt, from_table, extra_froms, **kw):
-        return "FROM " + ', '.join(t._compiler_dispatch(self, asfrom=True, **kw) for t in extra_froms)
+        """Provide a hook to override the generation of an 
+        UPDATE..FROM clause.
+        
+        MySQL overrides this.
 
-    render_table_with_column_in_update = False
+        """
+        return "FROM " + ', '.join(
+                    t._compiler_dispatch(self, asfrom=True, **kw) 
+                    for t in extra_froms)
 
     def visit_update(self, update_stmt, **kw):
         self.stack.append({'from': set([update_stmt.table])})
@@ -1005,20 +1029,16 @@ class SQLCompiler(engine.Compiled):
             extra_froms = set(update_stmt._whereclause._from_objects).\
                             difference([update_stmt.table])
         else:
-            extra_froms = set()
+            extra_froms = None
 
         colparams = self._get_colparams(update_stmt, extra_froms)
 
-        #for c in colparams:
-        #    if hasattr(c[1], '_from_objects'):
-        #        extra_froms.update(c[1]._from_objects)
-
         text = "UPDATE " + self.update_tables_clause(
                                         update_stmt, 
                                         update_stmt.table, 
                                         extra_froms, **kw)
 
-        if extra_froms and self.render_table_with_column_in_update:
+        if extra_froms and self.render_table_with_column_in_update_from:
             text += ' SET ' + \
                     ', '.join(
                             self.visit_column(c[0]) +