-
Notifications
You must be signed in to change notification settings - Fork 80
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
Standardize get_info() return types #398
base: main
Are you sure you want to change the base?
Conversation
Use the official types, as in the docs. See https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetinfo-function?view=sql-server-ver16 > InfoValuePtr > [Output] Pointer to a buffer in which to return the information. > Depending on the InfoType requested, the information returned will > be one of the following: a null-terminated character string, an > SQLUSMALLINT value, an SQLUINTEGER bitmask, an SQLUINTEGER flag, > a SQLUINTEGER binary value, or a SQLULEN value. It seems better to use these types instead of matching them to the C data types, which can be platform dependent. For example SQLUINTEGER is currently different on Linux and Windows. Specifying the wrong type can cause undefined behavior and crashes, see e.g. r-dbi/odbc#677
a6d480d
to
b76add6
Compare
Hi @gaborcsardi Thank you for your PR. Although it is technically valid, I don't want to merge it before having a brief discussion about the issue from nanodbc perspective. One of the aims of nanodbc is to let its users interact with databases using C++ native types only. It means, it avoids uses of ODBC types in its public interface. It also tries to avoid use of platform-dependant types like So, instead of exposing the ODBC types to fix your problem, can we correct nanodbc to avoid uses of We could release the types clean up as 2.15 @lexicalunit Please, share your thoughts on that. |
I think that is reasonable, but it comes with a drawback. The current principle means that it is not trivial to write cross-platform code using nanodbc, because e.g. But I understand that this PR is a radical deviation from your rule. Maybe you could internally convert betweeen the standard integer type and the SQL types. So your API would stay the same, but internally you'd call the ODBC functions with the standard SQL types. I can try to modify this PR if you think that this is a good idea. |
I think you've nailed there both, the problem and the solution. The nanodbc as a wrapper - facade pattern - which goal is to hide complexity of the underlaying system and free users from having to make those decisions. Let's first try solve it as you suggest, moving the mapping into the nanodbc internal details and resort to the modification of the public interface only if it turns impossible to figure mapping for all possible platform variants. |
What does this PR do?
Use the official return types in
get_info()
, as in the docs. Seehttps://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetinfo-function?view=sql-server-ver16
It seems better to use these types instead of matching them to the C data types, which can be platform dependent. For example SQLUINTEGER is currently different on Linux and Windows. Specifying the wrong type can cause undefined behavior and crashes, see e.g. r-dbi/odbc#677
What are related issues/pull requests?
None.
Tasklist
Environment
Provide environment details, if relevant: