module Sequel::SqlAnywhere::DatabaseMethods

  1. lib/sequel/adapters/shared/sqlanywhere.rb

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 }.freeze  

Attributes

conversion_procs [R]
convert_smallint_to_bool [RW]

Set whether to convert smallint type to boolean for this Database instance

Public Instance methods

database_type()
[show source]
   # File lib/sequel/adapters/shared/sqlanywhere.rb
15 def database_type
16   :sqlanywhere
17 end
foreign_key_list(table, opts=OPTS)
[show source]
   # File lib/sequel/adapters/shared/sqlanywhere.rb
74 def foreign_key_list(table, opts=OPTS)
75   m = output_identifier_meth
76   im = input_identifier_meth
77   fk_indexes = {}
78   metadata_dataset.
79    from{sys[:sysforeignkey].as(:fk)}.
80    select{[
81      fk[:role].as(:name),
82      fks[:columns].as(:column_map),
83      si[:indextype].as(:type),
84      si[:colnames].as(:columns),
85      fks[:primary_tname].as(:table_name)]}.
86    join(Sequel[:sys][:sysforeignkeys].as(:fks), :role => :role).
87    join(Sequel[:sys][:sysindexes].as(:si), {:iname => Sequel[:fk][:role]}, {:implicit_qualifier => :fk}).
88    where{{fks[:foreign_tname]=>im.call(table)}}.
89    each do |r|
90     unless r[:type].downcase == 'primary key'
91       fk_indexes[r[:name]] =
92         {:name=>m.call(r[:name]),
93          :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)},
94          :table=>m.call(r[:table_name]),
95          :key=>r[:column_map].split(',').map{|v| m.call(v.split(' IS ').last)}}
96     end
97   end
98   fk_indexes.values
99 end
freeze()
[show source]
   # File lib/sequel/adapters/shared/sqlanywhere.rb
19 def freeze
20   @conversion_procs.freeze
21   super
22 end
indexes(table, opts = OPTS)
[show source]
   # File lib/sequel/adapters/shared/sqlanywhere.rb
51 def indexes(table, opts = OPTS)
52   m = output_identifier_meth
53   im = input_identifier_meth
54   table = table.value if table.is_a?(Sequel::SQL::Identifier)
55   indexes = {}
56   metadata_dataset.
57    from(Sequel[:dbo][:sysobjects].as(:z)).
58    select{[
59      z[:name].as(:table_name),
60      i[:name].as(:index_name),
61      si[:indextype].as(:type),
62      si[:colnames].as(:columns)]}.
63    join(Sequel[:dbo][:sysindexes].as(:i), :id=>:id).
64    join(Sequel[:sys][:sysindexes].as(:si), :iname=> :name).
65    where{{z[:type] => 'U', :table_name=>im.call(table)}}.
66    each do |r|
67     indexes[m.call(r[:index_name])] =
68       {:unique=>(r[:type].downcase=='unique'),
69        :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)}} unless r[:type].downcase == 'primary key'
70   end
71   indexes
72 end
schema_parse_table(table, opts)
[show source]
   # File lib/sequel/adapters/shared/sqlanywhere.rb
28 def schema_parse_table(table, opts)
29   m = output_identifier_meth(opts[:dataset])
30   im = input_identifier_meth(opts[:dataset])
31   metadata_dataset.
32    from{sa_describe_query("select * from #{im.call(table)}").as(:a)}.
33    join(Sequel[:syscolumn].as(:b), :table_id=>:base_table_id, :column_id=>:base_column_id).
34    order{a[:column_number]}.
35    map do |row|
36     auto_increment = row.delete(:is_autoincrement)
37     row[:auto_increment] = auto_increment == 1 || auto_increment == true
38     row[:primary_key] = row.delete(:pkey) == 'Y'
39     row[:allow_null] = row[:nulls_allowed].is_a?(Integer) ? row.delete(:nulls_allowed) == 1 : row.delete(:nulls_allowed)
40     row[:db_type] = row.delete(:domain_name_with_size)
41     row[:type] = if row[:db_type] =~ /numeric/i and (row[:scale].is_a?(Integer) ? row[:scale] == 0 : !row[:scale])
42       :integer
43     else
44       schema_column_type(row[:db_type])
45     end
46     row[:max_length] = row[:width] if row[:type] == :string
47     [m.call(row.delete(:name)), row]
48   end
49 end
tables(opts=OPTS)
[show source]
    # File lib/sequel/adapters/shared/sqlanywhere.rb
101 def tables(opts=OPTS)
102   tables_and_views('U', opts)
103 end
to_application_timestamp_sa(v)
[show source]
   # File lib/sequel/adapters/shared/sqlanywhere.rb
24 def to_application_timestamp_sa(v)
25   to_application_timestamp(v.to_s) if v
26 end
views(opts=OPTS)
[show source]
    # File lib/sequel/adapters/shared/sqlanywhere.rb
105 def views(opts=OPTS)
106   tables_and_views('V', opts)
107 end