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 303
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 313
def complex_expression_sql_append(sql, op, args)
  case op
  when :&, :|, :^, :%, :<<, :>>
    complex_expression_emulate_append(sql, op, args)
  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
quote_identifiers?() click to toggle source
# File lib/sequel/adapters/shared/db2.rb, line 329
def quote_identifiers?
  @opts.fetch(:quote_identifiers, false)
end
supports_cte?(type=:select) click to toggle source
# File lib/sequel/adapters/shared/db2.rb, line 333
def supports_cte?(type=:select)
  type == :select
end
supports_group_cube?() click to toggle source

DB2 supports GROUP BY CUBE

# File lib/sequel/adapters/shared/db2.rb, line 338
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 343
def supports_group_rollup?
  true
end
supports_grouping_sets?() click to toggle source

DB2 supports GROUPING SETS

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

DB2 does not support IS TRUE.

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

DB2 supports lateral subqueries

# File lib/sequel/adapters/shared/db2.rb, line 358
def supports_lateral_subqueries?
  true
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 363
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 368
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 373
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 383
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 378
def supports_window_functions?
  true
end

Private Instance Methods

_truncate_sql(table) click to toggle source
# File lib/sequel/adapters/shared/db2.rb, line 464
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
empty_from_sql() click to toggle source
# File lib/sequel/adapters/shared/db2.rb, line 389
def empty_from_sql
  EMPTY_FROM_TABLE
end
emulate_offset_with_row_number?() click to toggle source

Emulate offset with row number by default, and also when the limit_offset strategy is used without a limit, as DB2 doesn't support that syntax with no limit.

# File lib/sequel/adapters/shared/db2.rb, line 396
def emulate_offset_with_row_number?
  super && (db.offset_strategy == :emulate || (db.offset_strategy == :limit_offset && !@opts[:limit]))
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 402
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 417
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 407
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 412
def literal_true
  BOOL_TRUE
end
multi_insert_sql_strategy() click to toggle source

DB2 can insert multiple rows using a UNION

# File lib/sequel/adapters/shared/db2.rb, line 426
def multi_insert_sql_strategy
  :union
end
require_offset_order?() click to toggle source

DB2 does not require that ROW_NUMBER be ordered.

# File lib/sequel/adapters/shared/db2.rb, line 431
def require_offset_order?
  false
end
select_limit_sql(sql) click to toggle source

Modify the sql to limit the number of rows returned. Uses :offset_strategy Database option to determine how to format the limit and offset.

Calls superclass method
# File lib/sequel/adapters/shared/db2.rb, line 438
def select_limit_sql(sql)
  strategy = db.offset_strategy
  return super if strategy == :limit_offset

  if strategy == :offset_fetch && (o = @opts[:offset]) 
    sql << " OFFSET "
    literal_append(sql, o)
    sql << " ROWS"
  end

  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
supports_quoted_function_names?() click to toggle source

DB2 supports quoted function names.

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