| 43 | |
| 44 | template <typename Function> |
| 45 | inline SQLRETURN Execute(SQLRETURN rc, Function function) { |
| 46 | try { |
| 47 | GetDiagnostics().Clear(); |
| 48 | rc = function(); |
| 49 | } catch (const arrow::flight::sql::odbc::AuthenticationException& ex) { |
| 50 | GetDiagnostics().AddError(arrow::flight::sql::odbc::DriverException( |
| 51 | ex.GetMessageText(), ex.GetSqlState(), ex.GetNativeError())); |
| 52 | } catch (const arrow::flight::sql::odbc::NullWithoutIndicatorException& ex) { |
| 53 | GetDiagnostics().AddError(arrow::flight::sql::odbc::DriverException( |
| 54 | ex.GetMessageText(), ex.GetSqlState(), ex.GetNativeError())); |
| 55 | } |
| 56 | // on mac, DriverException doesn't catch the subclass exceptions hence we added |
| 57 | // the following above. |
| 58 | // GH-48278 TODO investigate if there is a way to catch all the subclass exceptions |
| 59 | // under DriverException |
| 60 | catch (const arrow::flight::sql::odbc::DriverException& ex) { |
| 61 | GetDiagnostics().AddError(ex); |
| 62 | } catch (const std::bad_alloc&) { |
| 63 | GetDiagnostics().AddError(arrow::flight::sql::odbc::DriverException( |
| 64 | "A memory allocation error occurred.", "HY001")); |
| 65 | } catch (const std::exception& ex) { |
| 66 | GetDiagnostics().AddError(arrow::flight::sql::odbc::DriverException(ex.what())); |
| 67 | } catch (...) { |
| 68 | GetDiagnostics().AddError( |
| 69 | arrow::flight::sql::odbc::DriverException("An unknown error occurred.")); |
| 70 | } |
| 71 | |
| 72 | if (GetDiagnostics().HasError()) { |
| 73 | return SQL_ERROR; |
| 74 | } |
| 75 | if (SQL_SUCCEEDED(rc) && GetDiagnostics().HasWarning()) { |
| 76 | return SQL_SUCCESS_WITH_INFO; |
| 77 | } |
| 78 | return rc; |
| 79 | } |
| 80 | |
| 81 | template <typename Function> |
| 82 | inline SQLRETURN ExecuteWithLock(SQLRETURN rc, Function function) { |
no test coverage detected