| 313 | } |
| 314 | |
| 315 | SQLRETURN SQLGetDiagField(SQLSMALLINT handle_type, SQLHANDLE handle, |
| 316 | SQLSMALLINT rec_number, SQLSMALLINT diag_identifier, |
| 317 | SQLPOINTER diag_info_ptr, SQLSMALLINT buffer_length, |
| 318 | SQLSMALLINT* string_length_ptr) { |
| 319 | // GH-46573 TODO: Implement additional fields types |
| 320 | ARROW_LOG(DEBUG) << "SQLGetDiagFieldW called with handle_type: " << handle_type |
| 321 | << ", handle: " << handle << ", rec_number: " << rec_number |
| 322 | << ", diag_identifier: " << diag_identifier |
| 323 | << ", diag_info_ptr: " << diag_info_ptr |
| 324 | << ", buffer_length: " << buffer_length << ", string_length_ptr: " |
| 325 | << static_cast<const void*>(string_length_ptr); |
| 326 | using ODBC::GetStringAttribute; |
| 327 | using ODBC::ODBCConnection; |
| 328 | using ODBC::ODBCDescriptor; |
| 329 | using ODBC::ODBCEnvironment; |
| 330 | using ODBC::ODBCStatement; |
| 331 | |
| 332 | if (!handle) { |
| 333 | return SQL_INVALID_HANDLE; |
| 334 | } |
| 335 | |
| 336 | if (!diag_info_ptr && !string_length_ptr) { |
| 337 | return SQL_ERROR; |
| 338 | } |
| 339 | |
| 340 | // If buffer length derived from null terminated string |
| 341 | if (diag_info_ptr && buffer_length == SQL_NTS) { |
| 342 | const wchar_t* str = reinterpret_cast<wchar_t*>(diag_info_ptr); |
| 343 | buffer_length = wcslen(str) * GetSqlWCharSize(); |
| 344 | } |
| 345 | |
| 346 | // Set character type to be Unicode by default |
| 347 | const bool is_unicode = true; |
| 348 | Diagnostics* diagnostics = nullptr; |
| 349 | |
| 350 | switch (handle_type) { |
| 351 | case SQL_HANDLE_ENV: { |
| 352 | ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(handle); |
| 353 | diagnostics = &environment->GetDiagnostics(); |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | case SQL_HANDLE_DBC: { |
| 358 | ODBCConnection* connection = reinterpret_cast<ODBCConnection*>(handle); |
| 359 | diagnostics = &connection->GetDiagnostics(); |
| 360 | break; |
| 361 | } |
| 362 | |
| 363 | case SQL_HANDLE_DESC: { |
| 364 | ODBCDescriptor* descriptor = reinterpret_cast<ODBCDescriptor*>(handle); |
| 365 | diagnostics = &descriptor->GetDiagnostics(); |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | case SQL_HANDLE_STMT: { |
| 370 | ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(handle); |
| 371 | diagnostics = &statement->GetDiagnostics(); |
| 372 | break; |