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 81
 81:       def foreign_key_list(table, opts=OPTS)
 82:         m = output_identifier_meth
 83:         im = input_identifier_meth
 84:         fk_indexes = {}
 85:         metadata_dataset.
 86:          from{sys[:sysforeignkey].as(:fk)}.
 87:          select{[
 88:            fk[:role].as(:name),
 89:            fks[:columns].as(:column_map),
 90:            si[:indextype].as(:type),
 91:            si[:colnames].as(:columns),
 92:            fks[:primary_tname].as(:table_name)]}.
 93:          join(Sequel[:sys][:sysforeignkeys].as(:fks), :role => :role).
 94:          join(Sequel[:sys][:sysindexes].as(:si), {:iname => Sequel[:fk][:role]}, {:implicit_qualifier => :fk}).
 95:          where{{fks[:foreign_tname]=>im.call(table)}}.
 96:          each do |r|
 97:           unless r[:type].downcase == 'primary key'
 98:             fk_indexes[r[:name]] =
 99:               {:name=>m.call(r[:name]),
100:                :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)},
101:                :table=>m.call(r[:table_name]),
102:                :key=>r[:column_map].split(',').map{|v| m.call(v.split(' IS ').last)}}
103:           end
104:         end
105:         fk_indexes.values
106:       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:         table = table.value if table.is_a?(Sequel::SQL::Identifier)
62:         indexes = {}
63:         metadata_dataset.
64:          from(Sequel[:dbo][:sysobjects].as(:z)).
65:          select{[
66:            z[:name].as(:table_name),
67:            i[:name].as(:index_name),
68:            si[:indextype].as(:type),
69:            si[:colnames].as(:columns)]}.
70:          join(Sequel[:dbo][:sysindexes].as(:i), :id=>:id).
71:          join(Sequel[:sys][:sysindexes].as(:si), :iname=> :name).
72:          where{{z[:type] => 'U', :table_name=>im.call(table)}}.
73:          each do |r|
74:           indexes[m.call(r[:index_name])] =
75:             {:unique=>(r[:type].downcase=='unique'),
76:              :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)}} unless r[:type].downcase == 'primary key'
77:         end
78:         indexes
79:       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 108
108:       def tables(opts=OPTS)
109:         tables_and_views('U', opts)
110:       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 112
112:       def views(opts=OPTS)
113:         tables_and_views('V', opts)
114:       end

[Validate]