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 282 def cast_sql_append(sql, expr, type) 283 if(type == String) 284 sql << "RTRIM(CHAR(" 285 literal_append(sql, expr) 286 sql << "))" 287 else 288 super 289 end 290 end
# File lib/sequel/adapters/shared/db2.rb 292 def complex_expression_sql_append(sql, op, args) 293 case op 294 when :&, :|, :^, :%, :<<, :>> 295 complex_expression_emulate_append(sql, op, args) 296 when :'B~' 297 literal_append(sql, SQL::Function.new(:BITNOT, *args)) 298 when :extract 299 sql << args[0].to_s 300 sql << '(' 301 literal_append(sql, args[1]) 302 sql << ')' 303 else 304 super 305 end 306 end
# File lib/sequel/adapters/shared/db2.rb 308 def quote_identifiers? 309 @opts.fetch(:quote_identifiers, false) 310 end
# File lib/sequel/adapters/shared/db2.rb 312 def supports_cte?(type=:select) 313 type == :select 314 end
DB2
supports GROUP BY CUBE
# File lib/sequel/adapters/shared/db2.rb 317 def supports_group_cube? 318 true 319 end
DB2
supports GROUP BY ROLLUP
# File lib/sequel/adapters/shared/db2.rb 322 def supports_group_rollup? 323 true 324 end
DB2
supports GROUPING SETS
# File lib/sequel/adapters/shared/db2.rb 327 def supports_grouping_sets? 328 true 329 end
DB2
does not support IS TRUE.
# File lib/sequel/adapters/shared/db2.rb 332 def supports_is_true? 333 false 334 end
DB2
supports lateral subqueries
# File lib/sequel/adapters/shared/db2.rb 337 def supports_lateral_subqueries? 338 true 339 end
DB2
supports MERGE
# File lib/sequel/adapters/shared/db2.rb 342 def supports_merge? 343 true 344 end
DB2
does not support multiple columns in IN.
# File lib/sequel/adapters/shared/db2.rb 347 def supports_multiple_column_in? 348 false 349 end
DB2
only allows * in SELECT if it is the only thing being selected.
# File lib/sequel/adapters/shared/db2.rb 352 def supports_select_all_and_column? 353 false 354 end
DB2
does not support WHERE 1.
# File lib/sequel/adapters/shared/db2.rb 362 def supports_where_true? 363 false 364 end
DB2
supports window functions
# File lib/sequel/adapters/shared/db2.rb 357 def supports_window_functions? 358 true 359 end
Private Instance Methods
Normalize conditions for MERGE WHEN.
# File lib/sequel/adapters/shared/db2.rb 369 def _merge_when_conditions_sql(sql, data) 370 if data.has_key?(:conditions) 371 sql << " AND " 372 literal_append(sql, _normalize_merge_when_conditions(data[:conditions])) 373 end 374 end
Handle nil, false, and true MERGE WHEN conditions to avoid non-boolean type error.
# File lib/sequel/adapters/shared/db2.rb 378 def _normalize_merge_when_conditions(conditions) 379 case conditions 380 when nil, false 381 {1=>0} 382 when true 383 {1=>1} 384 when Sequel::SQL::DelayedEvaluation 385 Sequel.delay{_normalize_merge_when_conditions(conditions.call(self))} 386 else 387 conditions 388 end 389 end
# File lib/sequel/adapters/shared/db2.rb 485 def _truncate_sql(table) 486 # "TRUNCATE #{table} IMMEDIATE" is only for newer version of db2, so we 487 # use the following one 488 "ALTER TABLE #{quote_schema_table(table)} ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE" 489 end
# File lib/sequel/adapters/shared/db2.rb 391 def empty_from_sql 392 ' FROM "SYSIBM"."SYSDUMMY1"' 393 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 398 def emulate_offset_with_row_number? 399 super && (db.offset_strategy == :emulate || (db.offset_strategy == :limit_offset && !@opts[:limit])) 400 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 404 def insert_supports_empty_values? 405 false 406 end
DB2
uses a literal hexidecimal number for blob strings
# File lib/sequel/adapters/shared/db2.rb 424 def literal_blob_append(sql, v) 425 if db.use_clob_as_blob 426 super 427 else 428 sql << "BLOB(X'" << v.unpack("H*").first << "')" 429 end 430 end
Use 0 for false on DB2
# File lib/sequel/adapters/shared/db2.rb 409 def literal_false 410 '0' 411 end
DB2
doesn’t support fractional seconds in times, only fractional seconds in timestamps.
# File lib/sequel/adapters/shared/db2.rb 414 def literal_sqltime(v) 415 v.strftime("'%H:%M:%S'") 416 end
Use 1 for true on DB2
# File lib/sequel/adapters/shared/db2.rb 419 def literal_true 420 '1' 421 end
DB2
can insert multiple rows using a UNION
# File lib/sequel/adapters/shared/db2.rb 433 def multi_insert_sql_strategy 434 :union 435 end
Emulate the char_length function with length
# File lib/sequel/adapters/shared/db2.rb 438 def native_function_name(emulated_function) 439 if emulated_function == :char_length 440 'length' 441 else 442 super 443 end 444 end
DB2
does not require that ROW_NUMBER be ordered.
# File lib/sequel/adapters/shared/db2.rb 447 def require_offset_order? 448 false 449 end
At least some versions of DB do not support NULLS FIRST/LAST.
# File lib/sequel/adapters/shared/db2.rb 452 def requires_emulating_nulls_first? 453 true 454 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 459 def select_limit_sql(sql) 460 strategy = db.offset_strategy 461 return super if strategy == :limit_offset 462 463 if strategy == :offset_fetch && (o = @opts[:offset]) 464 sql << " OFFSET " 465 literal_append(sql, o) 466 sql << " ROWS" 467 end 468 469 if l = @opts[:limit] 470 if l == 1 471 sql << " FETCH FIRST ROW ONLY" 472 else 473 sql << " FETCH FIRST " 474 literal_append(sql, l) 475 sql << " ROWS ONLY" 476 end 477 end 478 end
DB2
supports quoted function names.
# File lib/sequel/adapters/shared/db2.rb 481 def supports_quoted_function_names? 482 true 483 end