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 280 def cast_sql_append(sql, expr, type) 281 if(type == String) 282 sql << "RTRIM(CHAR(" 283 literal_append(sql, expr) 284 sql << "))" 285 else 286 super 287 end 288 end
# File lib/sequel/adapters/shared/db2.rb 290 def complex_expression_sql_append(sql, op, args) 291 case op 292 when :&, :|, :^, :%, :<<, :>> 293 complex_expression_emulate_append(sql, op, args) 294 when :'B~' 295 literal_append(sql, SQL::Function.new(:BITNOT, *args)) 296 when :extract 297 sql << args[0].to_s 298 sql << '(' 299 literal_append(sql, args[1]) 300 sql << ')' 301 else 302 super 303 end 304 end
# File lib/sequel/adapters/shared/db2.rb 306 def quote_identifiers? 307 @opts.fetch(:quote_identifiers, false) 308 end
# File lib/sequel/adapters/shared/db2.rb 310 def supports_cte?(type=:select) 311 type == :select 312 end
DB2
supports GROUP BY CUBE
# File lib/sequel/adapters/shared/db2.rb 315 def supports_group_cube? 316 true 317 end
DB2
supports GROUP BY ROLLUP
# File lib/sequel/adapters/shared/db2.rb 320 def supports_group_rollup? 321 true 322 end
DB2
supports GROUPING SETS
# File lib/sequel/adapters/shared/db2.rb 325 def supports_grouping_sets? 326 true 327 end
DB2
does not support IS TRUE.
# File lib/sequel/adapters/shared/db2.rb 330 def supports_is_true? 331 false 332 end
DB2
supports lateral subqueries
# File lib/sequel/adapters/shared/db2.rb 335 def supports_lateral_subqueries? 336 true 337 end
DB2
does not support multiple columns in IN.
# File lib/sequel/adapters/shared/db2.rb 340 def supports_multiple_column_in? 341 false 342 end
DB2
only allows * in SELECT if it is the only thing being selected.
# File lib/sequel/adapters/shared/db2.rb 345 def supports_select_all_and_column? 346 false 347 end
DB2
does not support WHERE 1.
# File lib/sequel/adapters/shared/db2.rb 355 def supports_where_true? 356 false 357 end
DB2
supports window functions
# File lib/sequel/adapters/shared/db2.rb 350 def supports_window_functions? 351 true 352 end
Private Instance Methods
# File lib/sequel/adapters/shared/db2.rb 455 def _truncate_sql(table) 456 # "TRUNCATE #{table} IMMEDIATE" is only for newer version of db2, so we 457 # use the following one 458 "ALTER TABLE #{quote_schema_table(table)} ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE" 459 end
# File lib/sequel/adapters/shared/db2.rb 361 def empty_from_sql 362 ' FROM "SYSIBM"."SYSDUMMY1"' 363 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 368 def emulate_offset_with_row_number? 369 super && (db.offset_strategy == :emulate || (db.offset_strategy == :limit_offset && !@opts[:limit])) 370 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 374 def insert_supports_empty_values? 375 false 376 end
DB2
uses a literal hexidecimal number for blob strings
# File lib/sequel/adapters/shared/db2.rb 394 def literal_blob_append(sql, v) 395 if db.use_clob_as_blob 396 super 397 else 398 sql << "BLOB(X'" << v.unpack("H*").first << "')" 399 end 400 end
Use 0 for false on DB2
# File lib/sequel/adapters/shared/db2.rb 379 def literal_false 380 '0' 381 end
DB2
doesn't support fractional seconds in times, only fractional seconds in timestamps.
# File lib/sequel/adapters/shared/db2.rb 384 def literal_sqltime(v) 385 v.strftime("'%H:%M:%S'") 386 end
Use 1 for true on DB2
# File lib/sequel/adapters/shared/db2.rb 389 def literal_true 390 '1' 391 end
DB2
can insert multiple rows using a UNION
# File lib/sequel/adapters/shared/db2.rb 403 def multi_insert_sql_strategy 404 :union 405 end
Emulate the char_length function with length
# File lib/sequel/adapters/shared/db2.rb 408 def native_function_name(emulated_function) 409 if emulated_function == :char_length 410 'length' 411 else 412 super 413 end 414 end
DB2
does not require that ROW_NUMBER be ordered.
# File lib/sequel/adapters/shared/db2.rb 417 def require_offset_order? 418 false 419 end
At least some versions of DB do not support NULLS FIRST/LAST.
# File lib/sequel/adapters/shared/db2.rb 422 def requires_emulating_nulls_first? 423 true 424 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 429 def select_limit_sql(sql) 430 strategy = db.offset_strategy 431 return super if strategy == :limit_offset 432 433 if strategy == :offset_fetch && (o = @opts[:offset]) 434 sql << " OFFSET " 435 literal_append(sql, o) 436 sql << " ROWS" 437 end 438 439 if l = @opts[:limit] 440 if l == 1 441 sql << " FETCH FIRST ROW ONLY" 442 else 443 sql << " FETCH FIRST " 444 literal_append(sql, l) 445 sql << " ROWS ONLY" 446 end 447 end 448 end
DB2
supports quoted function names.
# File lib/sequel/adapters/shared/db2.rb 451 def supports_quoted_function_names? 452 true 453 end