module Sequel::Oracle::DatasetMethods
Constants
- BITAND_PROC
- ROW_NUMBER_EXPRESSION
Public Instance Methods
# File lib/sequel/adapters/shared/oracle.rb 329 def complex_expression_sql_append(sql, op, args) 330 case op 331 when :& 332 complex_expression_arg_pairs_append(sql, args, &BITAND_PROC) 333 when :| 334 complex_expression_arg_pairs_append(sql, args){|a, b| Sequel.lit(["(", " - ", " + ", ")"], a, complex_expression_arg_pairs([a, b], &BITAND_PROC), b)} 335 when :^ 336 complex_expression_arg_pairs_append(sql, args) do |*x| 337 s1 = complex_expression_arg_pairs(x){|a, b| Sequel.lit(["(", " - ", " + ", ")"], a, complex_expression_arg_pairs([a, b], &BITAND_PROC), b)} 338 s2 = complex_expression_arg_pairs(x, &BITAND_PROC) 339 Sequel.lit(["(", " - ", ")"], s1, s2) 340 end 341 when :~, :'!~', :'~*', :'!~*' 342 raise InvalidOperation, "Pattern matching via regular expressions is not supported in this Oracle version" unless supports_regexp? 343 if op == :'!~' || op == :'!~*' 344 sql << 'NOT ' 345 end 346 sql << 'REGEXP_LIKE(' 347 literal_append(sql, args[0]) 348 sql << ',' 349 literal_append(sql, args[1]) 350 if op == :'~*' || op == :'!~*' 351 sql << ", 'i'" 352 end 353 sql << ')' 354 when :%, :<<, :>>, :'B~' 355 complex_expression_emulate_append(sql, op, args) 356 else 357 super 358 end 359 end
Oracle
doesn’t support CURRENT_TIME, as it doesn’t have a type for storing just time values without a date, so use CURRENT_TIMESTAMP in its place.
# File lib/sequel/adapters/shared/oracle.rb 364 def constant_sql_append(sql, c) 365 if c == :CURRENT_TIME 366 super(sql, :CURRENT_TIMESTAMP) 367 else 368 super 369 end 370 end
Use a custom expression with EXISTS to determine whether a dataset is empty.
# File lib/sequel/adapters/shared/oracle.rb 380 def empty? 381 db[:dual].where(@opts[:offset] ? exists : unordered.exists).get(1) == nil 382 end
Oracle
uses MINUS instead of EXCEPT, and doesn’t support EXCEPT ALL
# File lib/sequel/adapters/shared/oracle.rb 373 def except(dataset, opts=OPTS) 374 raise(Sequel::Error, "EXCEPT ALL not supported") if opts[:all] 375 compound_clone(:minus, dataset, opts) 376 end
Oracle
requires recursive CTEs to have column aliases.
# File lib/sequel/adapters/shared/oracle.rb 432 def recursive_cte_requires_column_aliases? 433 true 434 end
Handle LIMIT by using a unlimited subselect filtered with ROWNUM, unless Oracle
12 is used.
# File lib/sequel/adapters/shared/oracle.rb 398 def select_sql 399 return super if @opts[:sql] 400 return super if supports_fetch_next_rows? 401 402 o = @opts[:offset] 403 if o && o != 0 404 columns = clone(:append_sql=>String.new, :placeholder_literal_null=>true).columns 405 dsa1 = dataset_alias(1) 406 rn = row_number_column 407 limit = @opts[:limit] 408 ds = unlimited. 409 from_self(:alias=>dsa1). 410 select_append(ROW_NUMBER_EXPRESSION.as(rn)). 411 from_self(:alias=>dsa1). 412 select(*columns). 413 where(SQL::Identifier.new(rn) > o) 414 ds = ds.where(SQL::Identifier.new(rn) <= Sequel.+(o, limit)) if limit 415 sql = @opts[:append_sql] || String.new 416 subselect_sql_append(sql, ds) 417 sql 418 elsif limit = @opts[:limit] 419 ds = unlimited 420 # Lock doesn't work in subselects, so don't use a subselect when locking. 421 # Don't use a subselect if custom SQL is used, as it breaks somethings. 422 ds = ds.from_self unless @opts[:lock] 423 sql = @opts[:append_sql] || String.new 424 subselect_sql_append(sql, ds.where(SQL::ComplexExpression.new(:<=, ROW_NUMBER_EXPRESSION, limit))) 425 sql 426 else 427 super 428 end 429 end
Create a copy of this dataset associated to the given sequence name, which will be used when calling insert to find the most recently inserted value for the sequence.
# File lib/sequel/adapters/shared/oracle.rb 392 def sequence(s) 393 clone(:sequence=>s) 394 end
The version of the database server
# File lib/sequel/adapters/shared/oracle.rb 517 def server_version 518 db.server_version(@opts[:server]) 519 end
# File lib/sequel/adapters/shared/oracle.rb 436 def supports_cte?(type=:select) 437 type == :select 438 end
Oracle
does not support derived column lists
# File lib/sequel/adapters/shared/oracle.rb 441 def supports_derived_column_lists? 442 false 443 end
Oracle
supports FETCH NEXT ROWS since 12c, but it doesn’t work when locking or when skipping locked rows.
# File lib/sequel/adapters/shared/oracle.rb 447 def supports_fetch_next_rows? 448 server_version >= 12000000 && !(@opts[:lock] || @opts[:skip_locked]) 449 end
Oracle
supports GROUP BY CUBE
# File lib/sequel/adapters/shared/oracle.rb 452 def supports_group_cube? 453 true 454 end
Oracle
supports GROUP BY ROLLUP
# File lib/sequel/adapters/shared/oracle.rb 457 def supports_group_rollup? 458 true 459 end
Oracle
supports GROUPING SETS
# File lib/sequel/adapters/shared/oracle.rb 462 def supports_grouping_sets? 463 true 464 end
Oracle
does not support INTERSECT ALL or EXCEPT ALL
# File lib/sequel/adapters/shared/oracle.rb 467 def supports_intersect_except_all? 468 false 469 end
Oracle
does not support IS TRUE.
# File lib/sequel/adapters/shared/oracle.rb 472 def supports_is_true? 473 false 474 end
Oracle
supports NOWAIT.
# File lib/sequel/adapters/shared/oracle.rb 482 def supports_nowait? 483 true 484 end
Oracle
10+ supports pattern matching via regular expressions
# File lib/sequel/adapters/shared/oracle.rb 522 def supports_regexp? 523 server_version >= 10010002 524 end
Oracle
does not support SELECT *, column
# File lib/sequel/adapters/shared/oracle.rb 492 def supports_select_all_and_column? 493 false 494 end
Oracle
supports SKIP LOCKED.
# File lib/sequel/adapters/shared/oracle.rb 497 def supports_skip_locked? 498 true 499 end
Oracle
supports timezones in literal timestamps.
# File lib/sequel/adapters/shared/oracle.rb 502 def supports_timestamp_timezones? 503 true 504 end
Oracle
does not support WHERE ‘Y’ for WHERE TRUE.
# File lib/sequel/adapters/shared/oracle.rb 507 def supports_where_true? 508 false 509 end
Oracle
supports window functions
# File lib/sequel/adapters/shared/oracle.rb 512 def supports_window_functions? 513 true 514 end
Private Instance Methods
Allow preparing prepared statements, since determining the prepared sql to use for a prepared statement requires calling prepare on that statement.
# File lib/sequel/adapters/shared/oracle.rb 530 def allow_preparing_prepared_statements? 531 true 532 end
Oracle
doesn’t support the use of AS when aliasing a dataset. It doesn’t require the use of AS anywhere, so this disables it in all cases. Oracle
also does not support derived column lists in aliases.
# File lib/sequel/adapters/shared/oracle.rb 537 def as_sql_append(sql, aliaz, column_aliases=nil) 538 raise Error, "oracle does not support derived column lists" if column_aliases 539 sql << ' ' 540 quote_identifier_append(sql, aliaz) 541 end
The strftime format to use when literalizing the time.
# File lib/sequel/adapters/shared/oracle.rb 544 def default_timestamp_format 545 "TIMESTAMP '%Y-%m-%d %H:%M:%S%N %z'" 546 end
# File lib/sequel/adapters/shared/oracle.rb 548 def empty_from_sql 549 ' FROM DUAL' 550 end
There is no function on Oracle
that does character length and respects trailing spaces (datalength respects trailing spaces, but counts bytes instead of characters). Use a hack to work around the trailing spaces issue.
# File lib/sequel/adapters/shared/oracle.rb 556 def emulate_function?(name) 557 name == :char_length 558 end
Oracle
treats empty strings like NULL values, and doesn’t support char_length, so make char_length use length with a nonempty string. Unfortunately, as Oracle
treats the empty string as NULL, there is no way to get trim to return an empty string instead of nil if the string only contains spaces.
# File lib/sequel/adapters/shared/oracle.rb 565 def emulate_function_sql_append(sql, f) 566 if f.name == :char_length 567 literal_append(sql, Sequel::SQL::Function.new(:length, Sequel.join([f.args.first, 'x'])) - 1) 568 end 569 end
If this dataset is associated with a sequence, return the most recently inserted sequence value.
# File lib/sequel/adapters/shared/oracle.rb 573 def execute_insert(sql, opts=OPTS) 574 opts = Hash[opts] 575 if f = @opts[:from] 576 opts[:table] = f.first 577 end 578 opts[:sequence] = @opts[:sequence] 579 super 580 end
Use a colon for the timestamp offset, since Oracle
appears to require it.
# File lib/sequel/adapters/shared/oracle.rb 583 def format_timestamp_offset(hour, minute) 584 sprintf("%+03i:%02i", hour, minute) 585 end
Oracle
doesn’t support empty values when inserting.
# File lib/sequel/adapters/shared/oracle.rb 588 def insert_supports_empty_values? 589 false 590 end
Use string in hex format for blob data.
# File lib/sequel/adapters/shared/oracle.rb 593 def literal_blob_append(sql, v) 594 sql << "'" << v.unpack("H*").first << "'" 595 end
Oracle
uses ‘N’ for false values.
# File lib/sequel/adapters/shared/oracle.rb 598 def literal_false 599 "'N'" 600 end
Oracle
uses ‘Y’ for true values.
# File lib/sequel/adapters/shared/oracle.rb 608 def literal_true 609 "'Y'" 610 end
Oracle
can insert multiple rows using a UNION
# File lib/sequel/adapters/shared/oracle.rb 613 def multi_insert_sql_strategy 614 :union 615 end
# File lib/sequel/adapters/shared/oracle.rb 617 def select_limit_sql(sql) 618 return unless supports_fetch_next_rows? 619 620 if offset = @opts[:offset] 621 sql << " OFFSET " 622 literal_append(sql, offset) 623 sql << " ROWS" 624 end 625 626 if limit = @opts[:limit] 627 sql << " FETCH NEXT " 628 literal_append(sql, limit) 629 sql << " ROWS ONLY" 630 end 631 end
Use SKIP LOCKED if skipping locked rows.
# File lib/sequel/adapters/shared/oracle.rb 634 def select_lock_sql(sql) 635 super 636 637 if @opts[:lock] 638 if @opts[:skip_locked] 639 sql << " SKIP LOCKED" 640 elsif @opts[:nowait] 641 sql << " NOWAIT" 642 end 643 end 644 end
Oracle
supports quoted function names.
# File lib/sequel/adapters/shared/oracle.rb 647 def supports_quoted_function_names? 648 true 649 end