Changeset 6848
- Timestamp:
- 05/26/07 00:20:37 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (modified) (7 diffs)
- trunk/activerecord/test/active_schema_test_mysql.rb (modified) (2 diffs)
- trunk/activerecord/test/adapter_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6845 r6848 1 1 *SVN* 2 3 * MySQL: create_database takes :charset and :collation options. Charset defaults to utf8. #8448 [matt] 2 4 3 5 * Find with a list of ids supports limit/offset. #8437 [hrudududu] trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
r6678 r6848 210 210 "1" 211 211 end 212 212 213 213 def quoted_false 214 214 "0" … … 239 239 connect 240 240 end 241 241 242 242 def disconnect! 243 243 @connection.close rescue nil … … 305 305 sql = "SHOW TABLES" 306 306 end 307 307 308 308 select_all(sql).inject("") do |structure, table| 309 309 table.delete('Table_type') … … 317 317 end 318 318 319 def create_database(name) #:nodoc: 320 execute "CREATE DATABASE `#{name}`" 321 end 322 319 # Create a new MySQL database with optional :charset and :collation. 320 # Charset defaults to utf8. 321 # 322 # Example: 323 # create_database 'charset_test', :charset => 'latin1', :collation => 'latin1_bin' 324 # create_database 'matt_development' 325 # create_database 'matt_development', :charset => :big5 326 def create_database(name, options = {}) 327 if options[:collation] 328 execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{options[:charset] || 'utf8'}` COLLATE `#{options[:collation]}`" 329 else 330 execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{options[:charset] || 'utf8'}`" 331 end 332 end 333 323 334 def drop_database(name) #:nodoc: 324 335 execute "DROP DATABASE IF EXISTS `#{name}`" … … 326 337 327 338 def current_database 328 select_one("SELECT DATABASE() as db")["db"] 339 select_value 'SELECT DATABASE() as db' 340 end 341 342 # Returns the database character set. 343 def charset 344 show_variable 'character_set_database' 345 end 346 347 # Returns the database collation strategy. 348 def collation 349 show_variable 'collation_database' 329 350 end 330 351 … … 360 381 super(name, {:options => "ENGINE=InnoDB"}.merge(options)) 361 382 end 362 383 363 384 def rename_table(name, new_name) 364 385 execute "RENAME TABLE #{name} TO #{new_name}" 365 end 386 end 366 387 367 388 def change_column_default(table_name, column_name, default) #:nodoc: … … 386 407 end 387 408 409 410 # SHOW VARIABLES LIKE 'name' 411 def show_variable(name) 412 select_value "SHOW VARIABLES LIKE '#{name}'" 413 end 388 414 389 415 private trunk/activerecord/test/active_schema_test_mysql.rb
r4571 r6848 6 6 alias_method :real_execute, :execute 7 7 def execute(sql, name = nil) return sql end 8 end 8 end 9 9 end 10 10 11 11 def teardown 12 12 ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:alias_method, :execute, :real_execute) … … 16 16 assert_equal "DROP TABLE people", drop_table(:people) 17 17 end 18 18 19 if current_adapter?(:MysqlAdapter) 20 def test_create_mysql_database_with_encoding 21 assert_equal "CREATE DATABASE `matt` DEFAULT CHARACTER SET `utf8`", create_database(:matt) 22 assert_equal "CREATE DATABASE `aimonetti` DEFAULT CHARACTER SET `latin1`", create_database(:aimonetti, {:charset => 'latin1'}) 23 assert_equal "CREATE DATABASE `matt_aimonetti` DEFAULT CHARACTER SET `big5` COLLATE `big5_chinese_ci`", create_database(:matt_aimonetti, {:charset => :big5, :collation => :big5_chinese_ci}) 24 end 25 end 26 19 27 def test_add_column 20 28 assert_equal "ALTER TABLE people ADD `last_name` varchar(255)", add_column(:people, :last_name, :string) 21 29 end 22 30 23 31 def test_add_column_with_limit 24 32 assert_equal "ALTER TABLE people ADD `key` varchar(32)", add_column(:people, :key, :string, :limit => 32) 25 33 end 26 34 27 35 private 28 36 def method_missing(method_symbol, *arguments) trunk/activerecord/test/adapter_test.rb
r4291 r6848 20 20 def test_indexes 21 21 idx_name = "accounts_idx" 22 22 23 23 if @connection.respond_to?(:indexes) 24 24 indexes = @connection.indexes("accounts") … … 40 40 @connection.remove_index(:accounts, :name => idx_name) rescue nil 41 41 end 42 42 43 43 def test_current_database 44 44 if @connection.respond_to?(:current_database) 45 45 assert_equal ENV['ARUNIT_DB_NAME'] || "activerecord_unittest", @connection.current_database 46 end 47 end 48 49 if current_adapter?(:MysqlAdapter) 50 def test_charset 51 assert @connection.charset 52 end 53 54 def test_collation 55 assert @connection.collation 46 56 end 47 57 end … … 53 63 alias_method :table_alias_length, :test_table_alias_length 54 64 end 55 65 56 66 assert_equal 'posts', @connection.table_alias_for('posts') 57 67 assert_equal 'posts_comm', @connection.table_alias_for('posts_comments') 58 68 assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts') 59 69 60 70 class << @connection 61 71 alias_method :table_alias_length, :old_table_alias_length … … 67 77 require 'fixtures/movie' 68 78 require 'fixtures/subscriber' 69 79 70 80 def test_reset_empty_table_with_custom_pk 71 81 Movie.delete_all