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


8
9
10
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 8

def conversion_procs
  @conversion_procs
end

#convert_smallint_to_boolObject

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


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

def convert_smallint_to_bool
  @convert_smallint_to_bool
end

Instance Method Details

#database_typeObject


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

def database_type
  :sqlanywhere
end

#foreign_key_list(table, opts = OPTS) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 80

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


17
18
19
20
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 17

def freeze
  @conversion_procs.freeze
  super
end

#indexes(table, opts = OPTS) ⇒ Object


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 58

def indexes(table, opts = OPTS)
  m = output_identifier_meth
  im = input_identifier_meth
  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_column_type(db_type) ⇒ Object

Convert smallint type to boolean if convert_smallint_to_bool is true


27
28
29
30
31
32
33
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 27

def schema_column_type(db_type)
  if convert_smallint_to_bool && db_type =~ /smallint/i
    :boolean
  else
    super
  end
end

#schema_parse_table(table, opts) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 35

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)
    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


107
108
109
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 107

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

#to_application_timestamp_sa(v) ⇒ Object


22
23
24
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 22

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

#views(opts = OPTS) ⇒ Object


111
112
113
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 111

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