somer DB schema manipulation functions moved to libnxdb from nxdbmgr
[public/netxms.git] / src / server / tools / nxdbmgr / nxdbmgr.h
CommitLineData
7f6ecb6d 1/*
5039dede 2** nxdbmgr - NetXMS database manager
8e6e8ef1 3** Copyright (C) 2004-2016 Victor Kirhenshtein
5039dede
AK
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**
1e558daf 19** File: nxdbmgr.h
5039dede
AK
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>
9d88cdc9 30#include <nxdbapi.h>
5039dede
AK
31#include <netxmsdb.h>
32
33
5039dede
AK
34//
35// Non-standard data type codes
36//
37
38#define SQL_TYPE_TEXT 0
50da2d20
VK
39#define SQL_TYPE_TEXT4K 1
40#define SQL_TYPE_INT64 2
5039dede 41
40dedf5d
VK
42/**
43 * Execute with error check
44 */
ef607e62 45#define CHK_EXEC(x) do { if (!(x)) if (!g_bIgnoreErrors) return false; } while (0)
8ec9bcc9 46
5039dede
AK
47
48//
49// Functions
50//
51
63604cda 52DB_HANDLE ConnectToDatabase();
1e558daf 53void CheckDatabase();
08b214c6 54void InitDatabase(const char *pszInitFile);
9b4a2a0e 55bool ClearDatabase(bool preMigration);
4f23eecc 56void ExportDatabase(const char *file);
890a0930 57void ImportDatabase(const char *file);
f82c865a 58void MigrateDatabase(const TCHAR *sourceConfig, TCHAR *destConfFields);
1e558daf
VK
59void UpgradeDatabase();
60void UnlockDatabase();
7541bca2 61void ReindexIData();
5039dede 62DB_RESULT SQLSelect(const TCHAR *pszQuery);
f17cf019 63DB_UNBUFFERED_RESULT SQLSelectUnbuffered(const TCHAR *pszQuery);
c85c8ef2
VK
64bool SQLExecute(DB_STATEMENT hStmt);
65bool SQLQuery(const TCHAR *pszQuery);
66bool SQLBatch(const TCHAR *pszBatch);
67bool SQLDropColumn(const TCHAR *table, const TCHAR *column);
a4743a0f 68bool GetYesNo(const TCHAR *format, ...);
5039dede 69void ShowQuery(const TCHAR *pszQuery);
c85c8ef2
VK
70bool ExecSQLBatch(const char *pszFile);
71bool ValidateDatabase();
5039dede 72
06b83321 73bool IsDatabaseRecordExist(const TCHAR *table, const TCHAR *idColumn, UINT32 id);
035a4d73 74
3783d300 75BOOL MetaDataReadStr(const TCHAR *pszVar, TCHAR *pszBuffer, int iBufSize, const TCHAR *pszDefault);
2f1bc68b 76int MetaDataReadInt(const TCHAR *pszVar, int iDefault);
5039dede
AK
77BOOL ConfigReadStr(const TCHAR *pszVar, TCHAR *pszBuffer, int iBufSize, const TCHAR *pszDefault);
78int ConfigReadInt(const TCHAR *pszVar, int iDefault);
79DWORD ConfigReadULong(const TCHAR *pszVar, DWORD dwDefault);
c85c8ef2
VK
80bool CreateConfigParam(const TCHAR *name, const TCHAR *value, bool isVisible, bool needRestart, bool forceUpdate = false);
81bool CreateConfigParam(const TCHAR *name, const TCHAR *value, const TCHAR *description, char dataType, bool isVisible, bool needRestart, bool isPublic, bool forceUpdate = false);
5039dede 82
b29e5407 83bool IsDataTableExist(const TCHAR *format, UINT32 id);
63604cda 84
85ae39bc 85BOOL CreateIDataTable(DWORD nodeId);
63604cda 86BOOL CreateTDataTable(DWORD nodeId);
22aaa779 87BOOL CreateTDataTable_preV281(DWORD nodeId);
5039dede 88
be737a59 89void ResetSystemAccount();
c614ca60 90
5039dede
AK
91//
92// Global variables
93//
94
95extern DB_HANDLE g_hCoreDB;
96extern BOOL g_bIgnoreErrors;
97extern BOOL g_bTrace;
a4743a0f 98extern bool g_isGuiMode;
0d9b58ef 99extern bool g_checkData;
daf3c104 100extern bool g_checkDataTablesOnly;
ffaafdce
VK
101extern bool g_dataOnlyMigration;
102extern bool g_skipDataMigration;
09f1c9bf
VK
103extern bool g_skipDataSchemaMigration;
104extern int g_migrationTxnSize;
2a964810 105extern int g_dbSyntax;
5039dede 106extern const TCHAR *g_pszTableSuffix;
99d1de07 107extern const TCHAR *g_pszSqlType[6][3];
5039dede 108
5039dede 109#endif