Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cSQLDatabasePool.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cSQLDatabasePool_H
7 #define _INC_cSQLDatabasePool_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cSQLDatabase.h"
14 
15 namespace GrayLib
16 {
18  {
21 
22  public:
26 
27  private:
28  mutable cThreadLockCount m_Lock;
29  ITERATE_t m_iLastConnection;
30  cArrayRef<cSQLDatabase> m_aConnections;
31 
32  private:
33  ITERATE_t AddConnection(cSQLDatabase* pDatabase);
34  cSQLDatabasePtr FindFreeConnection() const;
35 
36  public:
37  cSQLDatabasePool(cStringF sConnectionString = "", int nMaxConnections = 256, TIMESYSD_t nMaxWait = 1000);
39 
40  HRESULT OpenConnectFirst(cStringF sConnectionString, cExceptionHolder* pEx = nullptr);
41  void Close();
42 
44  {
45  return m_aConnections.GetSize();
46  }
47  bool isOpen() const
48  {
49  return get_ConnectionCount();
50  }
51  bool isConfigured() const
52  {
53  return !m_sConnectionString.IsEmpty();
54  }
55 
56  HRESULT GetConnection(cSQLDatabasePtr& pConnection);
58  {
59  cSQLDatabasePtr pDatabase;
60  HRESULT hRes = GetConnection(pDatabase);
61  if (FAILED(hRes))
62  return nullptr;
63  return pDatabase;
64  }
65 
66  HRESULT ExecuteSQLCmd(cSQLCmd& command, cExceptionHolder* pExceptionRet = nullptr);
67  HRESULT ExecuteSQLAndFetch(cSQLCmd& oCmd, cSQLStatement& rResultSet, cExceptionHolder* pExceptionRet = nullptr, bool bWaitIfBusy = false);
68  HRESULT ExecuteSQLOrInsert(cSQLCmdUpdate& Update, cExceptionHolder* pExceptionRet = nullptr);
69  };
70 };
71 #endif // _INC_cSQLDatabasePool_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define FAILED(x)
Definition: HResult.h:30
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cSQLCmd.h:288
Definition: cSQLCmd.h:36
Definition: cSQLDatabasePool.h:18
bool isConfigured() const
Definition: cSQLDatabasePool.h:51
bool isOpen() const
Definition: cSQLDatabasePool.h:47
cSQLDatabasePtr get_Connection()
Definition: cSQLDatabasePool.h:57
ITERATE_t get_ConnectionCount() const
Definition: cSQLDatabasePool.h:43
int m_nMaxConnections
Definition: cSQLDatabasePool.h:24
TIMESYSD_t m_nMaxWait
Definition: cSQLDatabasePool.h:25
cStringF m_sConnectionString
string describing instructions of how to connect to the database. driver, URL etc.
Definition: cSQLDatabasePool.h:23
Definition: cSQLDatabase.h:30
Definition: cSQLStatement.h:33
ITERATE_t GetSize() const noexcept
Definition: cArray.h:137
bool IsEmpty() const noexcept
Definition: cString.h:176
Definition: cArrayRef.h:21
Definition: cException.h:28
Definition: cThreadLock.h:498
Definition: cMesh.h:22
class __DECL_IMPORT cSQLDatabasePool
Definition: cUIDManagerTable.h:24
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
int ITERATE_t
like size_t but signed
Definition: Index.h:28