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
does not support multiple columns in IN.
# File lib/sequel/adapters/shared/db2.rb 342 def supports_multiple_column_in? 343 false 344 end
DB2
only allows * in SELECT if it is the only thing being selected.
# File lib/sequel/adapters/shared/db2.rb 347 def supports_select_all_and_column? 348 false 349 end
DB2
does not support WHERE 1.
# File lib/sequel/adapters/shared/db2.rb 357 def supports_where_true? 358 false 359 end
DB2
supports window functions
# File lib/sequel/adapters/shared/db2.rb 352 def supports_window_functions? 353 true 354 end
Private Instance Methods
# File lib/sequel/adapters/shared/db2.rb 457 def _truncate_sql(table) 458 # "TRUNCATE #{table} IMMEDIATE" is only for newer version of db2, so we 459 # use the following one 460 "ALTER TABLE #{quote_schema_table(table)} ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE" 461 end
# File lib/sequel/adapters/shared/db2.rb 363 def empty_from_sql 364 ' FROM "SYSIBM"."SYSDUMMY1"' 365 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 370 def emulate_offset_with_row_number? 371 super && (db.offset_strategy == :emulate || (db.offset_strategy == :limit_offset && !@opts[:limit])) 372 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 376 def insert_supports_empty_values? 377 false 378 end
DB2
uses a literal hexidecimal number for blob strings
# File lib/sequel/adapters/shared/db2.rb 396 def literal_blob_append(sql, v) 397 if db.use_clob_as_blob 398 super 399 else 400 sql << "BLOB(X'" << v.unpack("H*").first << "')" 401 end 402 end
Use 0 for false on DB2
# File lib/sequel/adapters/shared/db2.rb 381 def literal_false 382 '0' 383 end
DB2
doesn’t support fractional seconds in times, only fractional seconds in timestamps.
# File lib/sequel/adapters/shared/db2.rb 386 def literal_sqltime(v) 387 v.strftime("'%H:%M:%S'") 388 end
Use 1 for true on DB2
# File lib/sequel/adapters/shared/db2.rb 391 def literal_true 392 '1' 393 end
DB2
can insert multiple rows using a UNION
# File lib/sequel/adapters/shared/db2.rb 405 def multi_insert_sql_strategy 406 :union 407 end
Emulate the char_length function with length
# File lib/sequel/adapters/shared/db2.rb 410 def native_function_name(emulated_function) 411 if emulated_function == :char_length 412 'length' 413 else 414 super 415 end 416 end
DB2
does not require that ROW_NUMBER be ordered.
# File lib/sequel/adapters/shared/db2.rb 419 def require_offset_order? 420 false 421 end
At least some versions of DB do not support NULLS FIRST/LAST.
# File lib/sequel/adapters/shared/db2.rb 424 def requires_emulating_nulls_first? 425 true 426 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 431 def select_limit_sql(sql) 432 strategy = db.offset_strategy 433 return super if strategy == :limit_offset 434 435 if strategy == :offset_fetch && (o = @opts[:offset]) 436 sql << " OFFSET " 437 literal_append(sql, o) 438 sql << " ROWS" 439 end 440 441 if l = @opts[:limit] 442 if l == 1 443 sql << " FETCH FIRST ROW ONLY" 444 else 445 sql << " FETCH FIRST " 446 literal_append(sql, l) 447 sql << " ROWS ONLY" 448 end 449 end 450 end
DB2
supports quoted function names.
# File lib/sequel/adapters/shared/db2.rb 453 def supports_quoted_function_names? 454 true 455 end