Module: JdbcSpec::DB2

Defined in:
lib/jdbc_adapter/jdbc_db2.rb

Defined Under Namespace

Modules: Column

Instance Method Summary collapse

Instance Method Details

#add_limit_offset!(sql, options) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/jdbc_adapter/jdbc_db2.rb', line 44

def add_limit_offset!(sql, options)
  if limit = options[:limit]
    offset = options[:offset] || 0
    sql.gsub!(/SELECT/i, 'SELECT B.* FROM (SELECT A.*, row_number() over () AS internal$rownum FROM (SELECT')
    sql << ") A ) B WHERE B.internal$rownum > #{offset} AND B.internal$rownum <= #{limit + offset}"
  end
end

#modify_types(tp) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/jdbc_adapter/jdbc_db2.rb', line 36

def modify_types(tp)
  tp[:primary_key] = 'int generated by default as identity (start with 42) primary key'
  tp[:string][:limit] = 255
  tp[:integer][:limit] = nil
  tp[:boolean][:limit] = nil
  tp
end

#quote(value, column = nil) ⇒ Object

:nodoc:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/jdbc_adapter/jdbc_db2.rb', line 56

def quote(value, column = nil) # :nodoc:
  if column && column.type == :primary_key
    return value.to_s
  end
  case value
  when String                
    if column && column.type == :binary
      "BLOB('#{quote_string(value)}')"
    else
      "'#{quote_string(value)}'"
    end
  else super
  end
end

#quote_column_name(column_name) ⇒ Object



52
53
54
# File 'lib/jdbc_adapter/jdbc_db2.rb', line 52

def quote_column_name(column_name)
  column_name
end

#quote_string(string) ⇒ Object



71
72
73
# File 'lib/jdbc_adapter/jdbc_db2.rb', line 71

def quote_string(string)
  string.gsub(/'/, "''") # ' (for ruby-mode)
end

#quoted_falseObject



79
80
81
# File 'lib/jdbc_adapter/jdbc_db2.rb', line 79

def quoted_false
  '0'
end

#quoted_trueObject



75
76
77
# File 'lib/jdbc_adapter/jdbc_db2.rb', line 75

def quoted_true
  '1'
end