# File lib/arjdbc/mysql/adapter.rb, line 18
18: def extract_default(default)
19: if sql_type =~ /blob/ || type == :text
20: if default.blank?
21: return null ? nil : ''
22: else
23: raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}"
24: end
25: elsif missing_default_forged_as_empty_string?(default)
26: nil
27: else
28: super
29: end
30: end
# File lib/arjdbc/mysql/adapter.rb, line 43
43: def extract_limit(sql_type)
44: case sql_type
45: when /blob|text/
46: case sql_type
47: when /tiny/
48: 255
49: when /medium/
50: 16777215
51: when /long/
52: 2147483647 # mysql only allows 2^31-1, not 2^32-1, somewhat inconsistently with the tiny/medium/normal cases
53: else
54: nil # we could return 65535 here, but we leave it undecorated by default
55: end
56: when /^bigint/; 8
57: when /^int/; 4
58: when /^mediumint/; 3
59: when /^smallint/; 2
60: when /^tinyint/; 1
61: when /^(datetime|date|timestamp)/
62: nil
63: else
64: super
65: end
66: end
# File lib/arjdbc/mysql/adapter.rb, line 32
32: def has_default?
33: return false if sql_type =~ /blob/ || type == :text #mysql forbids defaults on blob and text columns
34: super
35: 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 75
75: def missing_default_forged_as_empty_string?(default)
76: type != :string && !null && default == ''
77: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.