Skip to content
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

close connection in case of DatabaseError #173

Merged
merged 1 commit into from
Apr 26, 2019
Merged

Conversation

madamow
Copy link
Collaborator

@madamow madamow commented Apr 24, 2019

Fixes #130
@mgckind PTAL
Code catches the cx_Oracle.Database error due to incorrect syntax in query and closes the connection instead of trying to cancel it.
Cancelling connection causes it to hang, closing it allows to go around it.

@mgckind
Copy link
Owner

mgckind commented Apr 25, 2019

😱, that was quick. Thanks, I'll take a look

print(colored('Your query raised DatabaseError:', "red", self.ct))
print(colored(str(exc), "red", self.ct))
self.con.close()
if self.loading_bar:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have it somewhere, but is the connection reopen after closing it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I checked the next step after closing/canceling connection is pinging the database to check the connection. If the ping comes back as False, the code will connect to database again. Try to run invalid query and then a valid one.

https://github.com/madamow/easyaccess/blob/318357fbb2f1a56819d16bdc59d1a6032fb30e0f/easyaccess/easyaccess.py#L438-L451

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see, yes, that's what i meant. great!

(type, value, traceback) = sys.exc_info()
self.con.cancel()
t2 = time.time()

(type, value, traceback) = sys.exc_info()
self.con.cancel()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't these lines duplicated? they don't show are being removed

print(colored('Your query raised DatabaseError:', "red", self.ct))
print(colored(str(exc), "red", self.ct))
self.con.close()
if self.loading_bar:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see, yes, that's what i meant. great!

@mgckind mgckind merged commit 74c11d8 into mgckind:master Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

easyaccess unresponsive after Oracle error
2 participants