Module: Sequel::SqlAnywhere::DatabaseMethods
- Extended by:
- Database::ResetIdentifierMangling
- Included in:
- JDBC::SqlAnywhere::DatabaseMethods, Database
- Defined in:
- lib/sequel/adapters/shared/sqlanywhere.rb
Constant Summary collapse
- 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
Instance Attribute Summary collapse
-
#conversion_procs ⇒ Object
readonly
Returns the value of attribute conversion_procs.
-
#convert_smallint_to_bool ⇒ Object
Whether to convert smallint to boolean arguments for this dataset.
Instance Method Summary collapse
-
#database_type ⇒ Object
Sysbase Server uses the :sqlanywhere type.
- #foreign_key_list(table, opts = OPTS) ⇒ Object
- #indexes(table, opts = OPTS) ⇒ Object
-
#schema_column_type(db_type) ⇒ Object
Convert smallint type to boolean if convert_smallint_to_bool is true.
- #schema_parse_table(table, opts) ⇒ Object
- #tables(opts = OPTS) ⇒ Object
- #to_application_timestamp_sa(v) ⇒ Object
- #views(opts = OPTS) ⇒ Object
Methods included from Database::ResetIdentifierMangling
Instance Attribute Details
#conversion_procs ⇒ Object (readonly)
Returns the value of attribute conversion_procs.
15 16 17 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 15 def conversion_procs @conversion_procs end |
#convert_smallint_to_bool ⇒ Object
Whether to convert smallint to boolean arguments for this dataset. Defaults to the SqlAnywhere module setting.
30 31 32 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 30 def convert_smallint_to_bool defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@convert_smallint_to_bool = ::Sequel::SqlAnywhere.convert_smallint_to_bool) end |
Instance Method Details
#database_type ⇒ Object
Sysbase Server uses the :sqlanywhere type.
35 36 37 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 35 def database_type :sqlanywhere end |
#foreign_key_list(table, opts = OPTS) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 93 def foreign_key_list(table, opts=OPTS) m = output_identifier_meth im = input_identifier_meth fk_indexes = {} . from(:sys__sysforeignkey___fk). select(:fk__role___name, :fks__columns___column_map, :si__indextype___type, :si__colnames___columns, :fks__primary_tname___table_name). join(:sys__sysforeignkeys___fks, :role => :role). join_table(:inner, :sys__sysindexes___si, [:iname=> :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 |
#indexes(table, opts = OPTS) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 75 def indexes(table, opts = OPTS) m = output_identifier_meth im = input_identifier_meth indexes = {} . from(:dbo__sysobjects___z). select(:z__name___table_name, :i__name___index_name, :si__indextype___type, :si__colnames___columns). join(:dbo__sysindexes___i, :id___i=> :id___z). join(:sys__sysindexes___si, :iname=> :name___i). 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
44 45 46 47 48 49 50 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 44 def schema_column_type(db_type) if convert_smallint_to_bool && db_type =~ SMALLINT_RE :boolean else super end end |
#schema_parse_table(table, opts) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 52 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(:syscolumn___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?(Fixnum) ? row.delete(:nulls_allowed) == 1 : row.delete(:nulls_allowed) row[:db_type] = row.delete(:domain_name) row[:type] = if row[:db_type] =~ DECIMAL_TYPE_RE and (row[:scale].is_a?(Fixnum) ? 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
115 116 117 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 115 def tables(opts=OPTS) tables_and_views('U', opts) end |
#to_application_timestamp_sa(v) ⇒ Object
39 40 41 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 39 def (v) (v.to_s) if v end |
#views(opts = OPTS) ⇒ Object
119 120 121 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 119 def views(opts=OPTS) tables_and_views('V', opts) end |