| 137 | } |
| 138 | |
| 139 | SQLRETURN SQLFreeHandle(SQLSMALLINT type, SQLHANDLE handle) { |
| 140 | ARROW_LOG(DEBUG) << "SQLFreeHandle called with type: " << type |
| 141 | << ", handle: " << handle; |
| 142 | switch (type) { |
| 143 | case SQL_HANDLE_ENV: { |
| 144 | using ODBC::ODBCEnvironment; |
| 145 | |
| 146 | ODBCEnvironment* environment = reinterpret_cast<ODBCEnvironment*>(handle); |
| 147 | |
| 148 | if (!environment) { |
| 149 | return SQL_INVALID_HANDLE; |
| 150 | } |
| 151 | |
| 152 | delete environment; |
| 153 | |
| 154 | return SQL_SUCCESS; |
| 155 | } |
| 156 | |
| 157 | case SQL_HANDLE_DBC: { |
| 158 | using ODBC::ODBCConnection; |
| 159 | |
| 160 | ODBCConnection* conn = reinterpret_cast<ODBCConnection*>(handle); |
| 161 | |
| 162 | if (!conn) { |
| 163 | return SQL_INVALID_HANDLE; |
| 164 | } |
| 165 | |
| 166 | // `ReleaseConnection` does the equivalent of `delete`. |
| 167 | // `ReleaseConnection` removes the connection `shared_ptr` from the `std::vector` of |
| 168 | // connections, and the `shared_ptr` is automatically destructed afterwards. |
| 169 | conn->ReleaseConnection(); |
| 170 | |
| 171 | return SQL_SUCCESS; |
| 172 | } |
| 173 | |
| 174 | case SQL_HANDLE_STMT: { |
| 175 | using ODBC::ODBCStatement; |
| 176 | |
| 177 | ODBCStatement* statement = reinterpret_cast<ODBCStatement*>(handle); |
| 178 | |
| 179 | if (!statement) { |
| 180 | return SQL_INVALID_HANDLE; |
| 181 | } |
| 182 | |
| 183 | statement->ReleaseStatement(); |
| 184 | |
| 185 | return SQL_SUCCESS; |
| 186 | } |
| 187 | |
| 188 | case SQL_HANDLE_DESC: { |
| 189 | using ODBC::ODBCDescriptor; |
| 190 | |
| 191 | ODBCDescriptor* descriptor = reinterpret_cast<ODBCDescriptor*>(handle); |
| 192 | |
| 193 | if (!descriptor) { |
| 194 | return SQL_INVALID_HANDLE; |
| 195 | } |
| 196 | |