Module: Sequel::DB2::DatasetMethods

Includes:
EmulateOffsetWithRowNumber
Included in:
Dataset, IBMDB::Dataset, JDBC::DB2::Dataset
Defined in:
lib/sequel/adapters/shared/db2.rb

Constant Summary

PAREN_CLOSE =
Dataset::PAREN_CLOSE
PAREN_OPEN =
Dataset::PAREN_OPEN
BITWISE_METHOD_MAP =
{:& =>:BITAND, :| => :BITOR, :^ => :BITXOR, :B~'=>:BITNOT}
EMULATED_FUNCTION_MAP =
{:char_length=>'length'.freeze}
BOOL_TRUE =
'1'.freeze
BOOL_FALSE =
'0'.freeze
CAST_STRING_OPEN =
"RTRIM(CHAR(".freeze
CAST_STRING_CLOSE =
"))".freeze
FETCH_FIRST_ROW_ONLY =
" FETCH FIRST ROW ONLY".freeze
FETCH_FIRST =
" FETCH FIRST ".freeze
ROWS_ONLY =
" ROWS ONLY".freeze
EMPTY_FROM_TABLE =
' FROM "SYSIBM"."SYSDUMMY1"'.freeze
HSTAR =
"H*".freeze
BLOB_OPEN =
"BLOB(X'".freeze
BLOB_CLOSE =
"')".freeze

Instance Method Summary (collapse)

Methods included from EmulateOffsetWithRowNumber

#select_sql

Instance Method Details

- (Object) cast_sql_append(sql, expr, type)

DB2 casts strings using RTRIM and CHAR instead of VARCHAR.



247
248
249
250
251
252
253
254
255
# File 'lib/sequel/adapters/shared/db2.rb', line 247

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

- (Object) complex_expression_sql_append(sql, op, args)



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/sequel/adapters/shared/db2.rb', line 257

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

- (Boolean) supports_group_cube?

DB2 supports GROUP BY CUBE



282
283
284
# File 'lib/sequel/adapters/shared/db2.rb', line 282

def supports_group_cube?
  true
end

- (Boolean) supports_group_rollup?

DB2 supports GROUP BY ROLLUP



287
288
289
# File 'lib/sequel/adapters/shared/db2.rb', line 287

def supports_group_rollup?
  true
end

- (Boolean) supports_is_true?

DB2 does not support IS TRUE.



292
293
294
# File 'lib/sequel/adapters/shared/db2.rb', line 292

def supports_is_true?
  false
end

- (Boolean) supports_lateral_subqueries?

DB2 supports lateral subqueries



297
298
299
# File 'lib/sequel/adapters/shared/db2.rb', line 297

def supports_lateral_subqueries?
  true
end

- (Boolean) supports_multiple_column_in?

DB2 does not support multiple columns in IN.



302
303
304
# File 'lib/sequel/adapters/shared/db2.rb', line 302

def supports_multiple_column_in?
  false
end

- (Boolean) supports_select_all_and_column?

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



307
308
309
# File 'lib/sequel/adapters/shared/db2.rb', line 307

def supports_select_all_and_column?
  false
end

- (Boolean) supports_timestamp_usecs?

DB2 does not support fractional seconds in timestamps.



312
313
314
# File 'lib/sequel/adapters/shared/db2.rb', line 312

def supports_timestamp_usecs?
  false
end

- (Boolean) supports_where_true?

DB2 does not support WHERE 1.



322
323
324
# File 'lib/sequel/adapters/shared/db2.rb', line 322

def supports_where_true?
  false
end

- (Boolean) supports_window_functions?

DB2 supports window functions



317
318
319
# File 'lib/sequel/adapters/shared/db2.rb', line 317

def supports_window_functions?
  true
end