aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/arel
Commit message (Collapse)AuthorAgeFilesLines
* fix a typoyamato-payforward2019-07-311-1/+1
|
* Enabled matches_regex for MySqlJames Pearson2019-07-291-0/+46
| | | | | | | | | | | | | Previously matches_regex was only availble on PostgreSql, this will enable it for MySql Usage example: users = User.arel_table; users = User.arel_table; User.where(users[:email].matches_regexp('(.*)\@gmail.com')) Update activerecord/test/cases/arel/visitors/mysql_test.rb Co-Authored-By: Ryuta Kamizono <kamipo@gmail.com>
* Use match? where we don't need MatchDataAkira Matsuda2019-07-291-1/+1
|
* Merge pull request #36492 from kamipo/remove_depth_first_visitorRyuta Kamizono2019-07-254-306/+7
|\ | | | | Remove unused `DepthFirst` visitor
| * Remove unused `DepthFirst` visitorRyuta Kamizono2019-06-154-306/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | We only use `ToSQL` visitors in the our codebase, do not use `DepthFirst` and `Dot` visitors. The `DepthFirst` visitor (which was introduced at c86c37e5f) is used to traverse an Arel (partial) ast with depth first. Is there any worth to keep that undocumented feature with much code and test cases. This removes that unused `DepthFirst` code and test cases.
* | Support beginless ranges in hash conditions.Josh Goodall2019-07-171-0/+24
| | | | | | | | | | | | | | | | | | Ruby 2.7 introduces beginless ranges (..value and ...value) and as with endless ranges we can turn these into inequalities, enabling expressions such as Order.where(created_at: ..1.year.ago) User.where(karma: ...0)
* | Remove unused `Arel::Attributes.for`Ryuta Kamizono2019-06-151-41/+0
|/ | | | `Arel::Attributes.for` is no longer used since https://github.com/rails/arel/pull/196.
* Fix sliced IN clauses to be groupedRyuta Kamizono2019-04-244-42/+14
| | | | | | | Follow up of #35838. And also this refactors `in_clause_length` handling is entirely integrated in Arel visitor.
* Address `ORA-01795: maximum number of expressions in a list is 1000`Yasuo Honda2019-04-112-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * To address this error, this commit splits expressions by slices of 1000 elements. * "Oracle Database Error Messages 18c" https://docs.oracle.com/en/database/oracle/oracle-database/18/errmg/ ``` ORA-01795: maximum number of expressions in a list is 1000 Cause: Number of expressions in the query exceeded than 1000. Note that unused column/expressions are also counted Maximum number of expressions that are allowed are 1000. ``` * This commit addresses this ORA-01795 error Note: Actually addressing this error raises another "ORA-00913: too many values" Number of values Oracle database allows is 65535 regardless bind values or literal values. ```ruby $ ARCONN=oracle bin/test test/cases/bind_parameter_test.rb -n test_too_many_binds ... snip ... Error: ActiveRecord::BindParameterTest#test_too_many_binds: ActiveRecord::StatementInvalid: OCIError: ORA-01795: maximum number of expressions in a list is 1000 stmt.c:267:in oci8lib_260.so /home/yahonda/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/ruby-oci8-2.2.7/lib/oci8/cursor.rb:131:in `exec' /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb:142:in `exec' /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb:41:in `block in exec_query' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:676:in `block (2 levels) in log' /home/yahonda/.rbenv/versions/2.6.2/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:675:in `block in log' /home/yahonda/git/rails/activesupport/lib/active_support/notifications/instrumenter.rb:24:in `instrument' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:666:in `log' /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb:36:in `log' /home/yahonda/git/oracle-enhanced/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb:24:in `exec_query' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:484:in `select' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:70:in `select_all' /home/yahonda/git/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:106:in `select_all' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:299:in `block in execute_simple_calculation' /home/yahonda/git/rails/activerecord/lib/active_record/relation.rb:755:in `skip_query_cache_if_necessary' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:299:in `execute_simple_calculation' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:251:in `perform_calculation' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:141:in `calculate' /home/yahonda/git/rails/activerecord/lib/active_record/relation/calculations.rb:49:in `count' /home/yahonda/git/rails/activerecord/test/cases/bind_parameter_test.rb:113:in `test_too_many_binds' bin/test test/cases/bind_parameter_test.rb:109 .............................F ```
* Revert unused code and re-using query annotation for `update_all` and ↵Ryuta Kamizono2019-04-015-66/+0
| | | | | | | | | | | | | | | | `delete_all` This partly reverts #35617. #35617 includes unused code (for `InsertStatement`) and re-using query annotation for `update_all` and `delete_all`, which has not been discussed yet. If a relation has any annotation, I think it is mostly for SELECT query, so re-using annotation by default is not always desired behavior for me. We should discuss about desired behavior before publishing the implementation.
* Add Relation#annotate for SQL commentingMatt Yoho2019-03-2110-0/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch has two main portions: 1. Add SQL comment support to Arel via Arel::Nodes::Comment. 2. Implement a Relation#annotate method on top of that. == Adding SQL comment support Adds a new Arel::Nodes::Comment node that represents an optional SQL comment and teachers the relevant visitors how to handle it. Comment nodes may be added to the basic CRUD statement nodes and set through any of the four (Select|Insert|Update|Delete)Manager objects. For example: manager = Arel::UpdateManager.new manager.table table manager.comment("annotation") manager.to_sql # UPDATE "users" /* annotation */ This new node type will be used by ActiveRecord::Relation to enable query annotation via SQL comments. == Implementing the Relation#annotate method Implements `ActiveRecord::Relation#annotate`, which accepts a comment string that will be appeneded to any queries generated by the relation. Some examples: relation = Post.where(id: 123).annotate("metadata string") relation.first # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 # LIMIT 1 /* metadata string */ class Tag < ActiveRecord::Base scope :foo_annotated, -> { annotate("foo") } end Tag.foo_annotated.annotate("bar").first # SELECT "tags".* FROM "tags" LIMIT 1 /* foo */ /* bar */ Also wires up the plumbing so this works with `#update_all` and `#delete_all` as well. This feature is useful for instrumentation and general analysis of queries generated at runtime.
* Get rid of `Arel::Nodes::Values`Ryuta Kamizono2019-03-184-14/+13
| | | | | | That is completely covered by `Arel::Nodes::ValuesList`. Related https://github.com/rails/arel/pull/484.
* Make `And` and `Case` into expression nodesKevin Deisz2019-01-241-0/+9
| | | | Allows aliasing, predications, ordering, and various other functions on `And` and `Case` nodes. This brings them in line with other nodes like `Binary` and `Unary`.
* Alias case nodesKevin Deisz2019-01-211-0/+10
| | | | When `Arel` was merged into `ActiveRecord` we lost the ability to alias case nodes. This adds it back.
* More exercise test cases for `not_between`Ryuta Kamizono2019-01-121-29/+82
| | | | | | And support endless ranges for `not_between` like as `between`. Follow up #34906.
* Support endless ranges in whereGreg Navis2019-01-111-0/+12
| | | | | | This commit adds support for endless ranges, e.g. (1..), that were added in Ruby 2.6. They're functionally equivalent to explicitly specifying Float::INFINITY as the end of the range.
* Arel: Implemented DB-aware NULL-safe comparison (#34451)Dmytro Shteflyuk2018-11-159-1/+354
| | | | | | | | | * Arel: Implemented DB-aware NULL-safe comparison * Fixed where clause inversion for NULL-safe comparison * Renaming "null_safe_eq" to "is_not_distinct_from", "null_safe_not_eq" to "is_distinct_from" [Dmytro Shteflyuk + Rafael Mendonça França]
* Emit single pair of parens for UNION and UNION ALLKeenan Brock2018-11-132-10/+22
| | | | | | | | mysql has a great implementation to suppress multiple parens for union sql statements. This moves that functionality to the generic implementation This also introduces that functionality for UNION ALL
* Handle DELETE with LIMIT in ArelRyuta Kamizono2018-09-301-0/+1
| | | | | | | | | | | | | | | | | | MySQL supports DELETE with LIMIT and ORDER BY. https://dev.mysql.com/doc/refman/8.0/en/delete.html Before: ``` Post Destroy (1.0ms) DELETE FROM `posts` WHERE `posts`.`id` IN (SELECT `id` FROM (SELECT `posts`.`id` FROM `posts` WHERE `posts`.`author_id` = ? ORDER BY `posts`.`id` ASC LIMIT ?) __active_record_temp) [["author_id", 1], ["LIMIT", 1]] ``` After: ``` Post Destroy (0.4ms) DELETE FROM `posts` WHERE `posts`.`author_id` = ? ORDER BY `posts`.`id` ASC LIMIT ? [["author_id", 1], ["LIMIT", 1]] ```
* `SQLString#compile` is no longer used since ↵Ryuta Kamizono2018-09-301-11/+5
| | | | 53521a9e39b9d8af4165d7703c36dc905f1f8f67
* Remove `visit_Fixnum` and `visit_Bignum`Ryuta Kamizono2018-09-301-1/+1
| | | | Follow up ae406cd633dab2cafbc0d1bb5922d1ca40056ea0.
* Abandon TOP support.Vladimir Kochnev2018-09-253-4/+2
| | | | | | | | | | | | | | | | Initially, `TOP` was introduced to support `limit` for MSSQL database. Unlike PostgreSQL/MySQL/SQLite, MSSQL does not have native `LIMIT`/`OFFSET` support. The commit adding `TOP` is 1a246f71616cf246a75ef6cbdb56032e43d4e643. However, it figured out that `TOP` implementation was weak and it's not sufficient to also support `OFFSET`, then `TOP` was substituted with `ROW_NUMBER()` subquery in be48ed3071fd6524d0145c4ad3faeb4aafe3eda3. This is a well known trick in MSSQL - https://stackoverflow.com/questions/2135418/equivalent-of-limit-and-offset-for-sql-server. So now we don't need this `visit_Arel_Nodes_Top` at all. It does nothing useful but also adds an extra space after `SELECT` when `LIMIT` is being used for **any** database.
* Fix a wrong correctionKazuhiro Sera2018-08-081-1/+1
|
* Fix the obvious typos detected by github.com/client9/misspellKazuhiro Sera2018-08-084-15/+15
|
* Enable `Layout/EmptyLinesAroundBlockBody` to reduce review cost in the futureRyuta Kamizono2018-07-122-13/+0
| | | | | | | We sometimes ask "✂️ extra blank lines" to a contributor in reviews like https://github.com/rails/rails/pull/33337#discussion_r201509738. It is preferable to deal automatically without depending on manpower.
* Fix: Arel Postgresql visitor generates invalid SQL for GROUPING SETS.david2018-05-281-3/+3
|
* Enable `Lint/StringConversionInInterpolation` rubocop ruleRyuta Kamizono2018-05-211-2/+2
| | | | | To prevent redundant `to_s` like https://github.com/rails/rails/pull/32923#discussion_r189460008 automatically in the future.
* Add math testsNikolai B2018-05-142-9/+83
| | | | | | After #449 was merged math can be done on these nodes, adding a test file to unit test all the math operators.
* Remove unused `assert_like` from `Arel::Test`Yasuo Honda2018-05-021-5/+0
| | | | | It had been added at https://github.com/rails/arel/commit/05b5bb12270b32e094c1c879273e0978dabe5b3b and removed at https://github.com/rails/arel/commit/db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0
* Remove unnecessary requireyuuji.yaginuma2018-05-021-1/+0
| | | | `require 'rubygems'` is already required in Ruby 1.9 or later.
* `require "active_support/test_case"` is not supported since 53e877f7Ryuta Kamizono2018-05-021-1/+1
| | | | | | | It will cause "undefined method `test_order' for ActiveSupport:Module (NoMethodError)". https://travis-ci.org/rails/rails/jobs/373472604#L1208
* Make `Arel::Test` subclass of `ActiveSupport::TestCase`Yasuo Honda2018-05-018-73/+84
| | | | | | | | | | not `Minitest::Test` to address `CustomCops/RefuteNot` and `CustomCops/AssertNot` offenses for Arel test cases Also including `ActiveSupport::Testing::Assertions` to `Arel::Spec` and add test/unit backwards compatibility methods Fixes #32720
* Address `NameError: uninitialized constant Arel::Collectors::Bind`Yasuo Honda2018-04-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | when tested with Ruby 2.5 or higher ```ruby $ ruby -v ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] $ bundle exec ruby -w -Itest test/cases/arel/collectors/bind_test.rb -n test_compile_gathers_all_bind_params Run options: -n test_compile_gathers_all_bind_params --seed 24420 E Error: Arel::Collectors::TestBind#test_compile_gathers_all_bind_params: NameError: uninitialized constant Arel::Collectors::Bind Did you mean? Binding test/cases/arel/collectors/bind_test.rb:15:in `collect' test/cases/arel/collectors/bind_test.rb:19:in `compile' test/cases/arel/collectors/bind_test.rb:31:in `test_compile_gathers_all_bind_params' bin/rails test test/cases/arel/collectors/bind_test.rb:30 Finished in 0.002343s, 426.8559 runs/s, 0.0000 assertions/s. 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips $ ``` It is likely due to Ruby 2.5 does not look up top level constant. https://www.ruby-lang.org/en/news/2017/12/25/ruby-2-5-0-released/ "Top-level constant look-up is no longer available."
* Arel: rubocop -aMatthew Draper2018-02-2460-1218/+1263
|
* Merge Arel into Active RecordMatthew Draper2018-02-2460-0/+6722