<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,9 @@
 
 MASTER
 
+* Allow query_requires_identity_insert? method to return quoted table name in situations where the 
+  INSERT parts are not quoted themselves. [Gary/iawgens, Richard Penwell, Ken Collins]
+
 * Fixed namespace in calling test_sqlserver_odbc within test_unicode_types. [Gary/iawgens]
 
 * Columns with multi-line defaults work correctly. [bfabry]</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -946,7 +946,7 @@ module ActiveRecord
         if insert_sql?(sql)
           table_name = get_table_name(sql)
           id_column = identity_column(table_name)
-          id_column &amp;&amp; sql =~ /INSERT[^(]+\([^)]*\[#{id_column.name}\][^)]*\)/i ? table_name : false
+          id_column &amp;&amp; sql =~ /INSERT[^(]+\([^)]*\b(#{id_column.name})\b,?[^)]*\)/i ? quote_table_name(table_name) : false
         else
           false
         end</diff>
      <filename>lib/active_record/connection_adapters/sqlserver_adapter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -328,10 +328,14 @@ class AdapterTestSqlserver &lt; ActiveRecord::TestCase
     
     setup do
       @identity_insert_sql = &quot;INSERT INTO [funny_jokes] ([id],[name]) VALUES(420,'Knock knock')&quot;
+      @identity_insert_sql_unquoted = &quot;INSERT INTO funny_jokes (id, name) VALUES(420, 'Knock knock')&quot;
+      @identity_insert_sql_unordered = &quot;INSERT INTO [funny_jokes] ([name],[id]) VALUES('Knock knock',420)&quot;
     end
     
-    should 'return quoted table_name to #query_requires_identity_insert? when INSERT sql contains id_column' do
+    should 'return quoted table_name to #query_requires_identity_insert? when INSERT sql contains id column' do
       assert_equal '[funny_jokes]', @connection.send(:query_requires_identity_insert?,@identity_insert_sql)
+      assert_equal '[funny_jokes]', @connection.send(:query_requires_identity_insert?,@identity_insert_sql_unquoted)
+      assert_equal '[funny_jokes]', @connection.send(:query_requires_identity_insert?,@identity_insert_sql_unordered)
     end
     
     should 'return false to #query_requires_identity_insert? for normal SQL' do</diff>
      <filename>test/cases/adapter_test_sqlserver.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>92c2d77b8240f78066843484b62fe0b8ff34447f</id>
    </parent>
  </parents>
  <author>
    <name>Ken Collins</name>
    <email>ken@metaskills.net</email>
  </author>
  <url>http://github.com/rails-sqlserver/2000-2005-adapter/commit/4d208acc503bfb31f67857dfc1acae48e857d954</url>
  <id>4d208acc503bfb31f67857dfc1acae48e857d954</id>
  <committed-date>2009-11-02T12:41:21-08:00</committed-date>
  <authored-date>2009-11-02T12:41:21-08:00</authored-date>
  <message>Allow query_requires_identity_insert? method to return quoted table name in situations where the INSERT parts are not quoted themselves.</message>
  <tree>864663771811b59bff8f4ff9d859c1a705dc226f</tree>
  <committer>
    <name>Ken Collins</name>
    <email>ken@metaskills.net</email>
  </committer>
</commit>
