implemented DB driver call DrvGetFieldUnbufferedUTF8 (for databases with native UTF...
[public/netxms.git] / src / db / libnxdb / libnxdb.h
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 */
39 struct 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;
46 int m_defaultPrefetchLimit;
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);
52 bool (* m_fpDrvSetPrefetchLimit)(DBDRV_CONNECTION, int);
53 DBDRV_STATEMENT (* m_fpDrvPrepare)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);
54 void (* m_fpDrvFreeStatement)(DBDRV_STATEMENT);
55 bool (* m_fpDrvOpenBatch)(DBDRV_STATEMENT);
56 void (* m_fpDrvNextBatchRow)(DBDRV_STATEMENT);
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 *);
61 DBDRV_UNBUFFERED_RESULT (* m_fpDrvSelectUnbuffered)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);
62 DBDRV_RESULT (* m_fpDrvSelectPrepared)(DBDRV_CONNECTION, DBDRV_STATEMENT, DWORD *, WCHAR *);
63 DBDRV_UNBUFFERED_RESULT (* m_fpDrvSelectPreparedUnbuffered)(DBDRV_CONNECTION, DBDRV_STATEMENT, DWORD *, WCHAR *);
64 bool (* m_fpDrvFetch)(DBDRV_UNBUFFERED_RESULT);
65 LONG (* m_fpDrvGetFieldLength)(DBDRV_RESULT, int, int);
66 LONG (* m_fpDrvGetFieldLengthUnbuffered)(DBDRV_UNBUFFERED_RESULT, int);
67 WCHAR* (* m_fpDrvGetField)(DBDRV_RESULT, int, int, WCHAR *, int);
68 char* (* m_fpDrvGetFieldUTF8)(DBDRV_RESULT, int, int, char *, int);
69 WCHAR* (* m_fpDrvGetFieldUnbuffered)(DBDRV_UNBUFFERED_RESULT, int, WCHAR *, int);
70 char* (* m_fpDrvGetFieldUnbufferedUTF8)(DBDRV_UNBUFFERED_RESULT, int, char *, int);
71 int (* m_fpDrvGetNumRows)(DBDRV_RESULT);
72 void (* m_fpDrvFreeResult)(DBDRV_RESULT);
73 void (* m_fpDrvFreeUnbufferedResult)(DBDRV_UNBUFFERED_RESULT);
74 DWORD (* m_fpDrvBegin)(DBDRV_CONNECTION);
75 DWORD (* m_fpDrvCommit)(DBDRV_CONNECTION);
76 DWORD (* m_fpDrvRollback)(DBDRV_CONNECTION);
77 void (* m_fpDrvUnload)();
78 void (* m_fpEventHandler)(DWORD, const WCHAR *, const WCHAR *, bool, void *);
79 int (* m_fpDrvGetColumnCount)(DBDRV_RESULT);
80 const char* (* m_fpDrvGetColumnName)(DBDRV_RESULT, int);
81 int (* m_fpDrvGetColumnCountUnbuffered)(DBDRV_UNBUFFERED_RESULT);
82 const char* (* m_fpDrvGetColumnNameUnbuffered)(DBDRV_UNBUFFERED_RESULT, int);
83 WCHAR* (* m_fpDrvPrepareStringW)(const WCHAR *);
84 char* (* m_fpDrvPrepareStringA)(const char *);
85 int (* m_fpDrvIsTableExist)(DBDRV_CONNECTION, const WCHAR *);
86 };
87
88 /**
89 * Prepared statement
90 */
91 struct 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 */
102 struct 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 */
121 struct db_result_t
122 {
123 DB_DRIVER m_driver;
124 DB_HANDLE m_connection;
125 DBDRV_RESULT m_data;
126 };
127
128 /**
129 * Unbuffered SELECT query result
130 */
131 struct db_unbuffered_result_t
132 {
133 DB_DRIVER m_driver;
134 DB_HANDLE m_connection;
135 DBDRV_UNBUFFERED_RESULT m_data;
136 };
137
138 /**
139 * Internal functions
140 */
141 void __DBWriteLog(WORD level, const TCHAR *format, ...);
142
143 /**
144 * Global variables
145 */
146 extern UINT32 g_logMsgCode;
147 extern UINT32 g_sqlErrorMsgCode;
148 extern UINT32 g_sqlQueryExecTimeThreshold;
149
150 #endif /* _libnxsrv_h_ */