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