module Sequel::DB2::DatasetMethods
Constants
- BITWISE_METHOD_MAP
Public Instance Methods
Source
# 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
DB2 casts strings using RTRIM and CHAR instead of VARCHAR.
Source
# 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
Source
# File lib/sequel/adapters/shared/db2.rb 328 def quote_identifiers? 329 @opts.fetch(:quote_identifiers, false) 330 end
Source
# File lib/sequel/adapters/shared/db2.rb 332 def supports_cte?(type=:select) 333 type == :select 334 end
Source
# File lib/sequel/adapters/shared/db2.rb 337 def supports_group_cube? 338 true 339 end
DB2 supports GROUP BY CUBE
Source
# File lib/sequel/adapters/shared/db2.rb 342 def supports_group_rollup? 343 true 344 end
DB2 supports GROUP BY ROLLUP
Source
# File lib/sequel/adapters/shared/db2.rb 347 def supports_grouping_sets? 348 true 349 end
DB2 supports GROUPING SETS
Source
# File lib/sequel/adapters/shared/db2.rb 352 def supports_is_true? 353 false 354 end
DB2 does not support IS TRUE.
Source
# File lib/sequel/adapters/shared/db2.rb 357 def supports_lateral_subqueries? 358 true 359 end
DB2 supports lateral subqueries
Source
# File lib/sequel/adapters/shared/db2.rb 362 def supports_merge? 363 true 364 end
DB2 supports MERGE
Source
# File lib/sequel/adapters/shared/db2.rb 367 def supports_multiple_column_in? 368 false 369 end
DB2 does not support multiple columns in IN.
Source
# File lib/sequel/adapters/shared/db2.rb 372 def supports_select_all_and_column? 373 false 374 end
DB2 only allows * in SELECT if it is the only thing being selected.
Source
# File lib/sequel/adapters/shared/db2.rb 382 def supports_where_true? 383 false 384 end
DB2 does not support WHERE 1.
Source
# File lib/sequel/adapters/shared/db2.rb 377 def supports_window_functions? 378 true 379 end
DB2 supports window functions
Private Instance Methods
Source
# 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 conditions for MERGE WHEN.
Source
# 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
Handle nil, false, and true MERGE WHEN conditions to avoid non-boolean type error.
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
Source
# File lib/sequel/adapters/shared/db2.rb 411 def empty_from_sql 412 ' FROM "SYSIBM"."SYSDUMMY1"' 413 end
Source
# 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
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.
Sequel::EmulateOffsetWithRowNumber#emulate_offset_with_row_number?
Source
# File lib/sequel/adapters/shared/db2.rb 424 def insert_supports_empty_values? 425 false 426 end
DB2 needs the standard workaround to insert all default values into a table with more than one column.
Source
# 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
DB2 uses a literal hexadecimal number for blob strings
Source
# File lib/sequel/adapters/shared/db2.rb 429 def literal_false 430 '0' 431 end
Use 0 for false on DB2
Source
# File lib/sequel/adapters/shared/db2.rb 434 def literal_sqltime(v) 435 v.strftime("'%H:%M:%S'") 436 end
DB2 doesn’t support fractional seconds in times, only fractional seconds in timestamps.
Source
# File lib/sequel/adapters/shared/db2.rb 439 def literal_true 440 '1' 441 end
Use 1 for true on DB2
Source
# File lib/sequel/adapters/shared/db2.rb 453 def multi_insert_sql_strategy 454 :union 455 end
DB2 can insert multiple rows using a UNION
Source
# 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
Emulate the char_length function with length
Source
# File lib/sequel/adapters/shared/db2.rb 467 def require_offset_order? 468 false 469 end
DB2 does not require that ROW_NUMBER be ordered.
Source
# File lib/sequel/adapters/shared/db2.rb 472 def requires_emulating_nulls_first? 473 true 474 end
At least some versions of DB do not support NULLS FIRST/LAST.
Source
# 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
Modify the sql to limit the number of rows returned. Uses :offset_strategy Database option to determine how to format the limit and offset.
Source
# File lib/sequel/adapters/shared/db2.rb 501 def supports_quoted_function_names? 502 true 503 end
DB2 supports quoted function names.