Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cSQLDatabase Class Reference

#include <cSQLDatabase.h>

Inheritance diagram for GrayLib::cSQLDatabase:
GrayLib::cSQLBase Gray::cRefBase Gray::CObject Gray::cNonCopyable IUnknown

Public Member Functions

 cSQLDatabase ()
 
virtual ~cSQLDatabase ()
 
ISQLDatabaseget_ISQLDatabase () const
 
bool isConnected () const
 
bool IsExtReferenced (int nCheckVal=1) const
 
virtual cSQLDriverget_SQLDriver () const
 What driver ultimately owns this? More...
 
virtual cSQLBaseget_SQLParent () const
 
HRESULT OpenConnect (cStringF sConnectionString, cExceptionHolder *pExceptionHolder=nullptr, int iMaxRetries=3)
 
HRESULT RetryOpenConnect (cExceptionHolder *pExceptionHolder=nullptr, int iMaxRetries=100)
 
bool Close (bool bDestroyHandle)
 
bool get_AutoCommit () const
 
void put_AutoCommit (bool bAutoCommit)
 
const cSQLConfigDBGetConfigDB ()
 
HRESULT ExecuteSQLCmd (cSQLCmd &oCmd, cExceptionHolder *pExceptionRet=nullptr)
 
HRESULT ExecuteSQLAndFetch (cSQLCmd &oCmd, cSQLStatement &rResultSet, cExceptionHolder *pExceptionRet=nullptr, bool bWaitIfBusy=false)
 
HRESULT ExecuteSQLOrInsert (cSQLCmdUpdate &oCmdUpdate, cExceptionHolder *pExceptionRet)
 
HRESULT EndTransaction (bool bCommit)
 
- Public Member Functions inherited from GrayLib::cSQLBase
virtual ~cSQLBase ()
 
HRESULT FillException (cExceptionHolder &exh, cStringA sCommand, const cDebugSourceLine &src) const
 
HRESULT ReturnError1 (cExceptionHolder &exh) const
 
HRESULT ReturnError2 (cStringA sCommand, const cDebugSourceLine &src) const
 
bool isISQLValid () const
 The SQL handle. More...
 
ITERATE_t get_ChildHandleCount () const noexcept
 
- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 
- Public Member Functions inherited from Gray::cRefBase
 cRefBase (int iRefCount=0) noexcept
 
virtual ~cRefBase ()
 
int get_RefCount () const noexcept
 
HASHCODE_t get_HashCode () const noexcept
 
 STDMETHOD_ (HASHCODE_t, get_HashCodeX)() const noexcept
 
virtual void onFinalRelease ()
 
bool isValidObj () const noexcept
 
 STDMETHOD_ (ULONG, AddRef)(void) override
 
 STDMETHOD_ (ULONG, Release)(void) override
 
STDMETHOD() QueryInterface (const IID &riid, void __RPC_FAR *__RPC_FAR *ppvObject) override
 
void IncRefCount ()
 
void DecRefCount ()
 
bool isStaticConstruct () const noexcept
 
void StaticConstruct ()
 
void StaticDestruct ()
 
bool isDestructing () noexcept
 
void SetDestructing ()
 

Public Attributes

cSQLDriverm_pSQLDriver
 My parent. Not set until after OpenConnect and m_bIsConnected. More...
 
- Public Attributes inherited from GrayLib::cSQLBase
bool m_bLogOnError
 I want to log message if error. More...
 

Protected Member Functions

void ChangeCriticalWait (int iDelta)
 
HRESULT ReadConfigDB ()
 
bool AllocISQLDatabase (cSQLDriver *pSQLDriver)
 
HRESULT OpenConnectInt (cExceptionHolder *pExceptionHolder, int iMaxRetries, TIMESYS_t nTimeStart)
 
- Protected Member Functions inherited from GrayLib::cSQLBase
bool AttachISQL (ISQLBase *pSQL)
 
void FreeISQL ()
 
bool FreeISQLTested ()
 
 cSQLBase ()
 
- Protected Member Functions inherited from Gray::cNonCopyable
 cNonCopyable () noexcept
 Force the use of Factory creation via protected constructor. More...
 
 ~cNonCopyable () noexcept
 

Additional Inherited Members

- Static Public Member Functions inherited from GrayLib::cSQLBase
static const FILECHAR_t *GRAYCALL RemoveDriverIdentification (const FILECHAR_t *pszError)
 
- Protected Attributes inherited from GrayLib::cSQLBase
cIUnkPtr< ISQLBasem_pISQL
 ISQLBase to some SQL implementation object -> a Driver/environment, connection or recordset/statement. More...
 

Detailed Description

A connection to a database. Like System.Data.Common.DbConnection or System.Data.Odbc::OdbcConnection.

Note
We can only have one active cSQLStatement on this at any one time! or "MultipleActiveResultSets=True" ?
We may pool these for re-use. cSQLDatabasePool. Get this dynamically from cSQLDatabasePool.

Constructor & Destructor Documentation

◆ cSQLDatabase()

GrayLib::cSQLDatabase::cSQLDatabase ( )

◆ ~cSQLDatabase()

GrayLib::cSQLDatabase::~cSQLDatabase ( )
virtual

Member Function Documentation

◆ AllocISQLDatabase()

bool GrayLib::cSQLDatabase::AllocISQLDatabase ( cSQLDriver pSQLDriver)
protected

Create to the DB ISQLDriver interface object.

◆ ChangeCriticalWait()

void GrayLib::cSQLDatabase::ChangeCriticalWait ( int  iDelta)
protected

Warn the thread that this operation may take a long time.

◆ Close()

bool GrayLib::cSQLDatabase::Close ( bool  bDestroyHandle)

Close this connection to the DB.

◆ EndTransaction()

HRESULT GrayLib::cSQLDatabase::EndTransaction ( bool  bCommit)

may be part of put_AutoCommit(), Execute or called manually. SQLEndTran() replaces obsolete SQLTransact()

  • bCommit = false = try to undo the partial action.

◆ ExecuteSQLAndFetch()

HRESULT GrayLib::cSQLDatabase::ExecuteSQLAndFetch ( cSQLCmd oCmd,
cSQLStatement rResultSet,
cExceptionHolder pExceptionRet = nullptr,
bool  bWaitIfBusy = false 
)
Returns
0 = got data. HRESULT_WIN32_C(ERROR_NO_MORE_ITEMS) = We can fetch no data with this query. This is OK.

◆ ExecuteSQLCmd()

HRESULT GrayLib::cSQLDatabase::ExecuteSQLCmd ( cSQLCmd oCmd,
cExceptionHolder pExceptionRet = nullptr 
)

Exec the SQL command. ASSUME no result set is expected. (Insert,delete,etc) Similar to MFC CDatabase::ExecuteSQL()

◆ ExecuteSQLOrInsert()

HRESULT GrayLib::cSQLDatabase::ExecuteSQLOrInsert ( cSQLCmdUpdate oCmdUpdate,
cExceptionHolder pExceptionRet 
)

Update or insert whichever is needed.

Note
is this returns HRESULT_WIN32_C(ERROR_DS_BUSY) do i try again ?

◆ get_AutoCommit()

bool GrayLib::cSQLDatabase::get_AutoCommit ( ) const

◆ get_ISQLDatabase()

ISQLDatabase * GrayLib::cSQLDatabase::get_ISQLDatabase ( ) const

◆ get_SQLDriver()

virtual cSQLDriver* GrayLib::cSQLDatabase::get_SQLDriver ( ) const
inlinevirtual

What driver ultimately owns this?

Implements GrayLib::cSQLBase.

◆ get_SQLParent()

cSQLBase * GrayLib::cSQLDatabase::get_SQLParent ( ) const
virtual

Implements GrayLib::cSQLBase.

◆ GetConfigDB()

const cSQLConfigDB & GrayLib::cSQLDatabase::GetConfigDB ( )

◆ isConnected()

bool GrayLib::cSQLDatabase::isConnected ( ) const
inline

Is DB connected?

◆ IsExtReferenced()

bool GrayLib::cSQLDatabase::IsExtReferenced ( int  nCheckVal = 1) const

is this connection in use? (in a pool) May or may not be open connection.

◆ OpenConnect()

HRESULT GrayLib::cSQLDatabase::OpenConnect ( cStringF  sConnectionString,
cExceptionHolder pExceptionHolder = nullptr,
int  iMaxRetries = 3 
)

Open a connection to a database using the driver that matches the sConnectionString. see: http://www.codeguru.com/mfc/comments/44221.shtml –for details Similar to MFC CDatabase::OpenEx()

◆ OpenConnectInt()

HRESULT GrayLib::cSQLDatabase::OpenConnectInt ( cExceptionHolder pExceptionHolder,
int  iMaxRetries,
TIMESYS_t  nTimeStart 
)
protected

◆ put_AutoCommit()

void GrayLib::cSQLDatabase::put_AutoCommit ( bool  bAutoCommit)

auto SQL_COMMIT after Execute? makes all transactions COMMIT immediately. else we need to call EndTransaction(true) manually

◆ ReadConfigDB()

HRESULT GrayLib::cSQLDatabase::ReadConfigDB ( )
protected

Ask the DB/Driver about its capabilities. Populate m_ConfigDB.

◆ RetryOpenConnect()

HRESULT GrayLib::cSQLDatabase::RetryOpenConnect ( cExceptionHolder pExceptionHolder = nullptr,
int  iMaxRetries = 100 
)

Seems the connect has been broken! Try to re-open it. reconnect

Note
ASSUME all open recordset(s) on this database are now broken as well !
Returns
0 = OK

Member Data Documentation

◆ m_pSQLDriver

cSQLDriver* GrayLib::cSQLDatabase::m_pSQLDriver

My parent. Not set until after OpenConnect and m_bIsConnected.


The documentation for this class was generated from the following files: