Michael Manfre committed 18dca34

#69: Incorrectly used col_name instead of col_key

Comments (0)

Files changed (1)


 _re_order_limit_offset = re.compile(
     r'(?:ORDER BY\s+(.+?))?\s*(?:LIMIT\s+(\d+))?\s*(?:OFFSET\s+(\d+))?$')
+# Pattern to find the quoted column name at the end of a field specification
+_re_pat_col = re.compile(r"\[([^[]+)\]$")
+# Pattern to find each of the parts of a column name (extra_select, table, field)
+_re_pat_col_parts = re.compile(
+    r'(?:' +
+    r'(\([^\)]+\))\s+as\s+' +
+    r'|(\[[^[]+\])\.' +
+    r')?' +
+    r'\[([^[]+)\]$',
 def _break(s, find):
     """Break a string s into the part before the substring to find, 
     and the part including and after the substring."""
             order, limit_ignore, offset_ignore = _get_order_limit_offset(raw_sql)
             qn = self.connection.ops.quote_name
             inner_table_name = qn('AAAA')
             # Using ROW_NUMBER requires an ordering
             """Return tuple of SELECT and FROM clauses, aliasing duplicate column names."""
             qn = self.connection.ops.quote_name
-            # Pattern to find the quoted column name at the end of a field specification
-            _pat_col = r"\[([^[]+)\]$"  
-            #]) Funky comment to get e's syntax highlighting back on track. 
             outer = list()
             inner = list()
             names_seen = list()
             select_list, from_clause = _break(sql, ' FROM [')
             for col in [x.strip() for x in select_list.split(',')]:
-                col_name =, col).group(1)
+                col_name =
                 col_key = col_name.lower()
                 # If column name was already seen, alias it.
-                if col_name in names_seen:
+                if col_key in names_seen:
                     alias = qn('%s___%s' % (col_name, names_seen.count(col_key)))
                     inner.append("%s as %s" % (col, alias))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.