implemented DB driver call DrvGetFieldUnbufferedUTF8 (for databases with native UTF...
[public/netxms.git] / src / db / libnxdb / libnxdb.h
CommitLineData
4cd1e46b
AK
1/*
2** NetXMS - Network Management System
3** Copyright (C) 2003-2012 Victor Kirhenshtein
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU Lesser General Public License as published by
7** the Free Software Foundation; either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU Lesser General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: libnxdb.h
20**
21**/
22
23#ifndef _libnxsrv_h_
24#define _libnxsrv_h_
25
26#include <nms_common.h>
27#include <nms_util.h>
28#include <nms_threads.h>
29#include <nxdbapi.h>
30
31/**
32 * Max number of loaded database drivers
33 */
34#define MAX_DB_DRIVERS 16
35
36/**
37 * Database driver structure
38 */
39struct db_driver_t
40{
41 const char *m_name;
42 int m_refCount;
43 bool m_logSqlErrors;
44 bool m_dumpSql;
45 int m_reconnect;
85dfb586 46 int m_defaultPrefetchLimit;
4cd1e46b
AK
47 MUTEX m_mutexReconnect;
48 HMODULE m_handle;
49 void *m_userArg;
50 DBDRV_CONNECTION (* m_fpDrvConnect)(const char *, const char *, const char *, const char *, const char *, WCHAR *);
51 void (* m_fpDrvDisconnect)(DBDRV_CONNECTION);
85dfb586 52 bool (* m_fpDrvSetPrefetchLimit)(DBDRV_CONNECTION, int);
4cd1e46b
AK
53 DBDRV_STATEMENT (* m_fpDrvPrepare)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);
54 void (* m_fpDrvFreeStatement)(DBDRV_STATEMENT);
66c11d49
VK
55 bool (* m_fpDrvOpenBatch)(DBDRV_STATEMENT);
56 void (* m_fpDrvNextBatchRow)(DBDRV_STATEMENT);
4cd1e46b
AK
57 void (* m_fpDrvBind)(DBDRV_STATEMENT, int, int, int, void *, int);
58 DWORD (* m_fpDrvExecute)(DBDRV_CONNECTION, DBDRV_STATEMENT, WCHAR *);
59 DWORD (* m_fpDrvQuery)(DBDRV_CONNECTION, const WCHAR *, WCHAR *);
60 DBDRV_RESULT (* m_fpDrvSelect)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);
f17cf019 61 DBDRV_UNBUFFERED_RESULT (* m_fpDrvSelectUnbuffered)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);
4cd1e46b 62 DBDRV_RESULT (* m_fpDrvSelectPrepared)(DBDRV_CONNECTION, DBDRV_STATEMENT, DWORD *, WCHAR *);
f17cf019
VK
63 DBDRV_UNBUFFERED_RESULT (* m_fpDrvSelectPreparedUnbuffered)(DBDRV_CONNECTION, DBDRV_STATEMENT, DWORD *, WCHAR *);
64 bool (* m_fpDrvFetch)(DBDRV_UNBUFFERED_RESULT);
4cd1e46b 65 LONG (* m_fpDrvGetFieldLength)(DBDRV_RESULT, int, int);
f17cf019 66 LONG (* m_fpDrvGetFieldLengthUnbuffered)(DBDRV_UNBUFFERED_RESULT, int);
4cd1e46b 67 WCHAR* (* m_fpDrvGetField)(DBDRV_RESULT, int, int, WCHAR *, int);
43526096 68 char* (* m_fpDrvGetFieldUTF8)(DBDRV_RESULT, int, int, char *, int);
f17cf019 69 WCHAR* (* m_fpDrvGetFieldUnbuffered)(DBDRV_UNBUFFERED_RESULT, int, WCHAR *, int);
7f8e3ccf 70 char* (* m_fpDrvGetFieldUnbufferedUTF8)(DBDRV_UNBUFFERED_RESULT, int, char *, int);
4cd1e46b
AK
71 int (* m_fpDrvGetNumRows)(DBDRV_RESULT);
72 void (* m_fpDrvFreeResult)(DBDRV_RESULT);
f17cf019 73 void (* m_fpDrvFreeUnbufferedResult)(DBDRV_UNBUFFERED_RESULT);
4cd1e46b
AK
74 DWORD (* m_fpDrvBegin)(DBDRV_CONNECTION);
75 DWORD (* m_fpDrvCommit)(DBDRV_CONNECTION);
76 DWORD (* m_fpDrvRollback)(DBDRV_CONNECTION);
77 void (* m_fpDrvUnload)();
526ae8b8 78 void (* m_fpEventHandler)(DWORD, const WCHAR *, const WCHAR *, bool, void *);
4cd1e46b
AK
79 int (* m_fpDrvGetColumnCount)(DBDRV_RESULT);
80 const char* (* m_fpDrvGetColumnName)(DBDRV_RESULT, int);
f17cf019
VK
81 int (* m_fpDrvGetColumnCountUnbuffered)(DBDRV_UNBUFFERED_RESULT);
82 const char* (* m_fpDrvGetColumnNameUnbuffered)(DBDRV_UNBUFFERED_RESULT, int);
4cd1e46b
AK
83 WCHAR* (* m_fpDrvPrepareStringW)(const WCHAR *);
84 char* (* m_fpDrvPrepareStringA)(const char *);
daf3c104 85 int (* m_fpDrvIsTableExist)(DBDRV_CONNECTION, const WCHAR *);
4cd1e46b
AK
86};
87
88/**
89 * Prepared statement
90 */
91struct db_statement_t
92{
93 DB_DRIVER m_driver;
94 DB_HANDLE m_connection;
95 DBDRV_STATEMENT m_statement;
96 TCHAR *m_query;
97};
98
99/**
100 * Database connection structure
101 */
102struct db_handle_t
103{
104 DBDRV_CONNECTION m_connection;
105 DB_DRIVER m_driver;
106 bool m_dumpSql;
107 bool m_reconnectEnabled;
108 MUTEX m_mutexTransLock; // Transaction lock
109 int m_transactionLevel;
110 char *m_server;
111 char *m_login;
112 char *m_password;
113 char *m_dbName;
114 char *m_schema;
115 ObjectArray<db_statement_t> *m_preparedStatements;
116};
117
118/**
119 * SELECT query result
120 */
121struct db_result_t
122{
123 DB_DRIVER m_driver;
124 DB_HANDLE m_connection;
125 DBDRV_RESULT m_data;
126};
127
128/**
f17cf019 129 * Unbuffered SELECT query result
4cd1e46b 130 */
f17cf019 131struct db_unbuffered_result_t
4cd1e46b
AK
132{
133 DB_DRIVER m_driver;
134 DB_HANDLE m_connection;
f17cf019 135 DBDRV_UNBUFFERED_RESULT m_data;
4cd1e46b
AK
136};
137
f17cf019
VK
138/**
139 * Internal functions
140 */
4cd1e46b 141void __DBWriteLog(WORD level, const TCHAR *format, ...);
4cd1e46b 142
f17cf019
VK
143/**
144 * Global variables
145 */
58f1f627
VK
146extern UINT32 g_logMsgCode;
147extern UINT32 g_sqlErrorMsgCode;
148extern UINT32 g_sqlQueryExecTimeThreshold;
4cd1e46b 149
4cd1e46b 150#endif /* _libnxsrv_h_ */