-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle arrays of two element arrays as filter hash values automatically
Previously, Sequel's behavior of arrays of two element arrays as hash values was suboptimal (some would say broken). Because the values were an array, an IN operator was used, but because arrays of two element arrays are considered condition specifiers, the argument was converted to a boolean condition: DB[:a].filter([:a, :b]=>[[1, 2], [3, 4]]) # SELECT * FROM a WHERE ((a, b) IN ((1 = 2) AND (3 = 4))) This changes the behavior so that you now get the SQL you expect: SELECT * FROM a WHERE ((a, b) IN ((1, 2), (3, 4))) Previously, you had to call sql_array (which was added in Sequel 2.7.0) on the array to get the correct SQL, but that is no longer necessary when the array is a filter hash value. However, it is still necessary to use a method that wraps the array to two element arrays if you are going to use it as a placeholder value: DB[:a].filter('(a, b) IN ?', [[1, 2], [3, 4]]) This is because Sequel doesn't have the context to know that the array of two element arrays is being used as a an IN predicate (as Sequel does not parse SQL). This actually started when I decided that SQLArray was a bad name for the class, since arrays in standard SQL (starting with SQL99) are very different that what SQLArray actually represented, which was an IN predicate value list. To that end, SQLArray has been renamed to ValueList, though SQLArray still exists as an alias. Likewise Array#sql_value_list has been added, though Array#sql_array still exists as an alias to it. However, in most cases, the methods are no longer necessary, and Sequel internally no longer uses ValueList, as the only time it wants to deal with arrays of two element arrays as value lists, it uses them as hash values, which Sequel can now handle automatically. Another main difference is that ValueList now inherits from ::Array, not from Expression. This simplified some code, and since you can't really perform any operations on an SQL value list by itself (until it is used as part of an IN expression), there's no reason it needs to be an Expression subclass. While here, fix a minor bug in Expression#inspect.
- Loading branch information
1 parent
b7c3059
commit 65abb56
Showing
11 changed files
with
66 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters