Class: Arel::Visitors::Oracle
- Inherits:
-
Object
- Object
- Arel::Visitors::Oracle
- Defined in:
- lib/arel_extensions/visitors/oracle.rb
Constant Summary collapse
- SPECIAL_CHARS =
{"\t" => 'CHR(9)', "\n" => 'CHR(10)', "\r" => 'CHR(13)'}
- DATE_MAPPING =
{'d' => 'DAY', 'm' => 'MONTH', 'w' => 'IW', 'y' => 'YEAR', 'wd' => 'D', 'h' => 'HOUR', 'mn' => 'MINUTE', 's' => 'SECOND'}
- DATE_FORMAT_DIRECTIVES =
{ '%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY', '%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON', '%V' => 'IW', '%G' => 'IYYY', # ISO week number and year of week '%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%a' => 'Dy', '%A' => 'Day', # day, weekday '%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours '%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds }
- NUMBER_COMMA_MAPPING =
seconds, subseconds
{'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', '}
Instance Method Summary collapse
- #get_time_converted(element) ⇒ Object
-
#grouping_array_or_grouping_element(o, collector) ⇒ Object
Utilized by GroupingSet, Cube & RollUp visitors to handle grouping aggregation semantics.
- #visit_Arel_Attributes_Attribute(o, collector) ⇒ Object
- #visit_Arel_Nodes_As(o, collector) ⇒ Object
- #visit_Arel_Nodes_GreaterThan(o, collector) ⇒ Object
- #visit_Arel_Nodes_GreaterThanOrEqual(o, collector) ⇒ Object
- #visit_Arel_Nodes_LessThan(o, collector) ⇒ Object
- #visit_Arel_Nodes_LessThanOrEqual(o, collector) ⇒ Object
- #visit_Arel_Nodes_NotRegexp(o, collector) ⇒ Object
- #visit_Arel_Nodes_Regexp(o, collector) ⇒ Object
- #visit_Arel_Nodes_RollUp(o, collector) ⇒ Object
- #visit_Arel_Nodes_SelectStatement(o, collector) ⇒ Object
- #visit_Arel_Nodes_TableAlias(o, collector) ⇒ Object
- #visit_ArelExtensions_InsertManager_BulkValues(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_AiIMatches(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_AiMatches(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_As(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Blank(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Cast(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Coalesce(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Collate(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Concat(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_DateAdd(o, collector) ⇒ Object
-
#visit_ArelExtensions_Nodes_DateDiff(o, collector) ⇒ Object
:date is not possible in Oracle since this type does not really exist.
- #visit_ArelExtensions_Nodes_Duration(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Format(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_FormattedDate(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_FormattedNumber(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_GroupConcat(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IDoesNotMatch(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IMatches(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IsNotNull(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_IsNull(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Length(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_LevenshteinDistance(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Locate(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Log10(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Ltrim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_MD5(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_NotBlank(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Power(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Rand(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Repeat(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Rtrim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_SMatches(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Std(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Substring(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Trim(o, collector) ⇒ Object
- #visit_ArelExtensions_Nodes_Variance(o, collector) ⇒ Object
Instance Method Details
#get_time_converted(element) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 538 def get_time_converted element if element.is_a?(Time) ArelExtensions::Nodes::Format.new [element, '%H:%M:%S'] elsif element.is_a?(Arel::Attributes::Attribute) col = Arel.column_of(element.relation.table_name, element.name.to_s) if col && (col.type == :time) ArelExtensions::Nodes::Format.new [element, '%H:%M:%S'] else element end else element end end |
#grouping_array_or_grouping_element(o, collector) ⇒ Object
Utilized by GroupingSet, Cube & RollUp visitors to handle grouping aggregation semantics
720 721 722 723 724 725 726 727 728 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 720 def grouping_array_or_grouping_element(o, collector) if o.expr.is_a? Array collector << "( " visit o.expr, collector collector << " )" else visit o.expr, collector end end |
#visit_Arel_Attributes_Attribute(o, collector) ⇒ Object
625 626 627 628 629 630 631 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 625 def visit_Arel_Attributes_Attribute o, collector join_name = o.relation.table_alias || o.relation.name if join_name.length > 30 join_name = Arel.shorten(join_name) end collector << "#{quote_table_name join_name}.#{quote_column_name o.name}" end |
#visit_Arel_Nodes_As(o, collector) ⇒ Object
605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 605 def visit_Arel_Nodes_As o, collector if o.left.is_a?(Arel::Nodes::Binary) collector << '(' collector = visit o.left, collector collector << ')' else collector = visit o.left, collector end quote = /(\A".*"\z)|\A[a-zA-Z_]*\z/.match?(o.right.to_s) ? '' : '"' collector << " AS #{quote}" collector = visit o.right, collector collector << "#{quote}" collector end |
#visit_Arel_Nodes_GreaterThan(o, collector) ⇒ Object
563 564 565 566 567 568 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 563 def visit_Arel_Nodes_GreaterThan o, collector collector = visit get_time_converted(o.left), collector collector << ' > ' collector = visit get_time_converted(o.right), collector collector end |
#visit_Arel_Nodes_GreaterThanOrEqual(o, collector) ⇒ Object
555 556 557 558 559 560 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 555 def visit_Arel_Nodes_GreaterThanOrEqual o, collector collector = visit get_time_converted(o.left), collector collector << ' >= ' collector = visit get_time_converted(o.right), collector collector end |
#visit_Arel_Nodes_LessThan(o, collector) ⇒ Object
579 580 581 582 583 584 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 579 def visit_Arel_Nodes_LessThan o, collector collector = visit get_time_converted(o.left), collector collector << ' < ' collector = visit get_time_converted(o.right), collector collector end |
#visit_Arel_Nodes_LessThanOrEqual(o, collector) ⇒ Object
571 572 573 574 575 576 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 571 def visit_Arel_Nodes_LessThanOrEqual o, collector collector = visit get_time_converted(o.left), collector collector << ' <= ' collector = visit get_time_converted(o.right), collector collector end |
#visit_Arel_Nodes_NotRegexp(o, collector) ⇒ Object
355 356 357 358 359 360 361 362 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 355 def visit_Arel_Nodes_NotRegexp o, collector collector << ' NOT REGEXP_LIKE(' collector = visit o.left, collector collector << COMMA collector = visit o.right, collector collector << ')' collector end |
#visit_Arel_Nodes_Regexp(o, collector) ⇒ Object
346 347 348 349 350 351 352 353 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 346 def visit_Arel_Nodes_Regexp o, collector collector << ' REGEXP_LIKE(' collector = visit o.left, collector collector << COMMA collector = visit o.right, collector collector << ')' collector end |
#visit_Arel_Nodes_RollUp(o, collector) ⇒ Object
129 130 131 132 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 129 def visit_Arel_Nodes_RollUp(o, collector) collector << "ROLLUP" grouping_array_or_grouping_element o, collector end |
#visit_Arel_Nodes_SelectStatement(o, collector) ⇒ Object
588 589 590 591 592 593 594 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 588 def visit_Arel_Nodes_SelectStatement o, collector if !(collector.value.blank? || (collector.value.is_a?(Array) && collector.value[0].blank?)) && o.limit.blank? && o.offset.blank? o = o.dup o.orders = [] end old_visit_Arel_Nodes_SelectStatement(o, collector) end |
#visit_Arel_Nodes_TableAlias(o, collector) ⇒ Object
597 598 599 600 601 602 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 597 def visit_Arel_Nodes_TableAlias o, collector if o.name.length > 30 o = Arel::Table.new(o.table_name).alias(Arel.shorten(o.name)) end old_visit_Arel_Nodes_TableAlias(o, collector) end |
#visit_ArelExtensions_InsertManager_BulkValues(o, collector) ⇒ Object
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 492 def visit_ArelExtensions_InsertManager_BulkValues o, collector collector << '(' o.left.each_with_index do |row, idx| # values collector << ' UNION ALL ' if idx != 0 collector << '(SELECT ' len = row.length - 1 row.zip(o.cols).each_with_index { |(value, attr), i| case value when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam collector = visit value, collector else collector << quote(value, attr && column_for(attr)).to_s end collector << COMMA unless i == len } collector << ' FROM DUAL)' end collector << ')' collector end |
#visit_ArelExtensions_Nodes_AiIMatches(o, collector) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 72 def visit_ArelExtensions_Nodes_AiIMatches o, collector collector = visit o.left.ai_collate, collector collector << ' LIKE ' collector = visit o.right.ai_collate, collector if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_AiMatches(o, collector) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 60 def visit_ArelExtensions_Nodes_AiMatches o, collector collector = visit o.left.ai_collate, collector collector << ' LIKE ' collector = visit o.right.ai_collate, collector if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_As(o, collector) ⇒ Object
620 621 622 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 620 def visit_ArelExtensions_Nodes_As o, collector visit_Arel_Nodes_As o, collector end |
#visit_ArelExtensions_Nodes_Blank(o, collector) ⇒ Object
436 437 438 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 436 def visit_ArelExtensions_Nodes_Blank o, collector visit o.expr.trim.length.coalesce(0).eq(0), collector end |
#visit_ArelExtensions_Nodes_Cast(o, collector) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 257 def visit_ArelExtensions_Nodes_Cast o, collector case o.as_attr when :string collector << 'TO_CHAR(' collector = visit o.left, collector collector << ')' return collector when :text collector << 'TO_CLOB(' collector = visit o.left, collector collector << ')' return collector when :ntext collector << 'TO_NCLOB(' collector = visit o.left, collector collector << ')' return collector when :time if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted) collector << 'TO_DATE(' collector = visit o.left, collector collector << ",'HH24:MI:SS')" else collector << 'TO_DATE(TO_CHAR(' collector = visit o.left, collector collector << ",'HH24:MI:SS'),'HH24:MI:SS')" end return collector when :number, :decimal collector << 'TO_NUMBER(' collector = visit o.left, collector collector << ')' return collector when :datetime as_attr = Arel::Nodes::SqlLiteral.new('timestamp') when :date if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted) collector << 'TO_DATE(' collector = visit o.left, collector collector << ",'YYYY-MM-DD')" else collector << 'TO_DATE(TO_CHAR(' collector = visit o.left, collector collector << ",'YYYY-MM-DD'),'YYYY-MM-DD')" end return collector when :binary as_attr = Arel::Nodes::SqlLiteral.new('binary') else as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s) end collector << 'CAST(' collector = visit o.left, collector collector << ' AS ' collector = visit as_attr, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Coalesce(o, collector) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 157 def visit_ArelExtensions_Nodes_Coalesce o, collector collector << 'COALESCE(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 if i > 0 && o.left_node_type == :text if arg == '' || (arg.is_a?(Arel::Nodes::Quoted) && (arg.expr == '')) collector << 'NULL' else collector << 'TO_CLOB(' collector = visit arg, collector collector << ')' end else collector = visit arg, collector end } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Collate(o, collector) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 110 def visit_ArelExtensions_Nodes_Collate o, collector if o.ai collector << 'NLSSORT(' collector = visit o.expressions.first, collector collector << COMMA collector << "'NLS_SORT = BINARY_AI NLS_COMP = LINGUISTIC'" collector << ')' elsif o.ci collector << 'NLSSORT(' collector = visit o.expressions.first, collector collector << COMMA collector << "'NLS_SORT = BINARY_CI NLS_COMP = LINGUISTIC'" collector << ')' else collector = visit o.expressions.first, collector end collector end |
#visit_ArelExtensions_Nodes_Concat(o, collector) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 36 def visit_ArelExtensions_Nodes_Concat o, collector collector << '(' o.expressions.each_with_index { |arg, i| collector = visit o.convert_to_string_node(arg), collector collector << ' || ' unless i == o.expressions.length - 1 } collector << ')' collector end |
#visit_ArelExtensions_Nodes_DateAdd(o, collector) ⇒ Object
444 445 446 447 448 449 450 451 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 444 def visit_ArelExtensions_Nodes_DateAdd o, collector collector << '(' collector = visit o.left, collector collector << ' + ' # (o.right.value >= 0 ? ' + ' : ' - ') collector = visit o.oracle_value(o.right), collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_DateDiff(o, collector) ⇒ Object
:date is not possible in Oracle since this type does not really exist
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 185 def visit_ArelExtensions_Nodes_DateDiff o, collector lc = o.left_node_type == :ruby_date || o.left_node_type == :ruby_time rc = o.right_node_type == :ruby_date || o.right_node_type == :ruby_time if rc || o.right_node_type == :date || o.right_node_type == :datetime || o.right_node_type == :time collector << '(' collector << 'TO_DATE(' if lc collector = visit o.left, collector collector << ')' if lc collector << ' - ' collector << 'TO_DATE(' if rc collector = visit o.right, collector collector << ')' if rc collector << ')' if (o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time) collector << ' * (CASE WHEN (TRUNC(' collector << 'TO_DATE(' if lc collector = visit o.left, collector collector << ')' if lc collector << COMMA collector << "'DDD') = " collector << 'TO_DATE(' if lc collector = visit o.left, collector collector << ')' if lc collector << ') THEN 1 ELSE 86400 END)' # converts to seconds end else collector << '(' collector = visit o.left, collector collector << ' - (' if o.right.is_a?(ArelExtensions::Nodes::Duration) o.right.with_interval = true end collector = visit o.right, collector collector << '))' collector end collector end |
#visit_ArelExtensions_Nodes_Duration(o, collector) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 224 def visit_ArelExtensions_Nodes_Duration o, collector case o.left when 'wd', 'w' collector << 'TO_CHAR(' collector = visit o.right, collector collector << COMMA collector = visit Arel.quoted(DATE_MAPPING[o.left]), collector else right = case o.left when 'd', 'm', 'y' interval = 'DAY' o.right.cast(:date) when 'h', 'mn', 's' interval = 'SECOND' o.right.cast(:datetime) when /i\z/ interval = DATE_MAPPING[o.left[0..-2]] collector << '(' collector = visit o.right, collector collector << ") * (INTERVAL '1' #{interval})" return collector else interval = nil o.right end collector << "EXTRACT(#{DATE_MAPPING[o.left]} FROM " collector = visit right, collector end collector << ')' collector << " * (INTERVAL '1' #{interval})" if interval && o.with_interval collector end |
#visit_ArelExtensions_Nodes_Format(o, collector) ⇒ Object
453 454 455 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 453 def visit_ArelExtensions_Nodes_Format o, collector visit_ArelExtensions_Nodes_FormattedDate o, collector end |
#visit_ArelExtensions_Nodes_FormattedDate(o, collector) ⇒ Object
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 457 def visit_ArelExtensions_Nodes_FormattedDate o, collector fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES) collector << 'TO_CHAR(' collector << 'CAST(' if o.time_zone collector = visit o.left, collector case o.time_zone when Hash src_tz, dst_tz = o.time_zone.first collector << ' as timestamp) at time zone ' collector = visit Arel.quoted(src_tz), collector collector < ' at time zone ' collector = visit Arel.quoted(dst_tz), collector when String collector << ' as timestamp) at time zone ' collector = visit Arel.quoted(o.time_zone), collector end collector << COMMA collector = visit Arel.quoted(fmt), collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_FormattedNumber(o, collector) ⇒ Object
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 633 def visit_ArelExtensions_Nodes_FormattedNumber o, collector col = o.left.coalesce(0) comma = NUMBER_COMMA_MAPPING[o.locale] || '.,' comma_in_format = o.precision == 0 ? '' : 'D' nines_after = (1..o.precision - 1).map{'9'}.join('') + '0' if comma.length == 1 = Arel.quoted("NLS_NUMERIC_CHARACTERS = '#{comma} '") nines_before = ('999' * 4 + '990') else = Arel.quoted("NLS_NUMERIC_CHARACTERS = '#{comma}'") nines_before = ('999G' * 4 + '990') end sign = Arel.when(col < 0). then('-'). else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : '')) sign_length = o.flags.include?('+') || o.flags.include?(' ') ? Arel.quoted(1) : Arel.when(col < 0).then(1).else(0) if o.scientific_notation number = Arel::Nodes::NamedFunction.new('TO_CHAR', [ Arel.quoted(col.abs), Arel.quoted("FM#{nines_before}#{comma_in_format}#{nines_after}EEEE"), ]) if o.type == 'e' number = number.replace('E', 'e') end else number = Arel::Nodes::NamedFunction.new('TO_CHAR', [ Arel.quoted(col.abs), Arel.quoted("FM#{nines_before}#{comma_in_format}#{nines_after}"), ]) end repeated_char = if o.width == 0 Arel.quoted('') else Arel .when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0) .then(Arel.quoted( o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ') ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length)) ) .else('') end before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : '' middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : '' after = o.flags.include?('-') ? repeated_char : '' full_number = ArelExtensions::Nodes::Concat.new([ before, sign, middle, number, after ]) collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector collector end |
#visit_ArelExtensions_Nodes_GroupConcat(o, collector) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 134 def visit_ArelExtensions_Nodes_GroupConcat o, collector collector << '(LISTAGG(' collector = visit o.left, collector collector << COMMA collector = if o.separator && o.separator != 'NULL' visit o.separator, collector else visit Arel.quoted(','), collector end collector << ') WITHIN GROUP (ORDER BY ' if !o.order.blank? o.order.each_with_index do |order, i| collector << COMMA if i != 0 collector = visit order, collector end else collector = visit o.left, collector end collector << '))' collector end |
#visit_ArelExtensions_Nodes_IDoesNotMatch(o, collector) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 96 def visit_ArelExtensions_Nodes_IDoesNotMatch o, collector collector << 'LOWER(' collector = visit o.left, collector collector << ') NOT LIKE LOWER(' collector = visit o.right, collector collector << ')' if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_IMatches(o, collector) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 46 def visit_ArelExtensions_Nodes_IMatches o, collector collector << 'LOWER(' collector = visit o.left, collector collector << ') LIKE LOWER(' collector = visit o.right, collector collector << ')' if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_IsNotNull(o, collector) ⇒ Object
329 330 331 332 333 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 329 def visit_ArelExtensions_Nodes_IsNotNull o, collector collector = visit o.expr, collector collector << ' IS NOT NULL' collector end |
#visit_ArelExtensions_Nodes_IsNull(o, collector) ⇒ Object
323 324 325 326 327 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 323 def visit_ArelExtensions_Nodes_IsNull o, collector collector = visit o.expr, collector collector << ' IS NULL' collector end |
#visit_ArelExtensions_Nodes_Length(o, collector) ⇒ Object
316 317 318 319 320 321 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 316 def visit_ArelExtensions_Nodes_Length o, collector collector << "LENGTH#{o.bytewise ? 'B' : ''}(" collector = visit o.expr, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_LevenshteinDistance(o, collector) ⇒ Object
709 710 711 712 713 714 715 716 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 709 def visit_ArelExtensions_Nodes_LevenshteinDistance o, collector collector << 'UTL_MATCH.edit_distance(' collector = visit o.left, collector collector << Arel::Visitors::ToSql::COMMA collector = visit o.right, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Locate(o, collector) ⇒ Object
364 365 366 367 368 369 370 371 372 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 364 def visit_ArelExtensions_Nodes_Locate o, collector collector << 'INSTR(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Log10(o, collector) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 16 def visit_ArelExtensions_Nodes_Log10 o, collector collector << 'LOG(' o.expressions.each_with_index { |arg, i| collector << Arel::Visitors::ToSql::COMMA if i != 0 collector = visit arg, collector } collector << ',10)' collector end |
#visit_ArelExtensions_Nodes_Ltrim(o, collector) ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 410 def visit_ArelExtensions_Nodes_Ltrim o, collector collector << 'TRIM(LEADING ' if o.right.expr && SPECIAL_CHARS[o.right.expr] collector << SPECIAL_CHARS[o.right.expr] else collector = visit o.right, collector end collector << ' FROM ' collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_MD5(o, collector) ⇒ Object
177 178 179 180 181 182 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 177 def visit_ArelExtensions_Nodes_MD5 o, collector collector << 'LOWER (RAWTOHEX (DBMS_OBFUSCATION_TOOLKIT.md5(input => UTL_I18N.STRING_TO_RAW(' collector = visit o.left, collector collector << ", 'AL32UTF8'))))" collector end |
#visit_ArelExtensions_Nodes_NotBlank(o, collector) ⇒ Object
440 441 442 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 440 def visit_ArelExtensions_Nodes_NotBlank o, collector visit o.expr.trim.length.coalesce(0).gt(0), collector end |
#visit_ArelExtensions_Nodes_Power(o, collector) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 26 def visit_ArelExtensions_Nodes_Power o, collector collector << 'POWER(' o.expressions.each_with_index { |arg, i| collector << Arel::Visitors::ToSql::COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Rand(o, collector) ⇒ Object
335 336 337 338 339 340 341 342 343 344 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 335 def visit_ArelExtensions_Nodes_Rand o, collector collector << 'DBMS_RANDOM.VALUE(' if o.left && o.right collector = visit o.left, collector collector << COMMA collector = visit o.right, collector end collector << ')' collector end |
#visit_ArelExtensions_Nodes_Repeat(o, collector) ⇒ Object
479 480 481 482 483 484 485 486 487 488 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 479 def visit_ArelExtensions_Nodes_Repeat o, collector collector << 'LPAD(' collector = visit o.expressions[0], collector # can't put empty string, otherwise it wouldn't work collector << Arel::Visitors::ToSql::COMMA collector = visit o.expressions[1], collector collector << Arel::Visitors::ToSql::COMMA collector = visit o.expressions[0], collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Rtrim(o, collector) ⇒ Object
423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 423 def visit_ArelExtensions_Nodes_Rtrim o, collector collector << 'TRIM(TRAILING ' if o.right.expr && SPECIAL_CHARS[o.right.expr] collector << SPECIAL_CHARS[o.right.expr] else collector = visit o.right, collector end collector << ' FROM ' collector = visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_SMatches(o, collector) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 84 def visit_ArelExtensions_Nodes_SMatches o, collector collector = visit o.left, collector collector << ' LIKE ' collector = visit o.right, collector if o.escape collector << ' ESCAPE ' visit o.escape, collector else collector end end |
#visit_ArelExtensions_Nodes_Std(o, collector) ⇒ Object
695 696 697 698 699 700 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 695 def visit_ArelExtensions_Nodes_Std o, collector collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(') visit o.left, collector collector << ')' collector end |
#visit_ArelExtensions_Nodes_Substring(o, collector) ⇒ Object
374 375 376 377 378 379 380 381 382 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 374 def visit_ArelExtensions_Nodes_Substring o, collector collector << 'SUBSTR(' o.expressions.each_with_index { |arg, i| collector << COMMA if i != 0 collector = visit arg, collector } collector << ')' collector end |
#visit_ArelExtensions_Nodes_Trim(o, collector) ⇒ Object
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 384 def visit_ArelExtensions_Nodes_Trim o, collector collector << 'TRIM(' # BOTH if o.right.expr && SPECIAL_CHARS[o.right.expr] collector << SPECIAL_CHARS[o.right.expr] else collector = visit o.right, collector end collector << ' FROM ' collector << '(' if o.left.is_a? ArelExtensions::Nodes::Trim if o.type_of_attribute(o.left) == :text collector << 'dbms_lob.SUBSTR(' collector = visit o.left, collector collector << COMMA collector << 'COALESCE(dbms_lob.GETLENGTH(' collector = visit o.left, collector collector << '), 0)' collector << COMMA collector << '1)' else collector = visit o.left, collector end collector << ')' if o.left.is_a? ArelExtensions::Nodes::Trim collector << ')' collector end |
#visit_ArelExtensions_Nodes_Variance(o, collector) ⇒ Object
702 703 704 705 706 707 |
# File 'lib/arel_extensions/visitors/oracle.rb', line 702 def visit_ArelExtensions_Nodes_Variance o, collector collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(') visit o.left, collector collector << ')' collector end |