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

Methods

Constants

AUTO_INCREMENT = 'IDENTITY'.freeze
SQL_BEGIN = "BEGIN TRANSACTION".freeze
SQL_COMMIT = "COMMIT TRANSACTION".freeze
SQL_ROLLBACK = "IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION".freeze
TEMPORARY = "GLOBAL TEMPORARY ".freeze
SMALLINT_RE = /smallint/i.freeze
DECIMAL_TYPE_RE = /numeric/io
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  [W]  Override the default SqlAnywhere.convert_smallint_to_bool setting for this database.

Public Instance methods

Whether to convert smallint to boolean arguments for this dataset. Defaults to the SqlAnywhere module setting.

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 33
33:       def convert_smallint_to_bool
34:         defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@convert_smallint_to_bool = ::Sequel::SqlAnywhere.convert_smallint_to_bool)
35:       end

Sysbase Server uses the :sqlanywhere type.

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 38
38:       def database_type
39:         :sqlanywhere
40:       end

[Source]

     # File lib/sequel/adapters/shared/sqlanywhere.rb, line 96
 96:       def foreign_key_list(table, opts=OPTS)
 97:         m = output_identifier_meth
 98:         im = input_identifier_meth
 99:         fk_indexes = {}
100:         metadata_dataset.
101:          from(:sys__sysforeignkey___fk).
102:          select(:fk__role___name, :fks__columns___column_map, :si__indextype___type, :si__colnames___columns, :fks__primary_tname___table_name).
103:          join(:sys__sysforeignkeys___fks, :role => :role).
104:          join_table(:inner, :sys__sysindexes___si, [:iname=> :fk__role], {:implicit_qualifier => :fk}).
105:          where(:fks__foreign_tname=>im.call(table)).
106:          each do |r|
107:           unless r[:type].downcase == 'primary key'
108:             fk_indexes[r[:name]] =
109:               {:name=>m.call(r[:name]),
110:                :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)},
111:                :table=>m.call(r[:table_name]),
112:                :key=>r[:column_map].split(',').map{|v| m.call(v.split(' IS ').last)}}
113:           end
114:         end
115:         fk_indexes.values
116:       end

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 78
78:       def indexes(table, opts = OPTS)
79:         m = output_identifier_meth
80:         im = input_identifier_meth
81:         indexes = {}
82:         metadata_dataset.
83:          from(:dbo__sysobjects___z).
84:          select(:z__name___table_name, :i__name___index_name, :si__indextype___type, :si__colnames___columns).
85:          join(:dbo__sysindexes___i, :id___i=> :id___z).
86:          join(:sys__sysindexes___si, :iname=> :name___i).
87:          where(:z__type => 'U', :table_name=>im.call(table)).
88:          each do |r|
89:           indexes[m.call(r[:index_name])] =
90:             {:unique=>(r[:type].downcase=='unique'),
91:              :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)}} unless r[:type].downcase == 'primary key'
92:         end
93:         indexes
94:       end

Convert smallint type to boolean if convert_smallint_to_bool is true

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 47
47:       def schema_column_type(db_type)
48:         if convert_smallint_to_bool && db_type =~ SMALLINT_RE
49:           :boolean
50:         else
51:           super
52:         end
53:       end

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 55
55:       def schema_parse_table(table, opts)
56:         m = output_identifier_meth(opts[:dataset])
57:         im = input_identifier_meth(opts[:dataset])
58:         metadata_dataset.
59:          from{sa_describe_query("select * from #{im.call(table)}").as(:a)}.
60:          join(:syscolumn___b, :table_id=>:base_table_id, :column_id=>:base_column_id).
61:          order(:a__column_number).
62:          map do |row|
63:           auto_increment = row.delete(:is_autoincrement)
64:           row[:auto_increment] = auto_increment == 1 || auto_increment == true
65:           row[:primary_key] = row.delete(:pkey) == 'Y'
66:           row[:allow_null] = row[:nulls_allowed].is_a?(Fixnum) ? row.delete(:nulls_allowed) == 1 : row.delete(:nulls_allowed)
67:           row[:db_type] = row.delete(:domain_name)
68:           row[:type] = if row[:db_type] =~ DECIMAL_TYPE_RE and (row[:scale].is_a?(Fixnum) ? row[:scale] == 0 : !row[:scale])
69:             :integer
70:           else
71:             schema_column_type(row[:db_type])
72:           end
73:           row[:max_length] = row[:width] if row[:type] == :string
74:           [m.call(row.delete(:name)), row]
75:         end
76:       end

[Source]

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

[Source]

    # File lib/sequel/adapters/shared/sqlanywhere.rb, line 42
42:       def to_application_timestamp_sa(v)
43:         to_application_timestamp(v.to_s) if v
44:       end

[Source]

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

[Validate]