Skip to content
This repository has been archived by the owner on Aug 25, 2018. It is now read-only.

Remove unused output connection string from SQLDriverConnect call #188

Merged
merged 1 commit into from Jun 20, 2016
Merged

Remove unused output connection string from SQLDriverConnect call #188

merged 1 commit into from Jun 20, 2016

Conversation

jon-v
Copy link

@jon-v jon-v commented Jun 20, 2016

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.

@mloskot
Copy link
Contributor

mloskot commented Jun 20, 2016

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
Copy link
Contributor

Choose a reason for hiding this comment

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

NULL should read nullptr

Copy link
Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, thanks.

@jon-v
Copy link
Author

jon-v commented Jun 20, 2016

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?

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.

@mloskot
Copy link
Contributor

mloskot commented Jun 20, 2016

@jon-v

(...) SQLDriverConnect call. When connecting asynchronously the function will return immediately (...)

I see. I don't have experience with async connections and I thought this particular call might actually be blocking.

@mloskot
Copy link
Contributor

mloskot commented Jun 20, 2016

One more thing, MSDN on SQLDriverConnect mentions OutConnectionString parameter can be NULL:

If OutConnectionString is NULL, StringLength2Ptr will still return the total number of characters (excluding the null-termination character for character data) available to return in the buffer pointed to by OutConnectionString.

But, it does not indicate NULL is allowed for StringLength2Ptr.
Is that an overlook in MSDN and can we be sure all drivers will accept NULL?

@jon-v
Copy link
Author

jon-v commented Jun 20, 2016

Is that an overlook in MSDN and can we be sure all drivers will accept NULL?

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.

@mloskot
Copy link
Contributor

mloskot commented Jun 20, 2016

Yes, that's fair comment.

Let's wait for @lexicalunit vote.

@lexicalunit
Copy link
Owner

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 NULL vs nullptr issue in this PR or a subsequent one.

@mloskot
Copy link
Contributor

mloskot commented Jun 20, 2016

Great, thanks @jon-v !

I wonder if we could add a CI build focused on testing the async stuff. Any guidelines would be helpful.

@mloskot mloskot merged commit 382a273 into lexicalunit:master Jun 20, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants