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