-
Notifications
You must be signed in to change notification settings - Fork 41
Remove unused output connection string from SQLDriverConnect call #188
Conversation
Although this change looks good to me for now, we may require the returned connection string in future features. So, it would be good to understand why it was causing crashes when connecting asynchronously. Any ideas? |
, dsn | ||
, sizeof(dsn) / sizeof(NANODBC_SQLCHAR) | ||
, &dsn_size | ||
, NULL |
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.
NULL
should read nullptr
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.
NULL should read nullptr
There's quite a few instances of NULL instead of nullptr across the codebase (probably most of them from me, sorry about that). Do you mind if I leave this as-is for now and correct them all in a separate PR?
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.
Sure, thanks.
It's quite straightforward - the pointer being passed is to a local variable which goes out of scope immediately following the SQLDriverConnect call. When connecting asynchronously the function will return immediately, but the ODBC driver will try to write to the address later, probably when SQLCompleteAsync is called. If we wanted to save the output connection string it would be as easy as keeping the buffer as a member variable in the connection_impl object instead. |
I see. I don't have experience with async connections and I thought this particular call might actually be blocking. |
One more thing, MSDN on SQLDriverConnect mentions
But, it does not indicate |
History has shown that we can't even be sure that Microsoft's own drivers match their documentation. All I know is it works on our end, and the CI tests still pass. |
Yes, that's fair comment. Let's wait for @lexicalunit vote. |
Yeah this is a good catch here. I've never been able to test with async myself so I never would have caught this problem. Thanks for the PR @jon-v! LGTM, we can either address the |
Great, thanks @jon-v ! I wonder if we could add a CI build focused on testing the async stuff. Any guidelines would be helpful. |
Passing the output connection string pointer to SQLDriverConnect was causing crashes when connecting asynchronously. Since this variable was entirely unused inside nanodbc, the quickest and best fix seemed to be to simply remove it.