somer DB schema manipulation functions moved to libnxdb from nxdbmgr
[public/netxms.git] / src / server / tools / nxdbmgr / nxdbmgr.h
1 /*
2 ** nxdbmgr - NetXMS database manager
3 ** Copyright (C) 2004-2016 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: nxdbmgr.h
20 **
21 **/
22
23 #ifndef _nxdbmgr_h_
24 #define _nxdbmgr_h_
25
26 #include <nms_common.h>
27 #include <nms_util.h>
28 #include <uuid.h>
29 #include <nxsrvapi.h>
30 #include <nxdbapi.h>
31 #include <netxmsdb.h>
32
33
34 //
35 // Non-standard data type codes
36 //
37
38 #define SQL_TYPE_TEXT 0
39 #define SQL_TYPE_TEXT4K 1
40 #define SQL_TYPE_INT64 2
41
42 /**
43 * Execute with error check
44 */
45 #define CHK_EXEC(x) do { if (!(x)) if (!g_bIgnoreErrors) return false; } while (0)
46
47
48 //
49 // Functions
50 //
51
52 DB_HANDLE ConnectToDatabase();
53 void CheckDatabase();
54 void InitDatabase(const char *pszInitFile);
55 bool ClearDatabase(bool preMigration);
56 void ExportDatabase(const char *file);
57 void ImportDatabase(const char *file);
58 void MigrateDatabase(const TCHAR *sourceConfig, TCHAR *destConfFields);
59 void UpgradeDatabase();
60 void UnlockDatabase();
61 void ReindexIData();
62 DB_RESULT SQLSelect(const TCHAR *pszQuery);
63 DB_UNBUFFERED_RESULT SQLSelectUnbuffered(const TCHAR *pszQuery);
64 bool SQLExecute(DB_STATEMENT hStmt);
65 bool SQLQuery(const TCHAR *pszQuery);
66 bool SQLBatch(const TCHAR *pszBatch);
67 bool SQLDropColumn(const TCHAR *table, const TCHAR *column);
68 bool GetYesNo(const TCHAR *format, ...);
69 void ShowQuery(const TCHAR *pszQuery);
70 bool ExecSQLBatch(const char *pszFile);
71 bool ValidateDatabase();
72
73 bool IsDatabaseRecordExist(const TCHAR *table, const TCHAR *idColumn, UINT32 id);
74
75 BOOL MetaDataReadStr(const TCHAR *pszVar, TCHAR *pszBuffer, int iBufSize, const TCHAR *pszDefault);
76 int MetaDataReadInt(const TCHAR *pszVar, int iDefault);
77 BOOL ConfigReadStr(const TCHAR *pszVar, TCHAR *pszBuffer, int iBufSize, const TCHAR *pszDefault);
78 int ConfigReadInt(const TCHAR *pszVar, int iDefault);
79 DWORD ConfigReadULong(const TCHAR *pszVar, DWORD dwDefault);
80 bool CreateConfigParam(const TCHAR *name, const TCHAR *value, bool isVisible, bool needRestart, bool forceUpdate = false);
81 bool CreateConfigParam(const TCHAR *name, const TCHAR *value, const TCHAR *description, char dataType, bool isVisible, bool needRestart, bool isPublic, bool forceUpdate = false);
82
83 bool IsDataTableExist(const TCHAR *format, UINT32 id);
84
85 BOOL CreateIDataTable(DWORD nodeId);
86 BOOL CreateTDataTable(DWORD nodeId);
87 BOOL CreateTDataTable_preV281(DWORD nodeId);
88
89 void ResetSystemAccount();
90
91 //
92 // Global variables
93 //
94
95 extern DB_HANDLE g_hCoreDB;
96 extern BOOL g_bIgnoreErrors;
97 extern BOOL g_bTrace;
98 extern bool g_isGuiMode;
99 extern bool g_checkData;
100 extern bool g_checkDataTablesOnly;
101 extern bool g_dataOnlyMigration;
102 extern bool g_skipDataMigration;
103 extern bool g_skipDataSchemaMigration;
104 extern int g_migrationTxnSize;
105 extern int g_dbSyntax;
106 extern const TCHAR *g_pszTableSuffix;
107 extern const TCHAR *g_pszSqlType[6][3];
108
109 #endif