| Module | Sequel::MySQL |
| In: |
lib/sequel/adapters/mysql.rb
lib/sequel/adapters/shared/mysql.rb |
Module for holding all MySQL-related classes and modules for Sequel.
A class level convert_invalid_date_time accessor exists if the native adapter is used. If set to nil or :nil, the adapter treats dates like 0000-00-00 and times like 838:00:00 as nil values. If set to :string, it returns the strings as is. If is false by default, which means that invalid dates and times will raise errors.
| MYSQL_TYPES | = | {} | Mapping of type numbers to conversion procs | |
| MYSQL_TYPE_PROCS | = | { [0, 246] => lambda{|v| BigDecimal.new(v)}, # decimal [1, 2, 3, 8, 9, 13, 247, 248] => lambda{|v| v.to_i}, # integer [4, 5] => lambda{|v| v.to_f}, # float [10, 14] => lambda{|v| convert_date_time(:string_to_date, v)}, # date [7, 12] => lambda{|v| convert_date_time(:string_to_datetime, v)}, # datetime [11] => lambda{|v| convert_date_time(:string_to_time, v)}, # time [249, 250, 251, 252] => lambda{|v| Sequel::SQL::Blob.new(v)} | Use only a single proc for each type to save on memory |
| convert_invalid_date_time | [RW] | |
| default_charset | [RW] | Set the default options used for CREATE TABLE |
| default_collate | [RW] | Set the default options used for CREATE TABLE |
| default_engine | [RW] | Set the default options used for CREATE TABLE |
If convert_invalid_date_time is nil, :nil, or :string and the conversion raises an InvalidValue exception, return v if :string and nil otherwise.
# File lib/sequel/adapters/mysql.rb, line 39
39: def self.convert_date_time(meth, v)
40: begin
41: Sequel.send(meth, v)
42: rescue InvalidValue
43: case @convert_invalid_date_time
44: when nil, :nil
45: nil
46: when :string
47: v
48: else
49: raise
50: end
51: end
52: end