Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6365

Show
Ignore:
Timestamp:
03/09/07 03:25:37 (1 year ago)
Author:
bitsweat
Message:

Merge [6364] from trunk. Consistently quote primary key column names. References #7763.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1-2-stable/activerecord/CHANGELOG

    r6361 r6365  
    11*SVN* 
     2 
     3* Consistently quote primary key column names.  #7763 [toolmantim] 
    24 
    35* Fixtures: fix YAML ordered map support.  #2665 [Manuel Holtgrewe, nfbuckley] 
  • branches/1-2-stable/activerecord/lib/active_record/base.rb

    r6122 r6365  
    480480      # are deleted. 
    481481      def delete(id) 
    482         delete_all([ "#{primary_key} IN (?)", id ]) 
     482        delete_all([ "#{connection.quote_column_name(primary_key)} IN (?)", id ]) 
    483483      end 
    484484 
     
    527527      # that needs to list both the number of posts and comments. 
    528528      def increment_counter(counter_name, id) 
    529         update_all "#{counter_name} = #{counter_name} + 1", "#{primary_key} = #{quote_value(id)}" 
     529        update_all "#{connection.quote_column_name(counter_name)} = #{connection.quote_column_name(counter_name)} + 1", "#{connection.quote_column_name(primary_key)} = #{quote_value(id)}" 
    530530      end 
    531531 
    532532      # Works like increment_counter, but decrements instead. 
    533533      def decrement_counter(counter_name, id) 
    534         update_all "#{counter_name} = #{counter_name} - 1", "#{primary_key} = #{quote_value(id)}" 
     534        update_all "#{connection.quote_column_name(counter_name)} = #{connection.quote_column_name(counter_name)} - 1", "#{connection.quote_column_name(primary_key)} = #{quote_value(id)}" 
    535535      end 
    536536 
     
    10211021        def find_one(id, options) 
    10221022          conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions] 
    1023           options.update :conditions => "#{table_name}.#{primary_key} = #{quote_value(id,columns_hash[primary_key])}#{conditions}" 
     1023          options.update :conditions => "#{table_name}.#{connection.quote_column_name(primary_key)} = #{quote_value(id,columns_hash[primary_key])}#{conditions}" 
    10241024 
    10251025          # Use find_every(options).first since the primary key condition 
     
    10361036          conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions] 
    10371037          ids_list   = ids.map { |id| quote_value(id,columns_hash[primary_key]) }.join(',') 
    1038           options.update :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}" 
     1038          options.update :conditions => "#{table_name}.#{connection.quote_column_name(primary_key)} IN (#{ids_list})#{conditions}" 
    10391039 
    10401040          result = find_every(options) 
     
    15591559          connection.delete <<-end_sql, "#{self.class.name} Destroy" 
    15601560            DELETE FROM #{self.class.table_name} 
    1561             WHERE #{self.class.primary_key} = #{quoted_id} 
     1561            WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quoted_id} 
    15621562          end_sql 
    15631563        end 
     
    17981798          "UPDATE #{self.class.table_name} " + 
    17991799          "SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))} " + 
    1800           "WHERE #{self.class.primary_key} = #{quote_value(id)}", 
     1800          "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quote_value(id)}", 
    18011801          "#{self.class.name} Update" 
    18021802        ) 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/db2.drop.sql

    r4596 r6365  
    3030DROP TABLE legacy_things; 
    3131DROP TABLE numeric_data; 
     32DROP TABLE mixed_case_monkeys; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/db2.sql

    r4596 r6365  
    225225  decimal_number_with_default DECIMAL(3,2) DEFAULT 2.78 
    226226); 
     227 
     228CREATE TABLE mixed_case_monkeys ( 
     229 monkeyID INT NOT NULL PRIMARY KEY, 
     230 fleaCount INT 
     231); 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/firebird.drop.sql

    r4596 r6365  
    3131DROP TABLE legacy_things; 
    3232DROP TABLE numeric_data; 
     33DROP TABLE mixed_case_monkeys; 
    3334 
    3435DROP DOMAIN D_BOOLEAN; 
     
    6061DROP GENERATOR legacy_things_seq; 
    6162DROP GENERATOR numeric_data_seq; 
     63DROP GENERATOR mixed_case_monkeys_seq; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/firebird.sql

    r4596 r6365  
    296296CREATE GENERATOR numeric_data_seq; 
    297297SET GENERATOR numeric_data_seq TO 10000; 
     298 
     299CREATE TABLE mixed_case_monkeys ( 
     300 "monkeyID" BIGINT NOT NULL, 
     301 "fleaCount" INTEGER 
     302); 
     303CREATE GENERATOR mixed_case_monkeys_seq; 
     304SET GENERATOR mixed_case_monkeys_seq TO 10000; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/frontbase.drop.sql

    r4596 r6365  
    3030DROP TABLE legacy_things CASCADE; 
    3131DROP TABLE numeric_data CASCADE; 
     32DROP TABLE mixed_case_monkeys CASCADE; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/frontbase.sql

    r4596 r6365  
    261261); 
    262262SET UNIQUE FOR numeric_data(id); 
     263 
     264CREATE TABLE mixed_case_monkeys ( 
     265 "monkeyID" integer DEFAULT unique, 
     266 "fleaCount" integer 
     267); 
     268SET UNIQUE FOR mixed_case_monkeys("monkeyID"); 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/mysql.drop.sql

    r4596 r6365  
    3030DROP TABLE legacy_things; 
    3131DROP TABLE numeric_data; 
     32DROP TABLE mixed_case_monkeys; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/mysql.sql

    r5752 r6365  
    227227  `decimal_number_with_default` decimal(3,2) DEFAULT 2.78 
    228228) TYPE=InnoDB; 
     229 
     230CREATE TABLE mixed_case_monkeys ( 
     231 `monkeyID` int(11) NOT NULL auto_increment, 
     232 `fleaCount` int(11), 
     233 PRIMARY KEY (`monkeyID`) 
     234) TYPE=InnoDB; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/openbase.sql

    r4596 r6365  
    293293CREATE PRIMARY KEY numeric_data (id) 
    294294go 
     295 
     296CREATE TABLE mixed_case_monkeys ( 
     297  monkeyID INTEGER NOT NULL DEFAULT _rowid, 
     298  fleaCount INTEGER 
     299); 
     300go 
     301CREATE PRIMARY KEY mixed_case_monkeys (monkeyID) 
     302go 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/oracle.drop.sql

    r4596 r6365  
    3131drop table legacy_things; 
    3232drop table numeric_data; 
     33drop table mixed_case_monkeys; 
    3334 
    3435drop sequence accounts_seq; 
     
    6263drop sequence legacy_things_seq; 
    6364drop sequence numeric_data_seq; 
     65drop sequence mixed_case_monkeys_seq; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/oracle.sql

    r5934 r6365  
    318318); 
    319319create sequence numeric_data_seq minvalue 10000; 
     320 
     321CREATE TABLE mixed_case_monkeys ( 
     322 "monkeyID" INTEGER NOT NULL PRIMARY KEY, 
     323 "fleaCount" INTEGER 
     324); 
     325create sequence mixed_case_monkeys_seq minvalue 10000; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/postgresql.drop.sql

    r4596 r6365  
    3535DROP TABLE numeric_data; 
    3636DROP TABLE column_data; 
     37DROP TABLE mixed_case_monkeys; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/postgresql.sql

    r5599 r6365  
    257257  decimal_number_with_default decimal(3,2) default 2.78 
    258258); 
     259 
     260CREATE TABLE mixed_case_monkeys ( 
     261 "monkeyID" INTEGER PRIMARY KEY, 
     262 "fleaCount" INTEGER 
     263); 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/sqlite.drop.sql

    r4596 r6365  
    3030DROP TABLE legacy_things; 
    3131DROP TABLE numeric_data; 
     32DROP TABLE mixed_case_monkeys; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/sqlite.sql

    r5661 r6365  
    209209  'decimal_number_with_default' DECIMAL(3,2) DEFAULT 2.78 
    210210); 
     211 
     212CREATE TABLE mixed_case_monkeys ( 
     213 'monkeyID' INTEGER NOT NULL PRIMARY KEY, 
     214 'fleaCount' INTEGER 
     215); 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/sqlserver.drop.sql

    r5892 r6365  
    3232DROP TABLE numeric_data; 
    3333DROP TABLE [order]; 
     34DROP TABLE mixed_case_monkeys; 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/sqlserver.sql

    r5892 r6365  
    237237  flavor varchar(255) 
    238238); 
     239 
     240CREATE TABLE mixed_case_monkeys ( 
     241  [monkeyID] int NOT NULL IDENTITY(1, 1), 
     242  [fleaCount] int default NULL 
     243); 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/sybase.drop.sql

    r5840 r6365  
    3030DROP TABLE legacy_things 
    3131DROP TABLE numeric_data 
     32DROP TABLE mixed_case_monkeys 
    3233DROP TABLE schema_info 
    3334go 
  • branches/1-2-stable/activerecord/test/fixtures/db_definitions/sybase.sql

    r5840 r6365  
    211211) 
    212212 
     213CREATE TABLE mixed_case_monkeys ( 
     214  [monkeyID] numeric(9,0) IDENTITY PRIMARY KEY, 
     215  [fleaCount] numeric(9,0) 
     216); 
     217 
    213218go 
  • branches/1-2-stable/activerecord/test/pk_test.rb

    r4291 r6365  
    55require 'fixtures/movie' 
    66require 'fixtures/keyboard' 
     7require 'fixtures/mixed_case_monkey' 
    78 
    89class PrimaryKeysTest < Test::Unit::TestCase 
    9   fixtures :topics, :subscribers, :movies 
     10  fixtures :topics, :subscribers, :movies, :mixed_case_monkeys 
    1011 
    1112  def test_integer_key 
     
    7980    assert_equal "id", Topic.primary_key 
    8081  end 
     82   
     83  def test_delete_should_quote_pkey 
     84    assert_nothing_raised { MixedCaseMonkey.delete(1) } 
     85  end 
     86  def test_increment_counter_should_quote_pkey_and_quote_counter_columns 
     87    assert_nothing_raised { MixedCaseMonkey.increment_counter(:fleaCount, 1) } 
     88  end 
     89  def test_decrement_counter_should_quote_pkey_and_quote_counter_columns 
     90    assert_nothing_raised { MixedCaseMonkey.decrement_counter(:fleaCount, 1) } 
     91  end 
     92  def test_find_with_one_id_should_quote_pkey 
     93    assert_nothing_raised { MixedCaseMonkey.find(1) } 
     94  end 
     95  def test_find_with_multiple_ids_should_quote_pkey 
     96    assert_nothing_raised { MixedCaseMonkey.find([1,2]) } 
     97  end 
     98  def test_instance_update_should_quote_pkey 
     99    assert_nothing_raised { MixedCaseMonkey.find(1).save } 
     100  end 
     101  def test_instance_destry_should_quote_pkey 
     102    assert_nothing_raised { MixedCaseMonkey.find(1).destroy } 
     103  end 
    81104end