equal
deleted
inserted
replaced
|
1 /** |
|
2 * Relational pipes |
|
3 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, version 3. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 #pragma once |
|
18 |
|
19 #include <sql.h> |
|
20 |
|
21 #include "SqlException.h" |
|
22 |
|
23 namespace relpipe { |
|
24 namespace tr { |
|
25 namespace sql { |
|
26 |
|
27 class OdbcCommon { |
|
28 public: |
|
29 |
|
30 static bool isSuccessful(SQLRETURN result) { |
|
31 return result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO; |
|
32 } |
|
33 |
|
34 static bool isNotSuccessful(SQLRETURN result) { |
|
35 return !isSuccessful(result); |
|
36 } |
|
37 |
|
38 static SQLHANDLE allocateHandle(SQLSMALLINT type, SQLHANDLE input) { |
|
39 SQLHANDLE output; |
|
40 SQLRETURN result = SQLAllocHandle(type, input, &output); |
|
41 if (isNotSuccessful(result)) throw SqlException(L"Unable to allocate handle " + std::to_wstring(type)); |
|
42 return output; |
|
43 } |
|
44 |
|
45 static void freeHandle(SQLSMALLINT type, SQLHANDLE handle) { |
|
46 SQLRETURN result = SQLFreeHandle(type, handle); |
|
47 if (isNotSuccessful(result)) throw SqlException(L"Unable to free handle of type: " + std::to_wstring(type)); |
|
48 } |
|
49 }; |
|
50 |
|
51 } |
|
52 } |
|
53 } |