module Sequel::DB2::DatasetMethods
Constants
- BITWISE_METHOD_MAP
Public Instance Methods
DB2 casts strings using RTRIM and CHAR instead of VARCHAR.
# File lib/sequel/adapters/shared/db2.rb, line 280 def cast_sql_append(sql, expr, type) if(type == String) sql << "RTRIM(CHAR(" literal_append(sql, expr) sql << "))" else super end end
# File lib/sequel/adapters/shared/db2.rb, line 290 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[0].to_s sql << '(' literal_append(sql, args[1]) sql << ')' else super end end
# File lib/sequel/adapters/shared/db2.rb, line 306 def quote_identifiers? @opts.fetch(:quote_identifiers, false) end
# File lib/sequel/adapters/shared/db2.rb, line 310 def supports_cte?(type=:select) type == :select end
DB2 supports GROUP BY CUBE
# File lib/sequel/adapters/shared/db2.rb, line 315 def supports_group_cube? true end
DB2 supports GROUP BY ROLLUP
# File lib/sequel/adapters/shared/db2.rb, line 320 def supports_group_rollup? true end
DB2 supports GROUPING SETS
# File lib/sequel/adapters/shared/db2.rb, line 325 def supports_grouping_sets? true end
DB2 does not support IS TRUE.
# File lib/sequel/adapters/shared/db2.rb, line 330 def supports_is_true? false end
DB2 supports lateral subqueries
# File lib/sequel/adapters/shared/db2.rb, line 335 def supports_lateral_subqueries? true end
DB2 does not support multiple columns in IN.
# File lib/sequel/adapters/shared/db2.rb, line 340 def supports_multiple_column_in? false end
DB2 only allows * in SELECT if it is the only thing being selected.
# File lib/sequel/adapters/shared/db2.rb, line 345 def supports_select_all_and_column? false end
DB2 does not support WHERE 1.
# File lib/sequel/adapters/shared/db2.rb, line 355 def supports_where_true? false end
DB2 supports window functions
# File lib/sequel/adapters/shared/db2.rb, line 350 def supports_window_functions? true end
Private Instance Methods
# File lib/sequel/adapters/shared/db2.rb, line 450 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
# File lib/sequel/adapters/shared/db2.rb, line 361 def empty_from_sql ' FROM "SYSIBM"."SYSDUMMY1"' end
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 368 def emulate_offset_with_row_number? super && (db.offset_strategy == :emulate || (db.offset_strategy == :limit_offset && !@opts[:limit])) end
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 374 def insert_supports_empty_values? false end
DB2 uses a literal hexidecimal number for blob strings
# File lib/sequel/adapters/shared/db2.rb, line 394 def literal_blob_append(sql, v) if db.use_clob_as_blob super else sql << "BLOB(X'" << v.unpack("H*").first << "')" end end
Use 0 for false on DB2
# File lib/sequel/adapters/shared/db2.rb, line 379 def literal_false '0' end
DB2 doesn't support fractional seconds in times, only fractional seconds in timestamps.
# File lib/sequel/adapters/shared/db2.rb, line 384 def literal_sqltime(v) v.strftime("'%H:%M:%S'") end
Use 1 for true on DB2
# File lib/sequel/adapters/shared/db2.rb, line 389 def literal_true '1' end
DB2 can insert multiple rows using a UNION
# File lib/sequel/adapters/shared/db2.rb, line 403 def multi_insert_sql_strategy :union end
Emulate the char_length function with length
# File lib/sequel/adapters/shared/db2.rb, line 408 def native_function_name(emulated_function) if emulated_function == :char_length 'length' else super end end
DB2 does not require that ROW_NUMBER be ordered.
# File lib/sequel/adapters/shared/db2.rb, line 417 def require_offset_order? false end
Modify the sql to limit the number of rows returned. Uses :offset_strategy Database option to determine how to format the limit and offset.
# File lib/sequel/adapters/shared/db2.rb, line 424 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
DB2 supports quoted function names.
# File lib/sequel/adapters/shared/db2.rb, line 446 def supports_quoted_function_names? true end