<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -47,8 +47,8 @@ module ActiveRecord #:nodoc:
       # Returns the names (or aliases if used) of each table used in a JOIN fragment
       def table_aliases_from_join_fragment(sql)
         return [] if sql.blank?
-        return sql.scan(/JOIN\s+(`[^`]`|\S+)(?:\s+(?:AS\s+)?(`[^`]`|\S+))?/i).collect do |name|
-          ((name[1] =~ /^ON$/i) ? name[0] : (name[1] || name[0])).gsub(/^`(.*)`$/, '\1')
+        return sql.scan(/JOIN\s+(`[^`]+`|&quot;[^&quot;]+&quot;|\[[^\]]+\]|\S+)(?:\s+(?:AS\s+)?(`[^`]+`|&quot;[^&quot;]+&quot;|\[[^\]]+\]|\S+))?/i).collect do |name|
+          ((name[1] =~ /^ON$/i) ? name[0] : (name[1] || name[0])).gsub(/^[`&quot;\[]?(.*)[`&quot;\]]?$/, '\1')
         end
       end
       
@@ -73,15 +73,15 @@ module ActiveRecord #:nodoc:
       # Modifies the SQL fragment such that every instance of +old_table_name+
       # is replaced by or aliased using (in JOIN ... AS blocks) +new_alias+.
       def convert_table_name_to_new_alias!(sql, old_table_name, new_alias)
-        regex = Regexp.new(&quot;(?:(?:JOIN|AS)?\\s+|\\()`?#{old_table_name}`?(?:\\s+(?:AS\\s+)?(?:`[^`]`|\\S+)|\\.|\\s)&quot;, Regexp::IGNORECASE)
+        regex = Regexp.new(&quot;(?:(?:JOIN|AS)?\\s+|\\()[`\&quot;\\[]?#{old_table_name}[`\&quot;\\]]?(?:\\s+(?:AS\\s+)?(?:`[^`]+`|\&quot;[^\&quot;]+\&quot;|\\[[^\\]]+\\]|\\S+)|\\.|\\s)&quot;, Regexp::IGNORECASE)
         sql.gsub!(regex) do |match|
           prefix = (match =~ /^\(/) ? '(' : ''
           suffix = match.gsub(/^.*?(\s+ON|.)$/i, '\1')
-          if test = match.match(/^JOIN\s+(?:`[^`]`|\S+)(\s+(?:AS\s+)?(?:`[^`]`|\S+))/i) and !(test.captures.first =~ /^ ON$/i)
+          if test = match.match(/^JOIN\s+(?:`[^`]+`|&quot;[^&quot;]+&quot;|\[[^\]]+\]|\S+)(\s+(?:AS\s+)?(?:`[^`]+`|&quot;[^&quot;]+&quot;|\[[^\]]+\]|\S+))/i) and !(test.captures.first =~ /^ ON$/i)
             # If the table name is already aliased within this match, don't replace it
             result = match
           else
-            replacement = &quot;JOIN `#{old_table_name}` AS #{new_alias}&quot; if match =~ /^JOIN\s/i
+            replacement = &quot;JOIN #{old_table_name} AS #{new_alias}&quot; if match =~ /^JOIN\s/i
             replacement = &quot;AS #{new_alias}&quot; if match =~ /^AS\s/i
             replacement = &quot; #{new_alias}&quot; unless match =~ /^(JOIN|AS)\s/i
             result = &quot;#{prefix}#{replacement}#{suffix}&quot;</diff>
      <filename>lib/class_methods.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>00229e8df6d21b517ae439d4b0849b0f8062acfc</id>
    </parent>
  </parents>
  <author>
    <name>James Coglan</name>
    <email>jcoglan@googlemail.com</email>
  </author>
  <url>http://github.com/jcoglan/include_by_default/commit/e4996a2ad6195b4d96abd18e28c9d83c49154719</url>
  <id>e4996a2ad6195b4d96abd18e28c9d83c49154719</id>
  <committed-date>2007-08-01T07:53:07-07:00</committed-date>
  <authored-date>2007-08-01T07:53:07-07:00</authored-date>
  <message>Modified regexps for better database compatibility.</message>
  <tree>f3ed1a89561e49e3f7041de6ffe6065aadfb073b</tree>
  <committer>
    <name>James Coglan</name>
    <email>jcoglan@googlemail.com</email>
  </committer>
</commit>
