-
Notifications
You must be signed in to change notification settings - Fork 6
SQL Functions for Fields #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,6 +142,8 @@ def _attrpath(self, attrname): | |
| """ | ||
| rclass = self.entity | ||
| pattr = "" | ||
| if attrname.endswith(')'): | ||
| attrname = (attrname.split("("))[1].split(")")[0] | ||
| for attr in attrname.split('.'): | ||
| if pattr: | ||
| pattr += ".%s" % attr | ||
|
|
@@ -169,6 +171,8 @@ def _makesubst(self, objs): | |
| i = obj.rfind('.') | ||
| if i < 0: | ||
| continue | ||
| if obj.endswith(')'): | ||
| obj = (obj.split("("))[1].split(")")[0] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment as above: |
||
| obj = obj[:i] | ||
| for (o, attrInfo, oclass) in self._attrpath(obj): | ||
| if o not in subst: | ||
|
|
@@ -373,7 +377,10 @@ def addConditions(self, conditions): | |
| """ | ||
| if conditions: | ||
| for a in conditions.keys(): | ||
| for (pattr, attrInfo, rclass) in self._attrpath(a): | ||
| a_name = a | ||
| if a.endswith(')'): | ||
| a_name = (a.split("("))[1].split(")")[0] | ||
| for (pattr, attrInfo, rclass) in self._attrpath(a_name): | ||
| pass | ||
| if a in self.conditions: | ||
| conds = [] | ||
|
|
@@ -468,7 +475,13 @@ def __str__(self): | |
| if self.conditions: | ||
| conds = [] | ||
| for a in sorted(self.conditions.keys()): | ||
| attr = self._dosubst(a, subst, False) | ||
| a_name = a | ||
| if a.endswith(')'): | ||
| sql_function_name = a.split("(")[0] | ||
| a_name = (a.split("("))[1].split(")")[0] | ||
| attr = self._dosubst(a_name, subst, False) | ||
| if "sql_function_name" in locals(): | ||
| attr = f"{sql_function_name}({attr})" | ||
| cond = self.conditions[a] | ||
| if isinstance(cond, str): | ||
| conds.append("%s %s" % (attr, cond)) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the proper place to deal with that.
_attrpath()is a low level helper with a well defined scope: to check an attribute name, iterating over the components of the dotted path to related objects as needed. It should not deal with higher level issues such as whether that attribute is used inside an SQL function. It is called from many places, not in all of them an SQL function would make sense.Also, I'm not sure about the way how the attribute name and SQL function is parsed here.