-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[FIX] OWSql does not save selected table/query #2659
Merged
+54
−31
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6037f9e
Update owsql.py
ceprio 8ae9a1a
Changed file according to reviewer comments and bug fix for SQL Serve…
ceprio a1e6411
Correction following comments from Travis CI
ceprio 8ba7584
Cosmetic changes following reviewer's comment
ceprio 34433be
Removed white space
ceprio f791857
Code change to allow exact count be made by the callee.
ceprio 6e702a0
Removed spaces at end of lines
ceprio 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 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 |
---|---|---|
|
@@ -117,17 +117,26 @@ def _guess_variable(self, field_name, field_metadata, inspect_table): | |
EST_ROWS_RE = re.compile(r'StatementEstRows="(\d+)"') | ||
|
||
def count_approx(self, query): | ||
try: | ||
with self.connection.cursor() as cur: | ||
with self.connection.cursor() as cur: | ||
try: | ||
cur.execute("SET SHOWPLAN_XML ON") | ||
try: | ||
cur.execute(query) | ||
result = cur.fetchone() | ||
return int(self.EST_ROWS_RE.search(result[0]).group(1)) | ||
except AttributeError: | ||
# This is to catch a float received in StatementEstRows | ||
# a float is received when the server's statistics are out of date. | ||
pass | ||
finally: | ||
cur.execute("SET SHOWPLAN_XML OFF") | ||
except pymssql.Error as ex: | ||
if "SHOWPLAN permission denied" in str(ex): | ||
warnings.warn("SHOWPLAN permission denied, count approximates will not be used") | ||
return None | ||
raise BackendError(str(ex)) from ex | ||
except pymssql.Error as ex: | ||
if "SHOWPLAN permission denied" in str(ex): | ||
warnings.warn("SHOWPLAN permission denied, count approximates will not be used") | ||
return None | ||
raise BackendError(str(ex)) from ex | ||
# In case of an AttributeError, give a second chance: | ||
# Use the long method for counting | ||
cur.execute("SELECT count(*) FROM ( {} ) x".format(query)) | ||
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. This should not be necessary. When count_approx returns None, an exact count is already performed (see SqlTable.count_approx) |
||
result = cur.fetchone() | ||
return result[0] |
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
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 have read your comment and I agree, if the float is a result of a reallly bad estimate, it should not be used. I still do not like the flow of this function though. I would put it like this: