Module: Sequel::SqlAnywhere::DatabaseMethods

Included in:
JDBC::SqlAnywhere::DatabaseMethods, Database
Defined in:
lib/sequel/adapters/shared/sqlanywhere.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#conversion_procsObject (readonly)

Returns the value of attribute conversion_procs.



10
11
12
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 10

def conversion_procs
  @conversion_procs
end

#convert_smallint_to_boolObject

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



13
14
15
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 13

def convert_smallint_to_bool
  @convert_smallint_to_bool
end

Instance Method Details

#database_typeObject



15
16
17
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 15

def database_type
  :sqlanywhere
end

#foreign_key_list(table, opts = OPTS) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 74

def foreign_key_list(table, opts=OPTS)
  m = output_identifier_meth
  im = input_identifier_meth
  fk_indexes = {}
  .
   from{sys[:sysforeignkey].as(:fk)}.
   select{[
     fk[:role].as(:name),
     fks[:columns].as(:column_map),
     si[:indextype].as(:type),
     si[:colnames].as(:columns),
     fks[:primary_tname].as(:table_name)]}.
   join(Sequel[:sys][:sysforeignkeys].as(:fks), :role => :role).
   join(Sequel[:sys][:sysindexes].as(:si), {:iname => Sequel[:fk][:role]}, {:implicit_qualifier => :fk}).
   where{{fks[:foreign_tname]=>im.call(table)}}.
   each do |r|
    unless r[:type].downcase == 'primary key'
      fk_indexes[r[:name]] =
        {:name=>m.call(r[:name]),
         :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)},
         :table=>m.call(r[:table_name]),
         :key=>r[:column_map].split(',').map{|v| m.call(v.split(' IS ').last)}}
    end
  end
  fk_indexes.values
end

#freezeObject



19
20
21
22
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 19

def freeze
  @conversion_procs.freeze
  super
end

#indexes(table, opts = OPTS) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 51

def indexes(table, opts = OPTS)
  m = output_identifier_meth
  im = input_identifier_meth
  table = table.value if table.is_a?(Sequel::SQL::Identifier)
  indexes = {}
  .
   from(Sequel[:dbo][:sysobjects].as(:z)).
   select{[
     z[:name].as(:table_name),
     i[:name].as(:index_name),
     si[:indextype].as(:type),
     si[:colnames].as(:columns)]}.
   join(Sequel[:dbo][:sysindexes].as(:i), :id=>:id).
   join(Sequel[:sys][:sysindexes].as(:si), :iname=> :name).
   where{{z[:type] => 'U', :table_name=>im.call(table)}}.
   each do |r|
    indexes[m.call(r[:index_name])] =
      {:unique=>(r[:type].downcase=='unique'),
       :columns=>r[:columns].split(',').map{|v| m.call(v.split(' ').first)}} unless r[:type].downcase == 'primary key'
  end
  indexes
end

#schema_parse_table(table, opts) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 28

def schema_parse_table(table, opts)
  m = output_identifier_meth(opts[:dataset])
  im = input_identifier_meth(opts[:dataset])
  .
   from{sa_describe_query("select * from #{im.call(table)}").as(:a)}.
   join(Sequel[:syscolumn].as(:b), :table_id=>:base_table_id, :column_id=>:base_column_id).
   order{a[:column_number]}.
   map do |row|
    auto_increment = row.delete(:is_autoincrement)
    row[:auto_increment] = auto_increment == 1 || auto_increment == true
    row[:primary_key] = row.delete(:pkey) == 'Y'
    row[:allow_null] = row[:nulls_allowed].is_a?(Integer) ? row.delete(:nulls_allowed) == 1 : row.delete(:nulls_allowed)
    row[:db_type] = row.delete(:domain_name_with_size)
    row[:type] = if row[:db_type] =~ /numeric/i and (row[:scale].is_a?(Integer) ? row[:scale] == 0 : !row[:scale])
      :integer
    else
      schema_column_type(row[:db_type])
    end
    row[:max_length] = row[:width] if row[:type] == :string
    [m.call(row.delete(:name)), row]
  end
end

#tables(opts = OPTS) ⇒ Object



101
102
103
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 101

def tables(opts=OPTS)
  tables_and_views('U', opts)
end

#to_application_timestamp_sa(v) ⇒ Object



24
25
26
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 24

def to_application_timestamp_sa(v)
  to_application_timestamp(v.to_s) if v
end

#views(opts = OPTS) ⇒ Object



105
106
107
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 105

def views(opts=OPTS)
  tables_and_views('V', opts)
end