module Sequel::DB2::DatasetMethods

Constants

BITWISE_METHOD_MAP
BLOB_CLOSE
BLOB_OPEN
BOOL_FALSE
BOOL_TRUE
CAST_STRING_CLOSE
CAST_STRING_OPEN
EMPTY_FROM_TABLE
EMULATED_FUNCTION_MAP
FETCH_FIRST
FETCH_FIRST_ROW_ONLY
HSTAR
PAREN_CLOSE
PAREN_OPEN
ROWS_ONLY

Public Instance Methods

cast_sql_append(sql, expr, type) click to toggle source

DB2 casts strings using RTRIM and CHAR instead of VARCHAR.

Calls superclass method
# File lib/sequel/adapters/shared/db2.rb, line 245
def cast_sql_append(sql, expr, type)
  if(type == String)
    sql << CAST_STRING_OPEN
    literal_append(sql, expr)
    sql << CAST_STRING_CLOSE
  else
    super
  end
end
complex_expression_sql_append(sql, op, args) click to toggle source
Calls superclass method
# File lib/sequel/adapters/shared/db2.rb, line 255
def complex_expression_sql_append(sql, op, args)
  case op
  when :&, :|, :^
    # works with db2 v9.5 and after
    op = BITWISE_METHOD_MAP[op]
    sql << complex_expression_arg_pairs(args){|a, b| literal(SQL::Function.new(op, a, b))}
  when :<<
    sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} * POWER(2, #{literal(b)}))"}
  when :>>
    sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} / POWER(2, #{literal(b)}))"}
  when :%
    sql << complex_expression_arg_pairs(args){|a, b| "MOD(#{literal(a)}, #{literal(b)})"}
  when :'B~'
    literal_append(sql, SQL::Function.new(:BITNOT, *args))
  when :extract
    sql << args.at(0).to_s
    sql << PAREN_OPEN
    literal_append(sql, args.at(1))
    sql << PAREN_CLOSE
  else
    super
  end
end
supports_group_cube?() click to toggle source

DB2 supports GROUP BY CUBE

# File lib/sequel/adapters/shared/db2.rb, line 280
def supports_group_cube?
  true
end
supports_group_rollup?() click to toggle source

DB2 supports GROUP BY ROLLUP

# File lib/sequel/adapters/shared/db2.rb, line 285
def supports_group_rollup?
  true
end
supports_is_true?() click to toggle source

DB2 does not support IS TRUE.

# File lib/sequel/adapters/shared/db2.rb, line 290
def supports_is_true?
  false
end
supports_multiple_column_in?() click to toggle source

DB2 does not support multiple columns in IN.

# File lib/sequel/adapters/shared/db2.rb, line 295
def supports_multiple_column_in?
  false
end
supports_select_all_and_column?() click to toggle source

DB2 only allows * in SELECT if it is the only thing being selected.

# File lib/sequel/adapters/shared/db2.rb, line 300
def supports_select_all_and_column?
  false
end
supports_timestamp_usecs?() click to toggle source

DB2 does not support fractional seconds in timestamps.

# File lib/sequel/adapters/shared/db2.rb, line 305
def supports_timestamp_usecs?
  false
end
supports_where_true?() click to toggle source

DB2 does not support WHERE 1.

# File lib/sequel/adapters/shared/db2.rb, line 315
def supports_where_true?
  false
end
supports_window_functions?() click to toggle source

DB2 supports window functions

# File lib/sequel/adapters/shared/db2.rb, line 310
def supports_window_functions?
  true
end

Private Instance Methods

_truncate_sql(table) click to toggle source
# File lib/sequel/adapters/shared/db2.rb, line 373
def _truncate_sql(table)
  # "TRUNCATE #{table} IMMEDIATE" is only for newer version of db2, so we
  # use the following one
  "ALTER TABLE #{quote_schema_table(table)} ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE"
end
insert_supports_empty_values?() click to toggle source

DB2 needs the standard workaround to insert all default values into a table with more than one column.

# File lib/sequel/adapters/shared/db2.rb, line 323
def insert_supports_empty_values?
  false
end
literal_blob_append(sql, v) click to toggle source

DB2 uses a literal hexidecimal number for blob strings

Calls superclass method
# File lib/sequel/adapters/shared/db2.rb, line 338
def literal_blob_append(sql, v)
  if ::Sequel::DB2.use_clob_as_blob
    super
  else
    sql << BLOB_OPEN << v.unpack(HSTAR).first << BLOB_CLOSE
  end
end
literal_false() click to toggle source

Use 0 for false on DB2

# File lib/sequel/adapters/shared/db2.rb, line 328
def literal_false
  BOOL_FALSE
end
literal_true() click to toggle source

Use 1 for true on DB2

# File lib/sequel/adapters/shared/db2.rb, line 333
def literal_true
  BOOL_TRUE
end
select_from_sql(sql) click to toggle source

Add a fallback table for empty from situation

Calls superclass method
# File lib/sequel/adapters/shared/db2.rb, line 347
def select_from_sql(sql)
  @opts[:from] ? super : (sql << EMPTY_FROM_TABLE)
end
select_limit_sql(sql) click to toggle source

Modify the sql to limit the number of rows returned Note:

After db2 v9.7, MySQL flavored "LIMIT X OFFSET Y" can be enabled using

db2set DB2_COMPATIBILITY_VECTOR=MYSQL
db2stop
db2start

Support for this feature is not used in this adapter however.
# File lib/sequel/adapters/shared/db2.rb, line 361
def select_limit_sql(sql)
  if l = @opts[:limit]
    if l == 1
      sql << FETCH_FIRST_ROW_ONLY
    else
      sql << FETCH_FIRST
      literal_append(sql, l)
      sql << ROWS_ONLY
    end
  end
end