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 299 def cast_sql_append(sql, expr, type) 300 if(type == String) 301 sql << "RTRIM(CHAR(" 302 literal_append(sql, expr) 303 sql << "))" 304 else 305 super 306 end 307 end
# File lib/sequel/adapters/shared/db2.rb 309 def complex_expression_sql_append(sql, op, args) 310 case op 311 when :&, :|, :^, :%, :<<, :>> 312 complex_expression_emulate_append(sql, op, args) 313 when :'B~' 314 literal_append(sql, SQL::Function.new(:BITNOT, *args)) 315 when :extract 316 sql << args[0].to_s 317 sql << '(' 318 literal_append(sql, args[1]) 319 sql << ')' 320 else 321 super 322 end 323 end
# File lib/sequel/adapters/shared/db2.rb 325 def quote_identifiers? 326 @opts.fetch(:quote_identifiers, false) 327 end
# File lib/sequel/adapters/shared/db2.rb 329 def supports_cte?(type=:select) 330 type == :select 331 end
DB2
supports GROUP BY CUBE
# File lib/sequel/adapters/shared/db2.rb 334 def supports_group_cube? 335 true 336 end
DB2
supports GROUP BY ROLLUP
# File lib/sequel/adapters/shared/db2.rb 339 def supports_group_rollup? 340 true 341 end
DB2
supports GROUPING SETS
# File lib/sequel/adapters/shared/db2.rb 344 def supports_grouping_sets? 345 true 346 end
DB2
does not support IS TRUE.
# File lib/sequel/adapters/shared/db2.rb 349 def supports_is_true? 350 false 351 end
DB2
supports lateral subqueries
# File lib/sequel/adapters/shared/db2.rb 354 def supports_lateral_subqueries? 355 true 356 end
DB2
supports MERGE
# File lib/sequel/adapters/shared/db2.rb 359 def supports_merge? 360 true 361 end
DB2
does not support multiple columns in IN.
# File lib/sequel/adapters/shared/db2.rb 364 def supports_multiple_column_in? 365 false 366 end
DB2
only allows * in SELECT if it is the only thing being selected.
# File lib/sequel/adapters/shared/db2.rb 369 def supports_select_all_and_column? 370 false 371 end
DB2
does not support WHERE 1.
# File lib/sequel/adapters/shared/db2.rb 379 def supports_where_true? 380 false 381 end
DB2
supports window functions
# File lib/sequel/adapters/shared/db2.rb 374 def supports_window_functions? 375 true 376 end
Private Instance Methods
Normalize conditions for MERGE WHEN.
# File lib/sequel/adapters/shared/db2.rb 386 def _merge_when_conditions_sql(sql, data) 387 if data.has_key?(:conditions) 388 sql << " AND " 389 literal_append(sql, _normalize_merge_when_conditions(data[:conditions])) 390 end 391 end
Handle nil, false, and true MERGE WHEN conditions to avoid non-boolean type error.
# File lib/sequel/adapters/shared/db2.rb 395 def _normalize_merge_when_conditions(conditions) 396 case conditions 397 when nil, false 398 {1=>0} 399 when true 400 {1=>1} 401 when Sequel::SQL::DelayedEvaluation 402 Sequel.delay{_normalize_merge_when_conditions(conditions.call(self))} 403 else 404 conditions 405 end 406 end
# File lib/sequel/adapters/shared/db2.rb 502 def _truncate_sql(table) 503 # "TRUNCATE #{table} IMMEDIATE" is only for newer version of db2, so we 504 # use the following one 505 "ALTER TABLE #{quote_schema_table(table)} ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE" 506 end
# File lib/sequel/adapters/shared/db2.rb 408 def empty_from_sql 409 ' FROM "SYSIBM"."SYSDUMMY1"' 410 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?
# File lib/sequel/adapters/shared/db2.rb 415 def emulate_offset_with_row_number? 416 super && (db.offset_strategy == :emulate || (db.offset_strategy == :limit_offset && !@opts[:limit])) 417 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 421 def insert_supports_empty_values? 422 false 423 end
DB2
uses a literal hexidecimal number for blob strings
# File lib/sequel/adapters/shared/db2.rb 441 def literal_blob_append(sql, v) 442 if db.use_clob_as_blob 443 super 444 else 445 sql << "BLOB(X'" << v.unpack("H*").first << "')" 446 end 447 end
Use 0 for false on DB2
# File lib/sequel/adapters/shared/db2.rb 426 def literal_false 427 '0' 428 end
DB2
doesn’t support fractional seconds in times, only fractional seconds in timestamps.
# File lib/sequel/adapters/shared/db2.rb 431 def literal_sqltime(v) 432 v.strftime("'%H:%M:%S'") 433 end
Use 1 for true on DB2
# File lib/sequel/adapters/shared/db2.rb 436 def literal_true 437 '1' 438 end
DB2
can insert multiple rows using a UNION
# File lib/sequel/adapters/shared/db2.rb 450 def multi_insert_sql_strategy 451 :union 452 end
Emulate the char_length function with length
# File lib/sequel/adapters/shared/db2.rb 455 def native_function_name(emulated_function) 456 if emulated_function == :char_length 457 'length' 458 else 459 super 460 end 461 end
DB2
does not require that ROW_NUMBER be ordered.
# File lib/sequel/adapters/shared/db2.rb 464 def require_offset_order? 465 false 466 end
At least some versions of DB do not support NULLS FIRST/LAST.
# File lib/sequel/adapters/shared/db2.rb 469 def requires_emulating_nulls_first? 470 true 471 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 476 def select_limit_sql(sql) 477 strategy = db.offset_strategy 478 return super if strategy == :limit_offset 479 480 if strategy == :offset_fetch && (o = @opts[:offset]) 481 sql << " OFFSET " 482 literal_append(sql, o) 483 sql << " ROWS" 484 end 485 486 if l = @opts[:limit] 487 if l == 1 488 sql << " FETCH FIRST ROW ONLY" 489 else 490 sql << " FETCH FIRST " 491 literal_append(sql, l) 492 sql << " ROWS ONLY" 493 end 494 end 495 end
DB2
supports quoted function names.
# File lib/sequel/adapters/shared/db2.rb 498 def supports_quoted_function_names? 499 true 500 end