Module Sequel::SqlAnywhere::DatabaseMethods
In: lib/sequel/adapters/shared/sqlanywhere.rb

Methods

Constants

DATABASE_ERROR_REGEXPS = { /would not be unique|Primary key for table.+is not unique/ => Sequel::UniqueConstraintViolation, /Column .* in table .* cannot be NULL/ => Sequel::NotNullConstraintViolation, /Constraint .* violated: Invalid value in table .*/ => Sequel::CheckConstraintViolation, /No primary key value for foreign key .* in table .*/ => Sequel::ForeignKeyConstraintViolation, /Primary key for row in table .* is referenced by foreign key .* in table .*/ => Sequel::ForeignKeyConstraintViolation

Attributes

conversion_procs  [R] 
convert_smallint_to_bool  [RW]  Set whether to convert smallint type to boolean for this Database instance

Public Instance methods

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 13
13:       def database_type
14:         :sqlanywhere
15:       end

[Source]

     # File lib/sequel/adapters/shared/sqlanywhere.rb, line 80
 80:       def foreign_key_list(table, opts=OPTS)
 81:         m = output_identifier_meth
 82:         im = input_identifier_meth
 83:         fk_indexes = {}
 84:         metadata_dataset.
 85:          from{sys[:sysforeignkey].as(:fk)}.
 86:          select{[
 87:            fk[:role].as(:name),
 88:            fks[:columns].as(:column_map),
 89:            si[:indextype].as(:type),
 90:            si[:colnames].as(:columns),
 91:            fks[:primary_tname].as(:table_name)]}.
 92:          join(Sequel[:sys][:sysforeignkeys].as(:fks), :role => :role).
 93:          join(Sequel[:sys][:sysindexes].as(:si), {:iname => Sequel[:fk][:role]}, {:implicit_qualifier => :fk}).
 94:          where{{fks[:foreign_tname]=>im.call(table)}}.
 95:          each do |r|
 96:           unless r[:type].downcase == 'primary key'
 97:             fk_indexes[r[:name]] =
 98:               {:name=>m.call(r[:name]),
 99:                :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)},
100:                :table=>m.call(r[:table_name]),
101:                :key=>r[:column_map].split(',').map{|v| m.call(v.split(' IS ').last)}}
102:           end
103:         end
104:         fk_indexes.values
105:       end

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 17
17:       def freeze
18:         @conversion_procs.freeze
19:         super
20:       end

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 58
58:       def indexes(table, opts = OPTS)
59:         m = output_identifier_meth
60:         im = input_identifier_meth
61:         indexes = {}
62:         metadata_dataset.
63:          from(Sequel[:dbo][:sysobjects].as(:z)).
64:          select{[
65:            z[:name].as(:table_name),
66:            i[:name].as(:index_name),
67:            si[:indextype].as(:type),
68:            si[:colnames].as(:columns)]}.
69:          join(Sequel[:dbo][:sysindexes].as(:i), :id=>:id).
70:          join(Sequel[:sys][:sysindexes].as(:si), :iname=> :name).
71:          where{{z[:type] => 'U', :table_name=>im.call(table)}}.
72:          each do |r|
73:           indexes[m.call(r[:index_name])] =
74:             {:unique=>(r[:type].downcase=='unique'),
75:              :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)}} unless r[:type].downcase == 'primary key'
76:         end
77:         indexes
78:       end

Convert smallint type to boolean if convert_smallint_to_bool is true

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 27
27:       def schema_column_type(db_type)
28:         if convert_smallint_to_bool && db_type =~ /smallint/i
29:           :boolean
30:         else
31:           super
32:         end
33:       end

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 35
35:       def schema_parse_table(table, opts)
36:         m = output_identifier_meth(opts[:dataset])
37:         im = input_identifier_meth(opts[:dataset])
38:         metadata_dataset.
39:          from{sa_describe_query("select * from #{im.call(table)}").as(:a)}.
40:          join(Sequel[:syscolumn].as(:b), :table_id=>:base_table_id, :column_id=>:base_column_id).
41:          order{a[:column_number]}.
42:          map do |row|
43:           auto_increment = row.delete(:is_autoincrement)
44:           row[:auto_increment] = auto_increment == 1 || auto_increment == true
45:           row[:primary_key] = row.delete(:pkey) == 'Y'
46:           row[:allow_null] = row[:nulls_allowed].is_a?(Integer) ? row.delete(:nulls_allowed) == 1 : row.delete(:nulls_allowed)
47:           row[:db_type] = row.delete(:domain_name)
48:           row[:type] = if row[:db_type] =~ /numeric/i and (row[:scale].is_a?(Integer) ? row[:scale] == 0 : !row[:scale])
49:             :integer
50:           else
51:             schema_column_type(row[:db_type])
52:           end
53:           row[:max_length] = row[:width] if row[:type] == :string
54:           [m.call(row.delete(:name)), row]
55:         end
56:       end

[Source]

     # File lib/sequel/adapters/shared/sqlanywhere.rb, line 107
107:       def tables(opts=OPTS)
108:         tables_and_views('U', opts)
109:       end

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 22
22:       def to_application_timestamp_sa(v)
23:         to_application_timestamp(v.to_s) if v
24:       end

[Source]

     # File lib/sequel/adapters/shared/sqlanywhere.rb, line 111
111:       def views(opts=OPTS)
112:         tables_and_views('V', opts)
113:       end

[Validate]