# File lib/arjdbc/mysql/adapter.rb, line 26 def extract_default(default) if sql_type =~ /blob/ || type == :text if default.blank? return null ? nil : '' else raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}" end elsif missing_default_forged_as_empty_string?(default) nil else super end end
# File lib/arjdbc/mysql/adapter.rb, line 55 def extract_limit(sql_type) case sql_type when /blob|text/ case sql_type when /tiny/ 255 when /medium/ 16777215 when /long/ 2147483647 # mysql only allows 2^31-1, not 2^32-1, somewhat inconsistently with the tiny/medium/normal cases else super # we could return 65535 here, but we leave it undecorated by default end when /^bigint/; 8 when /^int/; 4 when /^mediumint/; 3 when /^smallint/; 2 when /^tinyint/; 1 when /^enum\((.+)\)/ # 255 $1.split(',').map{ |enum| enum.strip.length - 2 }.max when /^(bool|date|float|int|time)/ nil else super end end
# File lib/arjdbc/mysql/adapter.rb, line 40 def has_default? return false if sql_type =~ /blob/ || type == :text #mysql forbids defaults on blob and text columns super end
MySQL misreports NOT NULL column default when none is given. We can't detect this for columns which may have a legitimate " default (string) but we can for others (integer, datetime, boolean, and the rest).
Test whether the column has default ", is not null, and is not a type allowing default ".
# File lib/arjdbc/mysql/adapter.rb, line 89 def missing_default_forged_as_empty_string?(default) type != :string && !null && default == '' end
Generated with the Darkfish Rdoc Generator 2.