"Fossies" - the Fresh Open Source Software Archive

Member "netxms-3.8.166/include/nxdbapi.h" (23 Feb 2021, 13603 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "nxdbapi.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.6.300_vs_3.7.95.

    1 /* 
    2 ** NetXMS - Network Management System
    3 ** DB Library
    4 ** Copyright (C) 2003-2011 Victor Kirhenshtein
    5 **
    6 ** This program is free software; you can redistribute it and/or modify
    7 ** it under the terms of the GNU Lesser General Public License as published by
    8 ** the Free Software Foundation; either version 3 of the License, or
    9 ** (at your option) any later version.
   10 **
   11 ** This program is distributed in the hope that it will be useful,
   12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 ** GNU General Public License for more details.
   15 **
   16 ** You should have received a copy of the GNU Lesser General Public License
   17 ** along with this program; if not, write to the Free Software
   18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   19 **
   20 ** File: nxdbapi.h
   21 **
   22 **/
   23 
   24 #ifndef _nxdbapi_h_
   25 #define _nxdbapi_h_
   26 
   27 #ifdef LIBNXDB_EXPORTS
   28 #define LIBNXDB_EXPORTABLE __EXPORT
   29 #else
   30 #define LIBNXDB_EXPORTABLE __IMPORT
   31 #endif
   32 
   33 #include <dbdrv.h>
   34 #include <uuid.h>
   35 
   36 
   37 //
   38 // DB-related constants
   39 //
   40 
   41 #define MAX_DB_LOGIN          64
   42 #define MAX_DB_PASSWORD       64
   43 #define MAX_DB_NAME           256
   44 
   45 /**
   46  * DB events
   47  */
   48 #define DBEVENT_CONNECTION_LOST        0
   49 #define DBEVENT_CONNECTION_RESTORED    1
   50 #define DBEVENT_QUERY_FAILED           2
   51 
   52 
   53 /**
   54  * Database syntax codes
   55  */
   56 #define DB_SYNTAX_MYSQL    0
   57 #define DB_SYNTAX_PGSQL    1
   58 #define DB_SYNTAX_MSSQL    2
   59 #define DB_SYNTAX_ORACLE   3
   60 #define DB_SYNTAX_SQLITE   4
   61 #define DB_SYNTAX_DB2      5
   62 #define DB_SYNTAX_INFORMIX 6
   63 #define DB_SYNTAX_TSDB     7
   64 #define DB_SYNTAX_UNKNOWN   -1
   65 
   66 /**
   67  * Database connection structures
   68  */
   69 struct db_driver_t;
   70 typedef db_driver_t * DB_DRIVER;
   71 
   72 struct db_handle_t;
   73 typedef db_handle_t * DB_HANDLE;
   74 
   75 struct db_statement_t;
   76 typedef db_statement_t * DB_STATEMENT;
   77 
   78 struct db_result_t;
   79 typedef db_result_t * DB_RESULT;
   80 
   81 struct db_unbuffered_result_t;
   82 typedef db_unbuffered_result_t * DB_UNBUFFERED_RESULT;
   83 
   84 /**
   85  * Pool connection information
   86  */
   87 struct PoolConnectionInfo
   88 {
   89    DB_HANDLE handle;
   90    bool inUse;
   91    bool resetOnRelease;
   92    time_t lastAccessTime;
   93    time_t connectTime;
   94    uint32_t usageCount;
   95    char srcFile[128];
   96    int srcLine;
   97 };
   98 
   99 /**
  100  * DB library performance counters
  101  */
  102 struct LIBNXDB_PERF_COUNTERS
  103 {
  104    uint64_t selectQueries;
  105    uint64_t nonSelectQueries;
  106    uint64_t totalQueries;
  107    uint64_t longRunningQueries;
  108    uint64_t failedQueries;
  109 };
  110 
  111 /**
  112  * Functions
  113  */
  114 bool LIBNXDB_EXPORTABLE DBInit();
  115 DB_DRIVER LIBNXDB_EXPORTABLE DBLoadDriver(const TCHAR *module, const TCHAR *initParameters,
  116          void (*eventHandler)(uint32_t, const WCHAR *, const WCHAR *, bool, void *), void *context);
  117 void LIBNXDB_EXPORTABLE DBUnloadDriver(DB_DRIVER driver);
  118 const char LIBNXDB_EXPORTABLE *DBGetDriverName(DB_DRIVER driver);
  119 void LIBNXDB_EXPORTABLE DBSetDefaultPrefetchLimit(DB_DRIVER driver, int limit);
  120 void LIBNXDB_EXPORTABLE DBEnableQueryTrace(bool enabled);
  121 bool LIBNXDB_EXPORTABLE DBIsQueryTraceEnabled();
  122 
  123 DB_HANDLE LIBNXDB_EXPORTABLE DBConnect(DB_DRIVER driver, const TCHAR *server, const TCHAR *dbName,
  124                                        const TCHAR *login, const TCHAR *password, const TCHAR *schema, TCHAR *errorText);
  125 void LIBNXDB_EXPORTABLE DBDisconnect(DB_HANDLE hConn);
  126 void LIBNXDB_EXPORTABLE DBEnableReconnect(DB_HANDLE hConn, bool enabled);
  127 bool LIBNXDB_EXPORTABLE DBSetPrefetchLimit(DB_HANDLE hConn, int limit);
  128 void LIBNXDB_EXPORTABLE DBSetSessionInitCallback(void (*cb)(DB_HANDLE));
  129 DB_DRIVER LIBNXDB_EXPORTABLE DBGetDriver(DB_HANDLE hConn);
  130 
  131 DB_STATEMENT LIBNXDB_EXPORTABLE DBPrepare(DB_HANDLE hConn, const TCHAR *szQuery, bool optimizeForReuse = false);
  132 DB_STATEMENT LIBNXDB_EXPORTABLE DBPrepareEx(DB_HANDLE hConn, const TCHAR *szQuery, bool optimizeForReuse, TCHAR *errorText);
  133 void LIBNXDB_EXPORTABLE DBFreeStatement(DB_STATEMENT hStmt);
  134 const TCHAR LIBNXDB_EXPORTABLE *DBGetStatementSource(DB_STATEMENT hStmt);
  135 bool LIBNXDB_EXPORTABLE DBOpenBatch(DB_STATEMENT hStmt);
  136 void LIBNXDB_EXPORTABLE DBNextBatchRow(DB_STATEMENT hStmt);
  137 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, int cType, void *buffer, int allocType);
  138 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, const TCHAR *value, int allocType);
  139 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, const TCHAR *value, int allocType, int maxLen);
  140 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, INT32 value);
  141 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, UINT32 value);
  142 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, INT64 value);
  143 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, UINT64 value);
  144 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, double value);
  145 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, const uuid& value);
  146 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, const InetAddress& value);
  147 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, const MacAddress& value);
  148 void LIBNXDB_EXPORTABLE DBBind(DB_STATEMENT hStmt, int pos, int sqlType, json_t *value, int allocType);
  149 bool LIBNXDB_EXPORTABLE DBExecute(DB_STATEMENT hStmt);
  150 bool LIBNXDB_EXPORTABLE DBExecuteEx(DB_STATEMENT hStmt, TCHAR *errorText);
  151 DB_RESULT LIBNXDB_EXPORTABLE DBSelectPrepared(DB_STATEMENT hStmt);
  152 DB_RESULT LIBNXDB_EXPORTABLE DBSelectPreparedEx(DB_STATEMENT hStmt, TCHAR *errorText);
  153 DB_UNBUFFERED_RESULT LIBNXDB_EXPORTABLE DBSelectPreparedUnbuffered(DB_STATEMENT hStmt);
  154 DB_UNBUFFERED_RESULT LIBNXDB_EXPORTABLE DBSelectPreparedUnbufferedEx(DB_STATEMENT hStmt, TCHAR *errorText);
  155 
  156 bool LIBNXDB_EXPORTABLE DBQuery(DB_HANDLE hConn, const TCHAR *szQuery);
  157 bool LIBNXDB_EXPORTABLE DBQueryEx(DB_HANDLE hConn, const TCHAR *szQuery, TCHAR *errorText);
  158 
  159 DB_RESULT LIBNXDB_EXPORTABLE DBSelect(DB_HANDLE hConn, const TCHAR *szQuery);
  160 DB_RESULT LIBNXDB_EXPORTABLE DBSelectEx(DB_HANDLE hConn, const TCHAR *szQuery, TCHAR *errorText);
  161 int LIBNXDB_EXPORTABLE DBGetColumnCount(DB_RESULT hResult);
  162 bool LIBNXDB_EXPORTABLE DBGetColumnName(DB_RESULT hResult, int column, TCHAR *buffer, int bufSize);
  163 bool LIBNXDB_EXPORTABLE DBGetColumnNameA(DB_RESULT hResult, int column, char *buffer, int bufSize);
  164 int LIBNXDB_EXPORTABLE DBGetNumRows(DB_RESULT hResult);
  165 void LIBNXDB_EXPORTABLE DBFreeResult(DB_RESULT hResult);
  166 
  167 TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int row, int col, TCHAR *buffer, size_t nBufLen);
  168 SharedString LIBNXDB_EXPORTABLE DBGetFieldAsSharedString(DB_RESULT hResult, int row, int col);
  169 TCHAR LIBNXDB_EXPORTABLE *DBGetFieldForXML(DB_RESULT hResult, int row, int col);
  170 char LIBNXDB_EXPORTABLE *DBGetFieldA(DB_RESULT hResult, int iRow, int iColumn, char *buffer, size_t nBufLen);
  171 char LIBNXDB_EXPORTABLE *DBGetFieldUTF8(DB_RESULT hResult, int iRow, int iColumn, char *buffer, size_t nBufLen);
  172 int32_t LIBNXDB_EXPORTABLE DBGetFieldLong(DB_RESULT hResult, int row, int column);
  173 uint32_t LIBNXDB_EXPORTABLE DBGetFieldULong(DB_RESULT hResult, int row, int column);
  174 int64_t LIBNXDB_EXPORTABLE DBGetFieldInt64(DB_RESULT hResult, int row, int column);
  175 uint64_t LIBNXDB_EXPORTABLE DBGetFieldUInt64(DB_RESULT hResult, int row, int column);
  176 double LIBNXDB_EXPORTABLE DBGetFieldDouble(DB_RESULT hResult, int iRow, int iColumn);
  177 uint32_t LIBNXDB_EXPORTABLE DBGetFieldIPAddr(DB_RESULT hResult, int row, int column);
  178 InetAddress LIBNXDB_EXPORTABLE DBGetFieldInetAddr(DB_RESULT hResult, int iRow, int iColumn);
  179 MacAddress LIBNXDB_EXPORTABLE DBGetFieldMacAddr(DB_RESULT hResult, int iRow, int iColumn);
  180 bool LIBNXDB_EXPORTABLE DBGetFieldByteArray(DB_RESULT hResult, int iRow, int iColumn, int *pnArray, size_t size, int defaultValue);
  181 bool LIBNXDB_EXPORTABLE DBGetFieldByteArray2(DB_RESULT hResult, int iRow, int iColumn, BYTE *data, size_t size, BYTE defaultValue);
  182 uuid LIBNXDB_EXPORTABLE DBGetFieldGUID(DB_RESULT hResult, int iRow, int iColumn);
  183 
  184 DB_UNBUFFERED_RESULT LIBNXDB_EXPORTABLE DBSelectUnbuffered(DB_HANDLE hConn, const TCHAR *szQuery);
  185 DB_UNBUFFERED_RESULT LIBNXDB_EXPORTABLE DBSelectUnbufferedEx(DB_HANDLE hConn, const TCHAR *szQuery, TCHAR *errorText);
  186 bool LIBNXDB_EXPORTABLE DBFetch(DB_UNBUFFERED_RESULT hResult);
  187 int LIBNXDB_EXPORTABLE DBGetColumnCount(DB_UNBUFFERED_RESULT hResult);
  188 bool LIBNXDB_EXPORTABLE DBGetColumnName(DB_UNBUFFERED_RESULT hResult, int column, TCHAR *buffer, int bufSize);
  189 bool LIBNXDB_EXPORTABLE DBGetColumnNameA(DB_UNBUFFERED_RESULT hResult, int column, char *buffer, int bufSize);
  190 void LIBNXDB_EXPORTABLE DBFreeResult(DB_UNBUFFERED_RESULT hResult);
  191 void LIBNXDB_EXPORTABLE DBResultToTable(DB_RESULT hResult, Table *table);
  192 
  193 TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_UNBUFFERED_RESULT hResult, int iColumn, TCHAR *buffer, size_t bufSize);
  194 char LIBNXDB_EXPORTABLE *DBGetFieldUTF8(DB_UNBUFFERED_RESULT hResult, int iColumn, char *buffer, size_t bufSize);
  195 int32_t LIBNXDB_EXPORTABLE DBGetFieldLong(DB_UNBUFFERED_RESULT hResult, int column);
  196 uint32_t LIBNXDB_EXPORTABLE DBGetFieldULong(DB_UNBUFFERED_RESULT hResult, int column);
  197 int64_t LIBNXDB_EXPORTABLE DBGetFieldInt64(DB_UNBUFFERED_RESULT hResult, int column);
  198 uint64_t LIBNXDB_EXPORTABLE DBGetFieldUInt64(DB_UNBUFFERED_RESULT hResult, int column);
  199 double LIBNXDB_EXPORTABLE DBGetFieldDouble(DB_UNBUFFERED_RESULT hResult, int iColumn);
  200 uint32_t LIBNXDB_EXPORTABLE DBGetFieldIPAddr(DB_UNBUFFERED_RESULT hResult, int column);
  201 InetAddress LIBNXDB_EXPORTABLE DBGetFieldInetAddr(DB_UNBUFFERED_RESULT hResult, int column);
  202 uuid LIBNXDB_EXPORTABLE DBGetFieldGUID(DB_UNBUFFERED_RESULT hResult, int iColumn);
  203 
  204 bool LIBNXDB_EXPORTABLE DBBegin(DB_HANDLE hConn);
  205 bool LIBNXDB_EXPORTABLE DBCommit(DB_HANDLE hConn);
  206 bool LIBNXDB_EXPORTABLE DBRollback(DB_HANDLE hConn);
  207 
  208 int LIBNXDB_EXPORTABLE DBIsTableExist(DB_HANDLE conn, const TCHAR *table);
  209 
  210 bool LIBNXDB_EXPORTABLE DBGetSchemaVersion(DB_HANDLE conn, INT32 *major, INT32 *minor);
  211 int LIBNXDB_EXPORTABLE DBGetSyntax(DB_HANDLE conn, const TCHAR *fallback = NULL);
  212 void LIBNXDB_EXPORTABLE DBSetSyntaxReader(bool (*reader)(DB_HANDLE, TCHAR *));
  213 
  214 StringBuffer LIBNXDB_EXPORTABLE DBPrepareString(DB_HANDLE conn, const TCHAR *str, int maxSize = -1);
  215 StringBuffer LIBNXDB_EXPORTABLE DBPrepareString(DB_DRIVER drv, const TCHAR *str, int maxSize = -1);
  216 #ifdef UNICODE
  217 StringBuffer LIBNXDB_EXPORTABLE DBPrepareStringA(DB_HANDLE conn, const char *str, int maxSize = -1);
  218 StringBuffer LIBNXDB_EXPORTABLE DBPrepareStringA(DB_DRIVER drv, const char *str, int maxSize = -1);
  219 #else
  220 #define DBPrepareStringA DBPrepareString
  221 #endif
  222 StringBuffer LIBNXDB_EXPORTABLE DBPrepareStringUTF8(DB_HANDLE conn, const char *str, int maxSize = -1);
  223 StringBuffer LIBNXDB_EXPORTABLE DBPrepareStringUTF8(DB_DRIVER drv, const char *str, int maxSize = -1);
  224 
  225 bool LIBNXDB_EXPORTABLE DBConnectionPoolStartup(DB_DRIVER driver, const TCHAR *server, const TCHAR *dbName,
  226                                                                 const TCHAR *login, const TCHAR *password, const TCHAR *schema,
  227                                                                 int basePoolSize, int maxPoolSize, int cooldownTime,
  228                                                                 int connTTL);
  229 void LIBNXDB_EXPORTABLE DBConnectionPoolShutdown();
  230 void LIBNXDB_EXPORTABLE DBConnectionPoolReset();
  231 DB_HANDLE LIBNXDB_EXPORTABLE __DBConnectionPoolAcquireConnection(const char *srcFile, int srcLine);
  232 #define DBConnectionPoolAcquireConnection() __DBConnectionPoolAcquireConnection(__FILE__, __LINE__)
  233 void LIBNXDB_EXPORTABLE DBConnectionPoolReleaseConnection(DB_HANDLE connection);
  234 int LIBNXDB_EXPORTABLE DBConnectionPoolGetSize();
  235 int LIBNXDB_EXPORTABLE DBConnectionPoolGetAcquiredCount();
  236 
  237 void LIBNXDB_EXPORTABLE DBSetLongRunningThreshold(UINT32 threshold);
  238 ObjectArray<PoolConnectionInfo> LIBNXDB_EXPORTABLE *DBConnectionPoolGetConnectionList();
  239 void LIBNXDB_EXPORTABLE DBGetPerfCounters(LIBNXDB_PERF_COUNTERS *counters);
  240 
  241 bool LIBNXDB_EXPORTABLE IsDatabaseRecordExist(DB_HANDLE hdb, const TCHAR *table, const TCHAR *idColumn, uint32_t id);
  242 bool LIBNXDB_EXPORTABLE IsDatabaseRecordExist(DB_HANDLE hdb, const TCHAR *table, const TCHAR *idColumn, uint64_t id);
  243 bool LIBNXDB_EXPORTABLE IsDatabaseRecordExist(DB_HANDLE hdb, const TCHAR *table, const TCHAR *idColumn, const uuid& id);
  244 bool LIBNXDB_EXPORTABLE IsDatabaseRecordExist(DB_HANDLE hdb, const TCHAR *table, const TCHAR *idColumn, const TCHAR *id);
  245 
  246 void LIBNXDB_EXPORTABLE DBSetUtilityQueryTracer(void (*queryTracer)(const TCHAR *, bool, const TCHAR *));
  247 
  248 bool LIBNXDB_EXPORTABLE DBRenameTable(DB_HANDLE hdb, const TCHAR *oldName, const TCHAR *newName);
  249 bool LIBNXDB_EXPORTABLE DBDropPrimaryKey(DB_HANDLE hdb, const TCHAR *table);
  250 bool LIBNXDB_EXPORTABLE DBAddPrimaryKey(DB_HANDLE hdb, const TCHAR *table, const TCHAR *columns);
  251 bool LIBNXDB_EXPORTABLE DBRemoveNotNullConstraint(DB_HANDLE hdb, const TCHAR *table, const TCHAR *column);
  252 bool LIBNXDB_EXPORTABLE DBSetNotNullConstraint(DB_HANDLE hdb, const TCHAR *table, const TCHAR *column);
  253 bool LIBNXDB_EXPORTABLE DBResizeColumn(DB_HANDLE hdb, const TCHAR *table, const TCHAR *column, int newSize, bool nullable);
  254 bool LIBNXDB_EXPORTABLE DBDropColumn(DB_HANDLE hdb, const TCHAR *table, const TCHAR *column);
  255 bool LIBNXDB_EXPORTABLE DBRenameColumn(DB_HANDLE hdb, const TCHAR *tableName, const TCHAR *oldName, const TCHAR *newName);
  256 bool LIBNXDB_EXPORTABLE DBDropIndex(DB_HANDLE hdb, const TCHAR *table, const TCHAR *index);
  257 
  258 DB_HANDLE LIBNXDB_EXPORTABLE DBOpenInMemoryDatabase();
  259 void LIBNXDB_EXPORTABLE DBCloseInMemoryDatabase(DB_HANDLE hdb);
  260 bool LIBNXDB_EXPORTABLE DBCacheTable(DB_HANDLE cacheDB, DB_HANDLE sourceDB, const TCHAR *table, const TCHAR *indexColumn, const TCHAR *columns, const TCHAR * const *intColumns = NULL);
  261 
  262 #endif   /* _nxsrvapi_h_ */