418f202ba6f6b6a614b9a05e92c7bb8d0a6e9460
[public/netxms.git] / src / db / libnxdb / libnxdb.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2009 Victor Kirhenshtein
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; either version 2 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 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 //
33 // Constants
34 //
35
36 #define MAX_DB_DRIVERS 16
37
38
39 //
40 // Database driver structure
41 //
42
43 struct db_driver_t
44 {
45 const char *m_name;
46 int m_refCount;
47 bool m_logSqlErrors;
48 bool m_dumpSql;
49 int m_reconnect;
50 MUTEX m_mutexReconnect;
51 HMODULE m_handle;
52 void *m_userArg;
53 DBDRV_CONNECTION (* m_fpDrvConnect)(const char *, const char *, const char *, const char *);
54 void (* m_fpDrvDisconnect)(DBDRV_CONNECTION);
55 DWORD (* m_fpDrvQuery)(DBDRV_CONNECTION, WCHAR *, TCHAR *);
56 DBDRV_RESULT (* m_fpDrvSelect)(DBDRV_CONNECTION, WCHAR *, DWORD *, TCHAR *);
57 DBDRV_ASYNC_RESULT (* m_fpDrvAsyncSelect)(DBDRV_CONNECTION, WCHAR *, DWORD *, TCHAR *);
58 BOOL (* m_fpDrvFetch)(DBDRV_ASYNC_RESULT);
59 LONG (* m_fpDrvGetFieldLength)(DBDRV_RESULT, int, int);
60 LONG (* m_fpDrvGetFieldLengthAsync)(DBDRV_RESULT, int);
61 WCHAR* (* m_fpDrvGetField)(DBDRV_RESULT, int, int, WCHAR *, int);
62 WCHAR* (* m_fpDrvGetFieldAsync)(DBDRV_ASYNC_RESULT, int, WCHAR *, int);
63 int (* m_fpDrvGetNumRows)(DBDRV_RESULT);
64 void (* m_fpDrvFreeResult)(DBDRV_RESULT);
65 void (* m_fpDrvFreeAsyncResult)(DBDRV_ASYNC_RESULT);
66 DWORD (* m_fpDrvBegin)(DBDRV_CONNECTION);
67 DWORD (* m_fpDrvCommit)(DBDRV_CONNECTION);
68 DWORD (* m_fpDrvRollback)(DBDRV_CONNECTION);
69 void (* m_fpDrvUnload)(void);
70 void (* m_fpEventHandler)(DWORD, const TCHAR *, const TCHAR *, void *);
71 int (* m_fpDrvGetColumnCount)(DBDRV_RESULT);
72 const char* (* m_fpDrvGetColumnName)(DBDRV_RESULT, int);
73 int (* m_fpDrvGetColumnCountAsync)(DBDRV_ASYNC_RESULT);
74 const char* (* m_fpDrvGetColumnNameAsync)(DBDRV_ASYNC_RESULT, int);
75 TCHAR* (* m_fpDrvPrepareString)(const TCHAR *);
76 };
77
78
79 //
80 // database connection structure
81 //
82
83 struct db_handle_t
84 {
85 DBDRV_CONNECTION m_connection;
86 DB_DRIVER m_driver;
87 bool m_dumpSql;
88 MUTEX m_mutexTransLock; // Transaction lock
89 int m_transactionLevel;
90 TCHAR *m_server;
91 TCHAR *m_login;
92 TCHAR *m_password;
93 TCHAR *m_dbName;
94 };
95
96
97 //
98 // SELECT query result
99 //
100
101 struct db_result_t
102 {
103 DB_DRIVER m_driver;
104 DB_HANDLE m_connection;
105 DBDRV_RESULT m_data;
106 };
107
108
109 //
110 // Async SELECT query result
111 //
112
113 struct db_async_result_t
114 {
115 DB_DRIVER m_driver;
116 DB_HANDLE m_connection;
117 DBDRV_ASYNC_RESULT m_data;
118 };
119
120
121 //
122 // Internal functions
123 //
124
125 void __DBWriteLog(WORD level, const TCHAR *format, ...);
126 void __DBDbgPrintf(int level, const TCHAR *format, ...);
127
128
129 //
130 // Global variables
131 //
132
133 extern DWORD g_logMsgCode;
134 extern DWORD g_sqlErrorMsgCode;
135
136
137 #endif /* _libnxsrv_h_ */