Module: Sequel::DB2::DatabaseMethods
- Extended by:
- Sequel::Database::ResetIdentifierMangling
- Included in:
- Database, IBMDB::Database, JDBC::DB2::DatabaseMethods
- Defined in:
- lib/sequel/adapters/shared/db2.rb
Constant Summary collapse
- AUTOINCREMENT =
'GENERATED ALWAYS AS IDENTITY'.freeze
- NOT_NULL =
' NOT NULL'.freeze
- NULL =
''.freeze
Instance Method Summary collapse
-
#database_type ⇒ Object
DB2 always uses :db2 as it’s database type.
-
#db2_version ⇒ Object
(also: #server_version)
Return the database version as a string.
-
#indexes(table, opts = OPTS) ⇒ Object
Use SYSCAT.INDEXES to get the indexes for the table.
-
#schema_parse_table(table, opts = OPTS) ⇒ Object
Use SYSIBM.SYSCOLUMNS to get the information on the tables.
-
#supports_transaction_isolation_levels? ⇒ Boolean
DB2 supports transaction isolation levels.
-
#tables ⇒ Object
Use SYSCAT.TABLES to get the tables for the database.
-
#views ⇒ Object
Use SYSCAT.TABLES to get the views for the database.
Methods included from Sequel::Database::ResetIdentifierMangling
Instance Method Details
#database_type ⇒ Object
DB2 always uses :db2 as it’s database type
20 21 22 |
# File 'lib/sequel/adapters/shared/db2.rb', line 20 def database_type :db2 end |
#db2_version ⇒ Object Also known as: server_version
Return the database version as a string. Don’t rely on this, it may return an integer in the future.
26 27 28 29 |
# File 'lib/sequel/adapters/shared/db2.rb', line 26 def db2_version return @db2_version if @db2_version @db2_version = .with_sql("select service_level from sysibmadm.env_inst_info").first[:service_level] end |
#indexes(table, opts = OPTS) ⇒ Object
Use SYSCAT.INDEXES to get the indexes for the table
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sequel/adapters/shared/db2.rb', line 68 def indexes(table, opts = OPTS) m = output_identifier_meth indexes = {} . from(:syscat__indexes). select(:indname, :uniquerule, :colnames). where(:tabname=>input_identifier_meth.call(table), :system_required=>0). each do |r| indexes[m.call(r[:indname])] = {:unique=>(r[:uniquerule]=='U'), :columns=>r[:colnames][1..-1].split('+').map{|v| m.call(v)}} end indexes end |
#schema_parse_table(table, opts = OPTS) ⇒ Object
Use SYSIBM.SYSCOLUMNS to get the information on the tables.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sequel/adapters/shared/db2.rb', line 33 def schema_parse_table(table, opts = OPTS) m = output_identifier_meth(opts[:dataset]) im = input_identifier_meth(opts[:dataset]) .with_sql("SELECT * FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = #{literal(im.call(table))} ORDER BY COLNO"). collect do |column| column[:db_type] = column.delete(:typename) if column[:db_type] == "DECIMAL" column[:db_type] << "(#{column[:longlength]},#{column[:scale]})" end column[:allow_null] = column.delete(:nulls) == 'Y' identity = column.delete(:identity) == 'Y' if column[:primary_key] = identity || !column[:keyseq].nil? column[:auto_increment] = identity end column[:type] = schema_column_type(column[:db_type]) column[:max_length] = column[:longlength] if column[:type] == :string [ m.call(column.delete(:name)), column] end end |
#supports_transaction_isolation_levels? ⇒ Boolean
DB2 supports transaction isolation levels.
82 83 84 |
# File 'lib/sequel/adapters/shared/db2.rb', line 82 def supports_transaction_isolation_levels? true end |
#tables ⇒ Object
Use SYSCAT.TABLES to get the tables for the database
54 55 56 57 58 |
# File 'lib/sequel/adapters/shared/db2.rb', line 54 def tables . with_sql("SELECT TABNAME FROM SYSCAT.TABLES WHERE TYPE='T' AND OWNER = #{literal(input_identifier_meth.call(opts[:user]))}"). all.map{|h| output_identifier_meth.call(h[:tabname]) } end |
#views ⇒ Object
Use SYSCAT.TABLES to get the views for the database
61 62 63 64 65 |
# File 'lib/sequel/adapters/shared/db2.rb', line 61 def views . with_sql("SELECT TABNAME FROM SYSCAT.TABLES WHERE TYPE='V' AND OWNER = #{literal(input_identifier_meth.call(opts[:user]))}"). all.map{|h| output_identifier_meth.call(h[:tabname]) } end |