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

#include <cSQLStatement.h>

Inheritance diagram for GrayLib::cSQLStatement:
GrayLib::cSQLBase IScriptableEnumerator Gray::CObject Gray::cNonCopyable GrayLib::cSQLStatementQ GrayLib::cScriptSourceSQLStatement

Public Member Functions

 cSQLStatement ()
 
virtual ~cSQLStatement ()
 
bool isConnected () const
 
virtual cSQLDriverget_SQLDriver () const
 What driver ultimately owns this? More...
 
virtual cSQLBaseget_SQLParent () const
 
virtual HRESULT ExecuteAndFetch (cSQLDatabase *pDatabase, cSQLCmd &oCmd, cExceptionHolder *pExceptionRet=nullptr)
 
virtual HRESULT FetchNext (bool bWaitIfBusy=false)
 
void ExecCancel ()
 
bool CloseStatement (bool bDrop=true, bool bThrowOnError=false)
 
bool Close ()
 
SQL_COLUMN_t GetColumnCount ()
 
cSQLColumnInfoGetColumnInfo (SQL_COLUMN_t iColumn=k_SQL_COL_FIRST)
 
SQL_COLUMN_t FindColumn (const char *pszFieldName)
 
SQL_COLUMN_t VerifyColumn (SQL_COLUMN_t iColumn, const char *pszFieldName)
 
bool GetColumnString (SQL_COLUMN_t iColumn, OUT cStringA &sResult)
 Get the data. string/chars is sometimes a special case here. More...
 
cStringA GetColumnStr (SQL_COLUMN_t iColumn=k_SQL_COL_FIRST)
 
int GetColumnInt (SQL_COLUMN_t iColumn=k_SQL_COL_FIRST)
 
virtual bool GetColumnVar (SQL_COLUMN_t iColumn, OUT cVariant &vValRet)
 
STDMETHOD() s_GetEnum (ITERATE_t i, OUT cStringA &rsPropName, OUT cVariant &vValRet) override
 
cStringA GetColumnStr (const char *pszFieldName)
 These are slightly dangerous to use. you MUST know the order of the select in advance! (or use cSQLStatementQ) More...
 
int GetColumnInt (const char *pszFieldName)
 
bool GetColumnVar (const char *pszFieldName, OUT cVariant &vVal)
 
- 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 Attributes

cStringA m_sFromTable
 usually the table name. used for error text. More...
 
- Public Attributes inherited from GrayLib::cSQLBase
bool m_bLogOnError
 I want to log message if error. More...
 

Protected Member Functions

ISQLStatementget_ISQLStatement () const
 
ITERATE_t ReadColumnCount ()
 
bool ReadColumnInfo (SQL_COLUMN_t iColumn, OUT cSQLColumnInfo &info)
 ODBC data type (SQL_C_BINARY) More...
 
bool AllocISQLStatement (const cSQLCmd &oCmd)
 
- 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
 

Protected Attributes

cSQLDatabasePtr m_pDatabase
 parent/source Database. More...
 
cArrayStruct< cSQLColumnInfom_aColumnInfo
 store metadata/description of the fields selected. 1 based. More...
 
- Protected Attributes inherited from GrayLib::cSQLBase
cIUnkPtr< ISQLBasem_pISQL
 ISQLBase to some SQL implementation object -> a Driver/environment, connection or recordset/statement. More...
 

Friends

class cSQLDatabase
 

Additional Inherited Members

- Static Public Member Functions inherited from GrayLib::cSQLBase
static const FILECHAR_t *GRAYCALL RemoveDriverIdentification (const FILECHAR_t *pszError)
 

Detailed Description

the results of the SQL select query command. Transient usually stack based. search for a group of records sequentially. Similar to .NET SQLReader. Raw use of SQLGetData() (must be called in sequential column order)

Constructor & Destructor Documentation

◆ cSQLStatement()

GrayLib::cSQLStatement::cSQLStatement ( )
Note
For as long as this statement is open we cannot make any modifications ?!?

◆ ~cSQLStatement()

GrayLib::cSQLStatement::~cSQLStatement ( )
virtual

if the database gets reconnected the record set is screwed and this will crash!

Member Function Documentation

◆ AllocISQLStatement()

bool GrayLib::cSQLStatement::AllocISQLStatement ( const cSQLCmd oCmd)
protected

◆ Close()

bool GrayLib::cSQLStatement::Close ( void  )

Get rid of the record set. no need to disconnect from the database at this point. yet.

◆ CloseStatement()

bool GrayLib::cSQLStatement::CloseStatement ( bool  bDrop = true,
bool  bThrowOnError = false 
)

Free my ISQLStatement in a different way.

Note
since this method gets called from a destructor, we've got to be able to turn of the throw on error logic or else serious program errors will result.
  • bDrop = SQL_DROP

◆ ExecCancel()

void GrayLib::cSQLStatement::ExecCancel ( )

Shutdown any pending query for CRecordset's hstmt's

◆ ExecuteAndFetch()

HRESULT GrayLib::cSQLStatement::ExecuteAndFetch ( cSQLDatabase pDatabase,
cSQLCmd oCmd,
cExceptionHolder pExceptionRet = nullptr 
)
virtual
Todo:
Support Asynchronous response from query/command? Assume a FetchNext() will be called next if there are MORE expected results. (NOT insert or delete)
Returns
HRESULT_WIN32_C(ERROR_DATABASE_FAILURE) = connect to database has been broken! HRESULT_WIN32_C(ERROR_NO_MORE_ITEMS) = no data for this. HRESULT_WIN32_C(ERROR_INVALID_TABLE) : Invalid or unknown table specified.

The query command is complete. Send it to the SQL server.

Reimplemented in GrayLib::cSQLStatementQ.

◆ FetchNext()

HRESULT GrayLib::cSQLStatement::FetchNext ( bool  bWaitIfBusy = false)
virtual

Fetches the next rowset of data from the result set (after exec) and returns data for all bound columns. Called after of ExecuteAndFetch() repeat calling this until we get all rows. Like MFC MoveNext(). http://msdn.microsoft.com/en-us/library/ms712424%28VS.85%29.aspx

Returns
0 = got data. HRESULT_WIN32_C(ERROR_NO_MORE_ITEMS) = We can fetch no data with this query. This is OK.

Reimplemented in GrayLib::cSQLStatementQ.

◆ FindColumn()

SQL_COLUMN_t GrayLib::cSQLStatement::FindColumn ( const char *  pszFieldName)

Find by name.

Returns
-1 = can't find it.

◆ get_ISQLStatement()

ISQLStatement * GrayLib::cSQLStatement::get_ISQLStatement ( ) const
protected

◆ get_SQLDriver()

cSQLDriver * GrayLib::cSQLStatement::get_SQLDriver ( ) const
virtual

What driver ultimately owns this?

Implements GrayLib::cSQLBase.

◆ get_SQLParent()

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

Implements GrayLib::cSQLBase.

◆ GetColumnCount()

SQL_COLUMN_t GrayLib::cSQLStatement::GetColumnCount ( )

Number of columns. not including column 0 Lazy load. read the format info for all the columns. Info specific to the current column. i.e. Current size of variable length fields and null state is not included of course.

Returns
number of columns
Note
Since columns are 1 based. this is the same as SQL_COLUMN_t max

◆ GetColumnInfo()

cSQLColumnInfo * GrayLib::cSQLStatement::GetColumnInfo ( SQL_COLUMN_t  iColumn = k_SQL_COL_FIRST)
  • iColumn = 1 based column k_SQL_COL_FIRST

◆ GetColumnInt() [1/2]

int GrayLib::cSQLStatement::GetColumnInt ( const char *  pszFieldName)
inline

Get column by name.

◆ GetColumnInt() [2/2]

int GrayLib::cSQLStatement::GetColumnInt ( SQL_COLUMN_t  iColumn = k_SQL_COL_FIRST)

iColumn = k_SQL_COL_FIRST

◆ GetColumnStr() [1/2]

cStringA GrayLib::cSQLStatement::GetColumnStr ( const char *  pszFieldName)
inline

These are slightly dangerous to use. you MUST know the order of the select in advance! (or use cSQLStatementQ)

Get column by name. like MFC GetFieldValue()

◆ GetColumnStr() [2/2]

cStringA GrayLib::cSQLStatement::GetColumnStr ( SQL_COLUMN_t  iColumn = k_SQL_COL_FIRST)

return the string immediately for this column in the current rowset returned.

◆ GetColumnString()

bool GrayLib::cSQLStatement::GetColumnString ( SQL_COLUMN_t  iColumn,
OUT cStringA sResult 
)

Get the data. string/chars is sometimes a special case here.

  • iColumn = 1 based column. (column=0 is special?) Get a data column from the current result set. Make ODBC convert to string for us.

◆ GetColumnVar() [1/2]

bool GrayLib::cSQLStatement::GetColumnVar ( const char *  pszFieldName,
OUT cVariant vVal 
)
inline

Get column by name.

◆ GetColumnVar() [2/2]

bool GrayLib::cSQLStatement::GetColumnVar ( SQL_COLUMN_t  iColumn,
OUT cVariant vValRet 
)
virtual

Get the data for the column as a variant.

  • iColumn = 1 based column. k_SQL_COL_FIRST
    Note
    it is an error to call SQLGetData for column 5 and then call it for column 4

Reimplemented in GrayLib::cSQLStatementQ.

◆ isConnected()

bool GrayLib::cSQLStatement::isConnected ( ) const

Is DB connected?

◆ ReadColumnCount()

ITERATE_t GrayLib::cSQLStatement::ReadColumnCount ( )
protected

Get number of columns not including column 0. So index can be equal to this !

◆ ReadColumnInfo()

bool GrayLib::cSQLStatement::ReadColumnInfo ( SQL_COLUMN_t  iColumn,
OUT cSQLColumnInfo info 
)
protected

ODBC data type (SQL_C_BINARY)

Get metadata/description of the column in the current data set.

  • iColumn = 1 based column. 0 = bookmark k_SQL_COL_FIRST

◆ s_GetEnum()

HRESULT GrayLib::cSQLStatement::s_GetEnum ( ITERATE_t  i,
OUT cStringA rsPropName,
OUT cVariant vValRet 
)
override

IScriptableEnumerator

  • i = 0 based.

◆ VerifyColumn()

SQL_COLUMN_t GrayLib::cSQLStatement::VerifyColumn ( SQL_COLUMN_t  iColumn,
const char *  pszFieldName 
)

If the select order is known. we should verify sanity.

Friends And Related Function Documentation

◆ cSQLDatabase

friend class cSQLDatabase
friend

Member Data Documentation

◆ m_aColumnInfo

cArrayStruct<cSQLColumnInfo> GrayLib::cSQLStatement::m_aColumnInfo
protected

store metadata/description of the fields selected. 1 based.

◆ m_pDatabase

cSQLDatabasePtr GrayLib::cSQLStatement::m_pDatabase
protected

parent/source Database.

◆ m_sFromTable

cStringA GrayLib::cSQLStatement::m_sFromTable

usually the table name. used for error text.


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