public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix validates_uniqueness_of for SQL keywords [#23 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
maccman (author)
Sun May 04 04:28:08 -0700 2008
lifo (committer)
Sun May 11 11:30:03 -0700 2008
commit  4cc594bd708df1ec67b61833493198ab0009c627
tree    f641a527800f7820487b799d2712d912c8cab47d
parent  0dabb5b7ab3fad23da91a2312f7b586855d52f4a
...
640
641
642
643
 
644
645
646
...
640
641
642
 
643
644
645
646
0
@@ -640,7 +640,7 @@ module ActiveRecord
0
           results = finder_class.with_exclusive_scope do
0
             connection.select_all(
0
               construct_finder_sql(
0
-                :select     => "#{attr_name}",
0
+                :select     => "#{connection.quote_column_name(attr_name)}",
0
                 :from       => "#{finder_class.quoted_table_name}",
0
                 :conditions => [condition_sql, *condition_params]
0
               )
...
5
6
7
 
8
9
10
...
493
494
495
 
 
 
 
 
 
 
496
497
498
...
5
6
7
8
9
10
11
...
494
495
496
497
498
499
500
501
502
503
504
505
506
0
@@ -5,6 +5,7 @@ require 'models/reply'
0
 require 'models/person'
0
 require 'models/developer'
0
 require 'models/warehouse_thing'
0
+require 'models/guid'
0
 
0
 # The following methods in Topic are used in test_conditional_validation_*
0
 class Topic
0
@@ -493,6 +494,13 @@ class ValidationsTest < ActiveRecord::TestCase
0
     end
0
   end
0
 
0
+  def test_validate_uniqueness_with_columns_which_are_sql_keywords
0
+    Guid.validates_uniqueness_of :key
0
+    g = Guid.new
0
+    g.key = "foo"
0
+    assert_nothing_raised { !g.valid? }
0
+  end
0
+
0
   def test_validate_straight_inheritance_uniqueness
0
     w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork")
0
     assert w1.valid?, "Saving w1"
...
403
404
405
 
 
 
 
406
407
408
...
403
404
405
406
407
408
409
410
411
412
0
@@ -403,6 +403,10 @@ ActiveRecord::Schema.define do
0
     create_table(t, :force => true) { }
0
   end
0
 
0
+  create_table :guids, :force => true do |t|
0
+    t.column :key, :string
0
+  end
0
+
0
   except 'SQLite' do
0
     # fk_test_has_fk should be before fk_test_has_pk
0
     create_table :fk_test_has_fk, :force => true do |t|

Comments