Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The current SelectQuery class only supports AND operator when creating the query string. Would be good to also allow the OR operator and it is also a very easy way to accomplish this.
Comment | File | Size | Author |
---|---|---|---|
#15 | select-interface.patch | 2.1 KB | cwcorrigan |
#2 | 2879844-2.patch | 642 bytes | jzavrl |
Comments
Comment #2
jzavrl CreditAttribution: jzavrl at NDP commentedAttached patch.
Comment #3
AaronBaumanThis can be accomplished by adding conditions to SelectQuery->conditions property directly.
For example:
Maybe all that's needed is better documentation for this kind of usage?
Also, if you're using Salesforce Pull, you can use the Pull query SOQL "Where" clause feature to inject any arbitrary SOQL where conditions you need to.
Comment #4
jzavrl CreditAttribution: jzavrl at NDP commentedOh... :)
Then it's a good thing the patch only consisted of 2 lines, so I didn't really spend too much time on this :)
But either way, I think that the SelectQuery definitely needs a better documentation on this. I've had no idea you could add a condition like that, since the method is described as
addCondition($field, $value, $operator = '=')
.Even so, the use of public properties is discouraged by Drupal's coding standards, and we should use public methods for setting/getting the property values.
But for now, I think a better documentation of the
SelectQuery
method would come a long way. I'll put this together. Also, I feel that the changes from the patch could stay. They give you the flexibility to use a different operator when adding conditions with theaddCondition()
method, and the property also has a default value, so it wouldn't be breaking backwards compatibility.Thoughts?
Comment #5
AaronBaumanI agree that the current "everything is public" isn't a great approach.
Are we headed towards creating a database abstraction layer here?
I couldn't find any robust PHP solutions, but this node module is headed in the right direction: https://github.com/jsforce/jsforce/blob/63c94d30cbdc314444f8f6f113674b89...
Anyway, more documentation on existing features would be great.
Comment #6
acrosmanD8 core's Database Select class allows pretty wide-open access, and awhile back I ran into frustration with the fact that SearchAPI's equivalent for Solr does not. Which means to modify views that have similar needs but could be a Solr search query or a database interface query you end up having to write the same alterations in two very different ways. Obviously that's a rare use case, but it would be nice if the patterns in this module matched something else in the code base both in terms of methods and data structures. Personally I'd mirror Select and justify any extra public variables by saying it's better to be consistent with core than architecturally perfect.
Comment #7
AaronBaumanYup. Would like to get this done for 8.x-4.x
Comment #8
AaronBaumanComment #9
AaronBaumanUpdated version to 8.x-4.x for API changes.
If there non-breaking changes, we can get those into 3.x, but assuming that there will be some major stuff that will need to go to 4.x
Comment #10
cwcorrigan CreditAttribution: cwcorrigan at Message Agency commentedComment #11
AaronBaumanHere's the complete set of methods and inherited methods from core's SelectInterface.
Let's start off by identifying which make sense for SOQL:
Comment #12
AaronBaumanComment #13
cwcorrigan CreditAttribution: cwcorrigan at Message Agency commentedI think most/all of these could do something to translate to an equivalent but not all of them have a 'native' implementation in SOQL.
Comment #14
AaronBaumanA few more we may wish to reconsider:
addTag($tag);
hasTag($tag);
hasAllTags();
hasAnyTag();
addMetaData($key, $object);
getMetaData($key);
alwaysFalse
compile
compiled
preexecute
prepared
execute
join($table, $alias = NULL, $condition = NULL, $arguments = []);
innerJoin($table, $alias = NULL, $condition = NULL, $arguments = []);
leftJoin($table, $alias = NULL, $condition = NULL, $arguments = []);
rightJoin($table, $alias = NULL, $condition = NULL, $arguments = []);
addJoin($type, $table, $alias = NULL, $condition = NULL, $arguments = []);
arguments();
uniqueIdentifier();
nextPlaceholder();
I'm not sure how well subquery/parent query will adapt to the "join" API.
We might want to consider breaking compatibility there as well.
Tags, metadata, compile, prepare - these don't seem particularly useful.
Execute() is an interesting case, and got me thinking about how to refactor the whole framework to work more like the Database API...
Comment #15
cwcorrigan CreditAttribution: cwcorrigan at Message Agency commentedPotential Interface based on the first pass
Comment #16
cwcorrigan CreditAttribution: cwcorrigan at Message Agency commentedComment #17
AaronBaumanI may have gone a bit overboard with these changes, but they've gotten a bit too large to manage with the patch workflow.
I posted a PR at https://github.com/messageagency/sfd8/pull/9 for review
When we're happy with the scope, we can put a patch back up here to appease testbot.
Comment #19
AaronBaumanHere's what's included to mimic core, generally (not exhaustive):
- tables
- expressions
- conditions
though we're using conditions to collect our condition expressions, Drupal's compilation doesn't make sense for SOQL. So, there's a compilation step within the Select class itself. Not the most elegant. We may wish to consider a new Condition class specifically for SOQL.
- having
- order by
- limit
- offset
- group by
- subquery expressions
- subquery conditions
Here's what's excluded generally:
- aliases
aliases are supported for tables, so that's included. But only aggregate expressions support aliasing, so I've omitted explicit support for field aliasing. (And it seems like even aggregate experssion aliases are ignored in results anyway).
- arguments and placeholder substitution
Drupal's database layer relies on PHP PDO for placeholder and argument substitution, and no such analog exists to support Salesforce. In theory, we could rebuild such a feature for Salesforce, but I don't think that's in scope here. For now, we'll continue to rely on callers to properly escape, quote, parenthesize, etc.
- joins
Salesforce equivalents of joins may be achieved with subquery expressions.
- unions
- distinct
- tags
- metadata
- comments
And finally there are a number of SOQL specific features which I've not yet implemented, like FOR REFERENCE, TRACKING|VIEWSTAT, DATA CATEGORY, USING SCOPE. Patches to include these are welcome, but shouldn't block committing this changeset.
Comment #20
cwcorrigan CreditAttribution: cwcorrigan at Message Agency commentedComment #21
AaronBaumanI'm doing some cleanup on unsupported branches.
Please re-open this issue and update the version to 5.0.x-dev if this issue is still applicable to the latest release.