-
Notifications
You must be signed in to change notification settings - Fork 177
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
Add fallback to ConfigReader.get, **kwargs to connect_to_database, and pymssql support to call_stored_procedure #214
Conversation
…Manager Some database connection functions don't require all of dbapiModuleName, dbName, dbUsername... These functions also fail in some libraries if given a blank string on some libraries. By 'some libraries' here I mostly mean pymssql, but these changes should be invisible to any tests running with a fully db.cfg. Similarly, I passed **kwargs in from connect_to_database on connections to misc databases not in the existing if/elif cases. This was mostly to allow for passing in tds_version on pymssql (see this issue: pymssql/pymssql#860), but it would be useful for any misc database to be able to set up their connection using custom parameters. It may also be a good idea to pass kwargs in to each db_connection in that whole big if/else statement, but I wanted this to be minimally impactful to connection modules I don't know well enough to not break.
Similar support to existing call_stored_procedure functions, but pymssql annoyingly requires data types on its outputs, so the syntax has to be 'CURSOR_[TYPE]' instead of just CURSOR.
Hello @markus-leben, thanks a lot for your contribution!
Thank you! |
|
Hello Markus, sorry for the late reply. I've been working on the second part of your PR - regarding handling the OUT parameters when calling a procedure in MSSQL. I basically took your solution, but I had to change something. I also extended the documentation of the keyword 'Call Stored Procedure' - now it should explain in a better way the special cases with different databases. |
Regarding the first part of your PR (config files) - it's still in the ToDo list, but I'll check it out soon. |
Wrote a brief review and tested query.py locally. Looks like it works well, and it's compatible with the connection_manager changes I made same as my code was. I'm gonna leave this open for the config file stuff, but feel free to close when you get those to a state you're happy with. Also no worries on the delay, from the looks of things you were prepping to present at a con and that sounds like a LOT of hard work. |
@markus-leben I finally took a closer look at your "add fallback" changes and more generally at the way, how the library creates a DB connection with/without a config.file.
What do you think? |
There is, yeah. Using a trusted connection for MSSQL connects using your windows auth you're logged in on without another username or password. Like with this connection string for an mssql server:
And this db.cfg:
It's actually slightly fiddlier than that. In this case basic params must explicitly be unset. You can't have a dbUsername and dbPassword or it fails with this relatively opaque error:
So at least in this specific context defaulting to None is probably appropriate behavior, as you end up with this connection:
I think there's a middle ground here, like you were mentioning with port numbers. Assuming defaults appropriate to the defaults of different DB types seems helpful, and hopefully not very likely to change over time. It would probably be good to be as explicit as possible in the logger.info statements in ConnectionManager.connect_to_database about what the connection parameters are, both for passed in **kwargs and for any assumed defaults. I figure if you assume some defaults, but allow them to be overwritten and are explicit in docs, debug console logging, and error messaging, then the burden of having perfect defaults is lessened. If you say "Connect to Database uses these defaults" and then the debug console logs "Connecting using : this_db.connect(params)", and then an error throws "Connection failed, connection was this_db.connect(params), error message: foo" and someone ends up not understanding or frustrated with default values then they're probably in the wrong. This is a bit subjective though. Here's a doodle for what the error handling might look like:
Sorry for the somewhat unhinged fstring and dict comprehension for spreading arguments into the message. |
@markus-leben I've just created a PR #220 with custom connection parameters. Could you please have a look? |
Implemented in #220 |
Mostly exists to better support pymssql querying. Fixes this issue from pymssql in database library: pymssql/pymssql#860