Class: Swift::DB::DB2

Inherits:
Adapter show all
Defined in:
lib/swift/db.rb

Overview

Postgres

Instance Attribute Summary

Attributes inherited from Adapter

#options

Instance Method Summary collapse

Methods inherited from Adapter

#all, #begin, #clone, #close, #commit, #create, #destroy, #dup, #escape, #execute, #first, #get, #identity_map, #migrate!, #prepare, #results, #rollback, #transaction, #update, #write

Constructor Details

#initialize(options = {}) ⇒ DB2

Returns a new instance of DB2.



31
32
33
# File 'lib/swift/db.rb', line 31

def initialize options = {}
  super options.update(driver: 'db2')
end

Instance Method Details

#drop_store(name) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/swift/db.rb', line 39

def drop_store name
  exists_sql =<<-SQL
    select count(*) as exists from syscat.tables where tabschema = CURRENT_SCHEMA and tabname = '#{name.upcase}'
  SQL

  execute(exists_sql.strip) do |r|
    execute("drop table #{name}") if r[:exists] > 0
  end
end

#field_type(attribute) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/swift/db.rb', line 49

def field_type attribute
  case attribute
    when Type::String     then 'clob(2g)'
    when Type::Integer    then attribute.serial ? 'integer not null generated by default as identity' : 'integer'
    when Type::Boolean    then 'char(1)'
    when Type::Float      then 'real'
    when Type::BigDecimal then 'double'
    else super
  end
end

#prepare_create(scheme) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/swift/db.rb', line 60

def prepare_create scheme
  prepare_cached(scheme, :create) do
    values = (['?'] * scheme.header.insertable.size).join(', ')
    sql    = "insert into #{scheme.store} (#{scheme.header.insertable.join(', ')}) values (#{values})"
    scheme.header.serial ? "select #{scheme.header.serial} from final table (#{sql})" : sql
  end
end

#returning?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/swift/db.rb', line 35

def returning?
  false
end