Module: Sequel::Oracle::DatasetMethods
- Included in:
- JDBC::Oracle::Dataset, Dataset
- Defined in:
- lib/sequel/adapters/shared/oracle.rb
Constant Summary collapse
- ROW_NUMBER_EXPRESSION =
LiteralString.new('ROWNUM').freeze
- SPACE =
Dataset::SPACE
- APOS =
Dataset::APOS
- APOS_RE =
Dataset::APOS_RE
- DOUBLE_APOS =
Dataset::DOUBLE_APOS
- FROM =
Dataset::FROM
- TIMESTAMP_FORMAT =
"TIMESTAMP '%Y-%m-%d %H:%M:%S%N %z'".freeze
- TIMESTAMP_OFFSET_FORMAT =
"%+03i:%02i".freeze
- BOOL_FALSE =
"'N'".freeze
- BOOL_TRUE =
"'Y'".freeze
- HSTAR =
"H*".freeze
- DUAL =
' FROM DUAL'.freeze
- BITAND_PROC =
lambda{|a, b| Sequel.lit(["CAST(BITAND(", ", ", ") AS INTEGER)"], a, b)}
Instance Method Summary collapse
- #complex_expression_sql_append(sql, op, args) ⇒ Object
-
#constant_sql_append(sql, c) ⇒ Object
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.
-
#empty? ⇒ Boolean
Use a custom expression with EXISTS to determine whether a dataset is empty.
-
#except(dataset, opts = OPTS) ⇒ Object
Oracle uses MINUS instead of EXCEPT, and doesn’t support EXCEPT ALL.
-
#recursive_cte_requires_column_aliases? ⇒ Boolean
Oracle requires recursive CTEs to have column aliases.
-
#requires_sql_standard_datetimes? ⇒ Boolean
Oracle requires SQL standard datetimes.
-
#select_sql ⇒ Object
Handle LIMIT by using a unlimited subselect filtered with ROWNUM.
-
#sequence(s) ⇒ Object
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.
- #supports_cte?(type = :select) ⇒ Boolean
-
#supports_derived_column_lists? ⇒ Boolean
Oracle does not support derived column lists.
-
#supports_group_cube? ⇒ Boolean
Oracle supports GROUP BY CUBE.
-
#supports_group_rollup? ⇒ Boolean
Oracle supports GROUP BY ROLLUP.
-
#supports_grouping_sets? ⇒ Boolean
Oracle supports GROUPING SETS.
-
#supports_intersect_except_all? ⇒ Boolean
Oracle does not support INTERSECT ALL or EXCEPT ALL.
-
#supports_is_true? ⇒ Boolean
Oracle does not support IS TRUE.
-
#supports_limits_in_correlated_subqueries? ⇒ Boolean
Oracle does not support limits in correlated subqueries.
-
#supports_offsets_in_correlated_subqueries? ⇒ Boolean
Oracle does not support offsets in correlated subqueries.
-
#supports_select_all_and_column? ⇒ Boolean
Oracle does not support SELECT *, column.
-
#supports_timestamp_timezones? ⇒ Boolean
Oracle supports timezones in literal timestamps.
-
#supports_where_true? ⇒ Boolean
Oracle does not support WHERE ‘Y’ for WHERE TRUE.
-
#supports_window_functions? ⇒ Boolean
Oracle supports window functions.
Instance Method Details
#complex_expression_sql_append(sql, op, args) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 289 def complex_expression_sql_append(sql, op, args) case op when :& complex_expression_arg_pairs_append(sql, args, &BITAND_PROC) when :| complex_expression_arg_pairs_append(sql, args){|a, b| Sequel.lit(["(", " - ", " + ", ")"], a, complex_expression_arg_pairs([a, b], &BITAND_PROC), b)} when :^ complex_expression_arg_pairs_append(sql, args) do |*x| s1 = complex_expression_arg_pairs(x){|a, b| Sequel.lit(["(", " - ", " + ", ")"], a, complex_expression_arg_pairs([a, b], &BITAND_PROC), b)} s2 = complex_expression_arg_pairs(x, &BITAND_PROC) Sequel.lit(["(", " - ", ")"], s1, s2) end when :%, :<<, :>>, :'B~' complex_expression_emulate_append(sql, op, args) else super end end |
#constant_sql_append(sql, c) ⇒ Object
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.
311 312 313 314 315 316 317 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 311 def constant_sql_append(sql, c) if c == :CURRENT_TIME super(sql, :CURRENT_TIMESTAMP) else super end end |
#empty? ⇒ Boolean
Use a custom expression with EXISTS to determine whether a dataset is empty.
327 328 329 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 327 def empty? db[:dual].where(@opts[:offset] ? exists : unordered.exists).get(1) == nil end |
#except(dataset, opts = OPTS) ⇒ Object
Oracle uses MINUS instead of EXCEPT, and doesn’t support EXCEPT ALL
320 321 322 323 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 320 def except(dataset, opts=OPTS) raise(Sequel::Error, "EXCEPT ALL not supported") if opts[:all] compound_clone(:minus, dataset, opts) end |
#recursive_cte_requires_column_aliases? ⇒ Boolean
Oracle requires recursive CTEs to have column aliases.
375 376 377 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 375 def recursive_cte_requires_column_aliases? true end |
#requires_sql_standard_datetimes? ⇒ Boolean
Oracle requires SQL standard datetimes
332 333 334 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 332 def requires_sql_standard_datetimes? true end |
#select_sql ⇒ Object
Handle LIMIT by using a unlimited subselect filtered with ROWNUM.
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 344 def select_sql return super if @opts[:sql] if o = @opts[:offset] columns = clone(:append_sql=>String.new, :placeholder_literal_null=>true).columns dsa1 = dataset_alias(1) rn = row_number_column limit = @opts[:limit] ds = unlimited. from_self(:alias=>dsa1). select_append(ROW_NUMBER_EXPRESSION.as(rn)). from_self(:alias=>dsa1). select(*columns). where(SQL::Identifier.new(rn) > o) ds = ds.where(SQL::Identifier.new(rn) <= Sequel.+(o, limit)) if limit sql = @opts[:append_sql] || String.new subselect_sql_append(sql, ds) sql elsif limit = @opts[:limit] ds = clone(:limit=>nil) # Lock doesn't work in subselects, so don't use a subselect when locking. # Don't use a subselect if custom SQL is used, as it breaks somethings. ds = ds.from_self unless @opts[:lock] sql = @opts[:append_sql] || String.new subselect_sql_append(sql, ds.where(SQL::ComplexExpression.new(:<=, ROW_NUMBER_EXPRESSION, limit))) sql else super end end |
#sequence(s) ⇒ Object
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.
339 340 341 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 339 def sequence(s) clone(:sequence=>s) end |
#supports_cte?(type = :select) ⇒ Boolean
379 380 381 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 379 def supports_cte?(type=:select) type == :select end |
#supports_derived_column_lists? ⇒ Boolean
Oracle does not support derived column lists
384 385 386 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 384 def supports_derived_column_lists? false end |
#supports_group_cube? ⇒ Boolean
Oracle supports GROUP BY CUBE
389 390 391 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 389 def supports_group_cube? true end |
#supports_group_rollup? ⇒ Boolean
Oracle supports GROUP BY ROLLUP
394 395 396 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 394 def supports_group_rollup? true end |
#supports_grouping_sets? ⇒ Boolean
Oracle supports GROUPING SETS
399 400 401 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 399 def supports_grouping_sets? true end |
#supports_intersect_except_all? ⇒ Boolean
Oracle does not support INTERSECT ALL or EXCEPT ALL
404 405 406 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 404 def supports_intersect_except_all? false end |
#supports_is_true? ⇒ Boolean
Oracle does not support IS TRUE.
409 410 411 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 409 def supports_is_true? false end |
#supports_limits_in_correlated_subqueries? ⇒ Boolean
Oracle does not support limits in correlated subqueries.
414 415 416 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 414 def false end |
#supports_offsets_in_correlated_subqueries? ⇒ Boolean
Oracle does not support offsets in correlated subqueries.
419 420 421 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 419 def false end |
#supports_select_all_and_column? ⇒ Boolean
Oracle does not support SELECT *, column
424 425 426 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 424 def supports_select_all_and_column? false end |
#supports_timestamp_timezones? ⇒ Boolean
Oracle supports timezones in literal timestamps.
429 430 431 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 429 def true end |
#supports_where_true? ⇒ Boolean
Oracle does not support WHERE ‘Y’ for WHERE TRUE.
434 435 436 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 434 def supports_where_true? false end |
#supports_window_functions? ⇒ Boolean
Oracle supports window functions
439 440 441 |
# File 'lib/sequel/adapters/shared/oracle.rb', line 439 def supports_window_functions? true end |