Conversation
jduo
left a comment
There was a problem hiding this comment.
Will SQLGetDiagRec and SQLError be implemented in separate PRs? They are commonly used in applications.
| diagnostics = &connection->GetDiagnostics(); | ||
| break; | ||
| } | ||
|
|
There was a problem hiding this comment.
We can go ahead and add statement and descriptor cases now so we don't forget.
| // Retrieve record field data | ||
| switch (diagIdentifier) { | ||
| case SQL_DIAG_MESSAGE_TEXT: { | ||
| const std::string message = diagnostics->GetMessageText(recordIndex); |
There was a problem hiding this comment.
This can be a const std::string& right? That avoids a copy. Check throughout.
| } | ||
|
|
||
| case SQL_DIAG_SERVER_NAME: { | ||
| const std::string source = diagnostics->GetDataSourceComponent(); |
There was a problem hiding this comment.
This field is supposed to be the DSN if connecting via DSN (same as SQLGetInfo(DATA_SOURCE_NAME).
I do not remember if GetDataSourceComponent() returns the DSN, or if it returns the component name that is used for formatting the error message here: https://learn.microsoft.com/en-us/sql/odbc/reference/develop-app/diagnostic-messages?view=sql-server-ver16 . That's supposed to describe the internal component reporting the error.
| return SQL_INVALID_HANDLE; | ||
| } | ||
|
|
||
| if (!diagInfoPtr) { |
There was a problem hiding this comment.
It's legal to pass a NULL here if they just want the length. Same as for attributes.
| stringLengthPtr, *diagnostics); | ||
| } | ||
|
|
||
| default: |
There was a problem hiding this comment.
It might be a problem to throw an error for unrecognized, but standard diag types. (Like it breaks apps). Perhaps we just return dummy values for any valid, but not supported fields. For non-standard fields we can report error.
The spec says we should only return SQL_ERROR for when "The DiagIdentifier argument was not one of the valid values."
@jduo SQLError would be in milestone 3 |
Implementation of SQLGetDiagField.