module Sequel::DB2::DatasetMethods

Constants

BITWISE_METHOD_MAP

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
302 def cast_sql_append(sql, expr, type)
303   if(type == String)
304     sql << "RTRIM(CHAR("
305     literal_append(sql, expr)
306     sql << "))"
307   else
308     super
309   end
310 end
complex_expression_sql_append(sql, op, args) click to toggle source
Calls superclass method
    # File lib/sequel/adapters/shared/db2.rb
312 def complex_expression_sql_append(sql, op, args)
313   case op
314   when :&, :|, :^, :%, :<<, :>>
315     complex_expression_emulate_append(sql, op, args)
316   when :'B~'
317     literal_append(sql, SQL::Function.new(:BITNOT, *args))
318   when :extract
319     sql << args[0].to_s
320     sql << '('
321     literal_append(sql, args[1])
322     sql << ')'
323   else
324     super
325   end
326 end
quote_identifiers?() click to toggle source
    # File lib/sequel/adapters/shared/db2.rb
328 def quote_identifiers?
329   @opts.fetch(:quote_identifiers, false)
330 end
supports_cte?(type=:select) click to toggle source
    # File lib/sequel/adapters/shared/db2.rb
332 def supports_cte?(type=:select)
333   type == :select
334 end
supports_group_cube?() click to toggle source

DB2 supports GROUP BY CUBE

    # File lib/sequel/adapters/shared/db2.rb
337 def supports_group_cube?
338   true
339 end
supports_group_rollup?() click to toggle source

DB2 supports GROUP BY ROLLUP

    # File lib/sequel/adapters/shared/db2.rb
342 def supports_group_rollup?
343   true
344 end
supports_grouping_sets?() click to toggle source

DB2 supports GROUPING SETS

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

DB2 does not support IS TRUE.

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

DB2 supports lateral subqueries

    # File lib/sequel/adapters/shared/db2.rb
357 def supports_lateral_subqueries?
358   true
359 end
supports_merge?() click to toggle source

DB2 supports MERGE

    # File lib/sequel/adapters/shared/db2.rb
362 def supports_merge?
363   true
364 end
supports_multiple_column_in?() click to toggle source

DB2 does not support multiple columns in IN.

    # File lib/sequel/adapters/shared/db2.rb
367 def supports_multiple_column_in?
368   false
369 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
372 def supports_select_all_and_column?
373   false
374 end
supports_where_true?() click to toggle source

DB2 does not support WHERE 1.

    # File lib/sequel/adapters/shared/db2.rb
382 def supports_where_true?
383   false
384 end
supports_window_functions?() click to toggle source

DB2 supports window functions

    # File lib/sequel/adapters/shared/db2.rb
377 def supports_window_functions?
378   true
379 end

Private Instance Methods

_merge_when_conditions_sql(sql, data) click to toggle source

Normalize conditions for MERGE WHEN.

    # File lib/sequel/adapters/shared/db2.rb
389 def _merge_when_conditions_sql(sql, data)
390   if data.has_key?(:conditions)
391     sql << " AND "
392     literal_append(sql, _normalize_merge_when_conditions(data[:conditions]))
393   end
394 end
_normalize_merge_when_conditions(conditions) click to toggle source

Handle nil, false, and true MERGE WHEN conditions to avoid non-boolean type error.

    # File lib/sequel/adapters/shared/db2.rb
398 def _normalize_merge_when_conditions(conditions)
399   case conditions
400   when nil, false
401     {1=>0}
402   when true
403     {1=>1}
404   when Sequel::SQL::DelayedEvaluation
405     Sequel.delay{_normalize_merge_when_conditions(conditions.call(self))}
406   else
407     conditions
408   end
409 end
_truncate_sql(table) click to toggle source
    # File lib/sequel/adapters/shared/db2.rb
505 def _truncate_sql(table)
506   # "TRUNCATE #{table} IMMEDIATE" is only for newer version of db2, so we
507   # use the following one
508   "ALTER TABLE #{quote_schema_table(table)} ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE"
509 end
empty_from_sql() click to toggle source
    # File lib/sequel/adapters/shared/db2.rb
411 def empty_from_sql
412   ' FROM "SYSIBM"."SYSDUMMY1"'
413 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
418 def emulate_offset_with_row_number?
419   super && (db.offset_strategy == :emulate || (db.offset_strategy == :limit_offset && !@opts[:limit]))
420 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
424 def insert_supports_empty_values?
425   false
426 end
literal_blob_append(sql, v) click to toggle source

DB2 uses a literal hexadecimal number for blob strings

Calls superclass method
    # File lib/sequel/adapters/shared/db2.rb
444 def literal_blob_append(sql, v)
445   if db.use_clob_as_blob
446     super
447   else
448     sql << "BLOB(X'" << v.unpack("H*").first << "')"
449   end
450 end
literal_false() click to toggle source

Use 0 for false on DB2

    # File lib/sequel/adapters/shared/db2.rb
429 def literal_false
430   '0'
431 end
literal_sqltime(v) click to toggle source

DB2 doesn't support fractional seconds in times, only fractional seconds in timestamps.

    # File lib/sequel/adapters/shared/db2.rb
434 def literal_sqltime(v)
435   v.strftime("'%H:%M:%S'")
436 end
literal_true() click to toggle source

Use 1 for true on DB2

    # File lib/sequel/adapters/shared/db2.rb
439 def literal_true
440   '1'
441 end
multi_insert_sql_strategy() click to toggle source

DB2 can insert multiple rows using a UNION

    # File lib/sequel/adapters/shared/db2.rb
453 def multi_insert_sql_strategy
454   :union
455 end
native_function_name(emulated_function) click to toggle source

Emulate the char_length function with length

Calls superclass method
    # File lib/sequel/adapters/shared/db2.rb
458 def native_function_name(emulated_function)
459   if emulated_function == :char_length
460     'length'
461   else
462     super
463   end
464 end
require_offset_order?() click to toggle source

DB2 does not require that ROW_NUMBER be ordered.

    # File lib/sequel/adapters/shared/db2.rb
467 def require_offset_order?
468   false
469 end
requires_emulating_nulls_first?() click to toggle source

At least some versions of DB do not support NULLS FIRST/LAST.

    # File lib/sequel/adapters/shared/db2.rb
472 def requires_emulating_nulls_first?
473   true
474 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
479 def select_limit_sql(sql)
480   strategy = db.offset_strategy
481   return super if strategy == :limit_offset
482 
483   if strategy == :offset_fetch && (o = @opts[:offset]) 
484     sql << " OFFSET "
485     literal_append(sql, o)
486     sql << " ROWS"
487   end
488 
489   if l = @opts[:limit]
490     if l == 1
491       sql << " FETCH FIRST ROW ONLY"
492     else
493       sql << " FETCH FIRST "
494       literal_append(sql, l)
495       sql << " ROWS ONLY"
496     end
497   end
498 end
supports_quoted_function_names?() click to toggle source

DB2 supports quoted function names.

    # File lib/sequel/adapters/shared/db2.rb
501 def supports_quoted_function_names?
502   true
503 end