NCBI C++ ToolKit
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
CStatement Class Reference

Search Toolkit Book for CStatement

#include "stmt_impl.hpp"
(Private to src/dbapi.)

+ Inheritance diagram for CStatement:
+ Collaboration diagram for CStatement:

Classes

class  CStmtParamsMetaData
 

Public Member Functions

 CStatement (class CConnection *conn)
 
virtual ~CStatement ()
 
virtual IResultSetGetResultSet ()
 Get resulset. More...
 
virtual bool HasMoreResults ()
 Check for more results available. More...
 
virtual bool HasRows ()
 Check if resultset has rows. More...
 
virtual bool Failed ()
 Check if the statement failed. More...
 
virtual int GetRowCount ()
 Get total of rows returned. More...
 
virtual void SendSql (const string &sql)
 Sends one or more SQL statements to the SQL server. More...
 
virtual void Execute (const string &sql)
 Sends one or more SQL statements to the SQL server (NOTE: replaced by the SendSql()) More...
 
virtual void ExecuteUpdate (const string &sql)
 Executes SQL statement with no results returned. More...
 
virtual IResultSetExecuteQuery (const string &sql)
 Exectues SQL statement and returns the first resultset. More...
 
virtual void ExecuteLast ()
 Executes the last command (with changed parameters, if any). More...
 
virtual void PurgeResults ()
 Purge results. More...
 
virtual void Cancel ()
 Cancel statement. More...
 
virtual void Close ()
 Close statement. More...
 
virtual void SetParam (const CVariant &v, const CDBParamVariant &param)
 Set input/output parameter. More...
 
virtual void ClearParamList ()
 Clear parameter list. More...
 
virtual const IResultSetMetaDataGetParamsMetaData (void)
 Get input parameters metadata. More...
 
virtual IConnectionGetParentConn ()
 Get the parent connection. More...
 
virtual IWriterGetBlobWriter (I_BlobDescriptor &d, size_t blob_size, TBlobOStreamFlags flags)
 Get a writer for writing BLOBs using previously created CDB_BlobDescriptor. More...
 
virtual IWriterGetBlobWriter (I_BlobDescriptor &d, size_t blob_size, EAllowLog log_it)
 
virtual CNcbiOstreamGetBlobOStream (I_BlobDescriptor &d, size_t blob_size, TBlobOStreamFlags flags, size_t buf_size)
 Get an ostream for writing BLOBs using previously created CDB_BlobDescriptor. More...
 
virtual CNcbiOstreamGetBlobOStream (I_BlobDescriptor &d, size_t blob_size, EAllowLog log_it, size_t buf_size)
 
CConnectionGetConnection ()
 
CDB_ResultGetCDB_Result ()
 
CDB_LangCmdGetLangCmd ()
 
virtual void Action (const CDbapiEvent &e)
 
virtual void SetAutoClearInParams (bool flag=true)
 Set auto-clear input parameter flag. More...
 
virtual bool IsAutoClearInParams (void) const
 Get auto-clear input parameter flag value. More...
 
- Public Member Functions inherited from CActiveObject
 CActiveObject ()
 
virtual ~CActiveObject ()
 
void AddListener (CActiveObject *obj)
 
void RemoveListener (CActiveObject *obj)
 
void Notify (const CDbapiEvent &e)
 
string GetIdent () const
 
- Public Member Functions inherited from IEventListener
virtual ~IEventListener ()
 
- Public Member Functions inherited from IStatement
virtual ~IStatement ()
 Destructor. More...
 

Protected Member Functions

void x_Send (const string &sql)
 
void SetBaseCmd (I_BaseCmd *cmd)
 
I_BaseCmdGetBaseCmd ()
 
void CacheResultSet (CDB_Result *rs)
 
void SetFailed (bool f)
 
void FreeResources ()
 
- Protected Member Functions inherited from CActiveObject
void SetIdent (const string &name)
 
TLListGetListenerList ()
 
- Protected Member Functions inherited from IEventListener
 IEventListener ()
 

Private Types

typedef map< string, CVariant * > ParamList
 
typedef vector< CVariant * > ParamByPosList
 

Private Attributes

class CConnectionm_conn
 
I_BaseCmdm_cmd
 
CStmtParamsMetaData m_InParams
 
int m_rowCount
 
bool m_failed
 
ParamList m_params
 
ParamByPosList m_posParams
 
class CResultSetm_irs
 
class IWriterm_wr
 
class CWStreamm_ostr
 
bool m_AutoClearInParams
 

Additional Inherited Members

- Protected Types inherited from CActiveObject
typedef list< CActiveObject * > TLList
 

Detailed Description

Definition at line 46 of file stmt_impl.hpp.

Member Typedef Documentation

◆ ParamByPosList

typedef vector<CVariant*> CStatement::ParamByPosList
private

Definition at line 156 of file stmt_impl.hpp.

◆ ParamList

Definition at line 155 of file stmt_impl.hpp.

Constructor & Destructor Documentation

◆ CStatement()

CStatement::CStatement ( class CConnection conn)

Definition at line 94 of file stmt_impl.cpp.

References CActiveObject::SetIdent().

◆ ~CStatement()

CStatement::~CStatement ( )
virtual

Member Function Documentation

◆ Action()

void CStatement::Action ( const CDbapiEvent e)
virtual

◆ CacheResultSet()

void CStatement::CacheResultSet ( CDB_Result rs)
protected

Definition at line 124 of file stmt_impl.cpp.

References _TRACE, CActiveObject::AddListener(), CResultSet::Invalidate(), m_conn, and m_irs.

Referenced by HasMoreResults().

◆ Cancel()

void CStatement::Cancel ( )
virtual

Cancel statement.

Rolls back current transaction.

Implements IStatement.

Definition at line 381 of file stmt_impl.cpp.

References I_BaseCmd::Cancel(), GetBaseCmd(), and m_rowCount.

◆ ClearParamList()

void CStatement::ClearParamList ( )
virtual

◆ Close()

void CStatement::Close ( )
virtual

Close statement.

Implements IStatement.

Reimplemented in CCallableStatement.

Definition at line 338 of file stmt_impl.cpp.

References FreeResources(), and CActiveObject::Notify().

◆ Execute()

void CStatement::Execute ( const string sql)
virtual

Sends one or more SQL statements to the SQL server (NOTE: replaced by the SendSql())

Parameters
sqlSQL statement to execute.
Deprecated:
Use SendSql() instead

Implements IStatement.

Reimplemented in CCallableStatement.

Definition at line 217 of file stmt_impl.cpp.

References sql, and x_Send().

◆ ExecuteLast()

void CStatement::ExecuteLast ( )
virtual

Executes the last command (with changed parameters, if any).

Implements IStatement.

Definition at line 268 of file stmt_impl.cpp.

References map_checker< Container >::begin(), CDBParams::Bind(), map_checker< Container >::end(), CDB_LangCmd::GetBindParams(), CVariant::GetData(), GetLangCmd(), i, m_cmd, m_params, m_posParams, NCBI_DBAPI_THROW, and I_BaseCmd::Send().

Referenced by x_Send().

◆ ExecuteQuery()

IResultSet * CStatement::ExecuteQuery ( const string sql)
virtual

Exectues SQL statement and returns the first resultset.

If there is more than one resultset, the rest remain pending unless either PurgeResults() is called or next statement is run or the statement is closed. NOTE: Provided only for queries containing a single sql statement returning rows.

Parameters
sqlSQL statement to execute.
Returns
Pointer to result set. Ownership of IResultSet* belongs to IStatement. It is not allowed to use unique_ptr<> or other smart pointers to manage life-time of IResultSet*.

Implements IStatement.

Reimplemented in CCallableStatement.

Definition at line 247 of file stmt_impl.cpp.

References Failed(), GetResultSet(), HasMoreResults(), HasRows(), NCBI_DBAPI_THROW, SendSql(), and sql.

◆ ExecuteUpdate()

void CStatement::ExecuteUpdate ( const string sql)
virtual

Executes SQL statement with no results returned.

All resultsets are discarded.

Parameters
sqlSQL statement to execute.

Implements IStatement.

Reimplemented in CCallableStatement.

Definition at line 261 of file stmt_impl.cpp.

References PurgeResults(), SendSql(), and sql.

◆ Failed()

bool CStatement::Failed ( )
virtual

Check if the statement failed.

Returns
Return true, if the statement failed.

Implements IStatement.

Definition at line 322 of file stmt_impl.cpp.

References m_failed.

Referenced by ExecuteQuery().

◆ FreeResources()

void CStatement::FreeResources ( )
protected

◆ GetBaseCmd()

I_BaseCmd* CStatement::GetBaseCmd ( )
inlineprotected

Definition at line 124 of file stmt_impl.hpp.

References m_cmd.

Referenced by Cancel(), GetRowCount(), CCallableStatement::GetRpcCmd(), and HasMoreResults().

◆ GetBlobOStream() [1/2]

virtual CNcbiOstream& CStatement::GetBlobOStream ( I_BlobDescriptor d,
size_t  blob_size,
EAllowLog  log_it,
size_t  buf_size 
)
inlinevirtual

Reimplemented from IStatement.

Definition at line 93 of file stmt_impl.hpp.

References IStatement::GetBlobOStream().

◆ GetBlobOStream() [2/2]

CNcbiOstream & CStatement::GetBlobOStream ( I_BlobDescriptor d,
size_t  blob_size,
TBlobOStreamFlags  flags,
size_t  buf_size 
)
virtual

Get an ostream for writing BLOBs using previously created CDB_BlobDescriptor.

Parameters
dDescriptor
blob_sizeSize of BLOB to write
flags
See also
EBlobOStreamFlags.
Parameters
buf_sizeBuffer size, default 4096

Implements IStatement.

Definition at line 304 of file stmt_impl.cpp.

References flags, CRWStreambuf::fLogExceptions, CRWStreambuf::fOwnWriter, GetConnection(), and m_ostr.

◆ GetBlobWriter() [1/2]

virtual IWriter* CStatement::GetBlobWriter ( I_BlobDescriptor d,
size_t  blob_size,
EAllowLog  log_it 
)
inlinevirtual

Reimplemented from IStatement.

Definition at line 83 of file stmt_impl.hpp.

References IStatement::GetBlobWriter().

◆ GetBlobWriter() [2/2]

IWriter * CStatement::GetBlobWriter ( I_BlobDescriptor d,
size_t  blob_size,
TBlobOStreamFlags  flags 
)
virtual

Get a writer for writing BLOBs using previously created CDB_BlobDescriptor.

Parameters
dDescriptor
blob_sizeSize of BLOB to write
flags
See also
EBlobOStreamFlags.

Implements IStatement.

Definition at line 294 of file stmt_impl.cpp.

References flags, GetConnection(), and m_wr.

◆ GetCDB_Result()

CDB_Result * CStatement::GetCDB_Result ( )

Definition at line 317 of file stmt_impl.cpp.

References CResultSet::GetCDB_Result(), and m_irs.

Referenced by CCallableStatement::HasMoreResults().

◆ GetConnection()

CConnection* CStatement::GetConnection ( void  )
inline

Definition at line 101 of file stmt_impl.hpp.

References m_conn.

Referenced by GetBlobOStream(), and GetBlobWriter().

◆ GetLangCmd()

CDB_LangCmd * CStatement::GetLangCmd ( )

Definition at line 389 of file stmt_impl.cpp.

References m_cmd.

Referenced by ExecuteLast().

◆ GetParamsMetaData()

const IResultSetMetaData & CStatement::GetParamsMetaData ( void  )
virtual

Get input parameters metadata.

Returns
Pointer to result metadata.

Implements IStatement.

Definition at line 284 of file stmt_impl.cpp.

References m_InParams.

◆ GetParentConn()

IConnection * CStatement::GetParentConn ( )
virtual

Get the parent connection.

If the original connections was cloned, returns cloned connection.

Implements IStatement.

Definition at line 119 of file stmt_impl.cpp.

References m_conn.

◆ GetResultSet()

IResultSet * CStatement::GetResultSet ( )
virtual

Get resulset.

Returns
Pointer to resultset. For statements with no resultset return 0.

Implements IStatement.

Definition at line 142 of file stmt_impl.cpp.

References m_irs.

Referenced by ExecuteQuery(), and PurgeResults().

◆ GetRowCount()

int CStatement::GetRowCount ( )
virtual

Get total of rows returned.

Valid only after all rows are retrieved from a resultset. Even then, can be -1 if the server didn't indicate a count.

Implements IStatement.

Definition at line 327 of file stmt_impl.cpp.

References GetBaseCmd(), and m_rowCount.

◆ HasMoreResults()

bool CStatement::HasMoreResults ( )
virtual

Check for more results available.

Each call advances to the next result and the current one will be cancelled it not retrieved before next call. The amount of retured results may be bigger than the expected amount due to auxiliary results returned depending on the driver and server platform.

Returns
Return true, if there are more results available.

Implements IStatement.

Reimplemented in CCallableStatement.

Definition at line 147 of file stmt_impl.cpp.

References CacheResultSet(), GetBaseCmd(), I_BaseCmd::HasMoreResults(), m_rowCount, NULL, I_BaseCmd::Result(), I_BaseCmd::RowCount(), and SetFailed().

Referenced by ExecuteQuery(), CCallableStatement::HasMoreResults(), and PurgeResults().

◆ HasRows()

bool CStatement::HasRows ( )
virtual

Check if resultset has rows.

Returns
Return true, if resultset has rows.

Implements IStatement.

Definition at line 289 of file stmt_impl.cpp.

References m_irs.

Referenced by ExecuteQuery(), and PurgeResults().

◆ IsAutoClearInParams()

virtual bool CStatement::IsAutoClearInParams ( void  ) const
inlinevirtual

Get auto-clear input parameter flag value.

Returns
auto-clear input parameter flag value

Implements IStatement.

Definition at line 117 of file stmt_impl.hpp.

References m_AutoClearInParams.

Referenced by CCallableStatement::Execute(), and x_Send().

◆ PurgeResults()

void CStatement::PurgeResults ( )
virtual

Purge results.

Calls fetch for every resultset received until finished.

Implements IStatement.

Definition at line 364 of file stmt_impl.cpp.

References GetResultSet(), HasMoreResults(), HasRows(), and m_irs.

Referenced by CCallableStatement::ExecuteUpdate(), and ExecuteUpdate().

◆ SendSql()

void CStatement::SendSql ( const string sql)
virtual

Sends one or more SQL statements to the SQL server.

Parameters
sqlSQL statement to execute.

Implements IStatement.

Reimplemented in CCallableStatement.

Definition at line 222 of file stmt_impl.cpp.

References sql, and x_Send().

Referenced by ExecuteQuery(), and ExecuteUpdate().

◆ SetAutoClearInParams()

virtual void CStatement::SetAutoClearInParams ( bool  flag = true)
inlinevirtual

Set auto-clear input parameter flag.

Parameters
flagauto-clear input parameter flag In case when flag == true implicitly clear a statement's parameter list after each Execute, ExecuteUpdate and ExecuteQuery call. Default value

Implements IStatement.

Definition at line 114 of file stmt_impl.hpp.

References m_AutoClearInParams.

◆ SetBaseCmd()

void CStatement::SetBaseCmd ( I_BaseCmd cmd)
inlineprotected

Definition at line 123 of file stmt_impl.hpp.

References cmd, and m_cmd.

Referenced by CCallableStatement::CCallableStatement().

◆ SetFailed()

void CStatement::SetFailed ( bool  f)
inlineprotected

Definition at line 128 of file stmt_impl.hpp.

References f, and m_failed.

Referenced by CCallableStatement::Execute(), HasMoreResults(), and x_Send().

◆ SetParam()

void CStatement::SetParam ( const CVariant v,
const CDBParamVariant param 
)
virtual

◆ x_Send()

void CStatement::x_Send ( const string sql)
protected

Member Data Documentation

◆ m_AutoClearInParams

bool CStatement::m_AutoClearInParams
private

Definition at line 168 of file stmt_impl.hpp.

Referenced by IsAutoClearInParams(), and SetAutoClearInParams().

◆ m_cmd

I_BaseCmd* CStatement::m_cmd
private

Definition at line 159 of file stmt_impl.hpp.

Referenced by ExecuteLast(), FreeResources(), GetBaseCmd(), GetLangCmd(), SetBaseCmd(), and x_Send().

◆ m_conn

class CConnection* CStatement::m_conn
private

Definition at line 158 of file stmt_impl.hpp.

Referenced by CacheResultSet(), FreeResources(), GetConnection(), GetParentConn(), and x_Send().

◆ m_failed

bool CStatement::m_failed
private

Definition at line 162 of file stmt_impl.hpp.

Referenced by Failed(), and SetFailed().

◆ m_InParams

CStmtParamsMetaData CStatement::m_InParams
private

Definition at line 160 of file stmt_impl.hpp.

Referenced by GetParamsMetaData().

◆ m_irs

class CResultSet* CStatement::m_irs
private

◆ m_ostr

class CWStream* CStatement::m_ostr
private

Definition at line 167 of file stmt_impl.hpp.

Referenced by FreeResources(), and GetBlobOStream().

◆ m_params

ParamList CStatement::m_params
private

Definition at line 163 of file stmt_impl.hpp.

Referenced by ClearParamList(), ExecuteLast(), and SetParam().

◆ m_posParams

ParamByPosList CStatement::m_posParams
private

Definition at line 164 of file stmt_impl.hpp.

Referenced by ClearParamList(), ExecuteLast(), and SetParam().

◆ m_rowCount

int CStatement::m_rowCount
private

Definition at line 161 of file stmt_impl.hpp.

Referenced by Action(), Cancel(), FreeResources(), GetRowCount(), HasMoreResults(), and x_Send().

◆ m_wr

class IWriter* CStatement::m_wr
private

Definition at line 166 of file stmt_impl.hpp.

Referenced by FreeResources(), and GetBlobWriter().


The documentation for this class was generated from the following files:
Modified on Fri Sep 20 14:58:27 2024 by modify_doxy.py rev. 669887