Class: ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
- Defined in:
- lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract_mysql_adapter.rb,
lib/activerecord-mysql-unsigned/active_record/v4/connection_adapters/abstract_mysql_adapter.rb
Direct Known Subclasses
Instance Method Summary collapse
- #add_column_sql(table_name, column_name, type, options = {}) ⇒ Object
- #change_column_sql(table_name, column_name, type, options = {}) ⇒ Object
-
#type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = false) ⇒ Object
Maps logical Rails types to MySQL-specific data types.
Instance Method Details
#add_column_sql(table_name, column_name, type, options = {}) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract_mysql_adapter.rb', line 45 def add_column_sql(table_name, column_name, type, = {}) add_column_sql = "ADD #{quote_column_name(column_name)} #{type_to_sql(type, [:limit], [:precision], [:scale], [:unsigned], [:auto_increment])}" (add_column_sql, ) add_column_position!(add_column_sql, ) add_column_sql end |
#change_column_sql(table_name, column_name, type, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract_mysql_adapter.rb', line 52 def change_column_sql(table_name, column_name, type, = {}) column = column_for(table_name, column_name) unless type.to_sym == :primary_key unless () [:default] = column.default end unless .has_key?(:null) [:null] = column.null end end change_column_sql = "CHANGE #{quote_column_name(column_name)} #{quote_column_name(column_name)} #{type_to_sql(type, [:limit], [:precision], [:scale], [:unsigned], [:auto_increment])}" (change_column_sql, ) add_column_position!(change_column_sql, ) change_column_sql end |
#type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = false) ⇒ Object
Maps logical Rails types to MySQL-specific data types.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/activerecord-mysql-unsigned/active_record/v3/connection_adapters/abstract_mysql_adapter.rb', line 12 def type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = false, auto_increment = false) case type.to_s when 'integer' case limit when 1 'tinyint' + (unsigned ? ' unsigned' : '') + (auto_increment ? ' AUTO_INCREMENT' : '') when 2 'smallint' + (unsigned ? ' unsigned' : '') + (auto_increment ? ' AUTO_INCREMENT' : '') when 3 'mediumint' + (unsigned ? ' unsigned' : '') + (auto_increment ? ' AUTO_INCREMENT' : '') when nil, 4, 11 # compatibility with MySQL default if unsigned 'int(10) unsigned' + (auto_increment ? ' AUTO_INCREMENT' : '') else 'int(10)' end when 5..8 'bigint' + (unsigned ? ' unsigned' : '') else raise(ActiveRecordError, "No integer type has byte size #{limit}") end when 'text' case limit when 0..0xff; 'tinytext' when nil, 0x100..0xffff; 'text' when 0x10000..0xffffff; 'mediumtext' when 0x1000000..0xffffffff; 'longtext' else raise(ActiveRecordError, "No text type has character length #{limit}") end else super end end |