dtl


DBStmt

Category: utilities Component type: type

Description

The DBStmt object manages a single ODBC statement, such as INSERT, SELECT, UPDATE or native SQL strings that need to be passed through to the database which do not return values. For more complex ODBC statements that need runtime parameters or return result sets you may need to use sql_iterator which can support more general types of operations than a DBStmt.

Definition

Defined in the DBStmt.h header file.

Refinement of

None.

Associated types

None.

Example: Executing a SQL Statement Directly via DBStmt

int main(int argc, char **argv)
{
  DBConnection::GetDefaultConnection().Connect("UID=example;PWD=example;DSN=example;");
  DBStmt("DELETE FROM DB_EXAMPLE").Execute();
  DBStmt("INSERT INTO DB_EXAMPLE SELECT * FROM DB_EXAMPLE_BACKUP").Execute();
}

Public Base Classes

ValidatedObject

Notation

X A type that is a model of DBStmt
a Object of type X

Expression semantics

Name Expression Precondition Semantics Postcondition
Constructor
X a(string query, 
DBConnection &connection = DBConnection::GetDefaultConnection(),
bool bPrepare = false)
  Creates an ODBC statement using the string in query and the DBConnection object specified by connection. If no connection object is passed in to the constructor, the default connection object is used. If bPrepare is true, the SQL statement is SQLPrepared against the database at construction time so that Execute() can run quickly if it needs to be called multiple times. However, if bPrepare is false, then the statement is run using SQLExecDirect().  
Execute a statement
Execute()
  Execute the SQL string held by the statement.  
Find the number of rows affected by a statement
long RowCount()
  Return the number of rows affected after Executing statement. Mostly useful for update or delete statements to test for success or failure.  
Swap with another connection
void swap(X &other)
  Swap *this with other.  
Get next result set if one exists bool MoreResults()   Get the next result set for this statement if one exists. Return whether the statement actually grabbed another result set.  
Set statement attribute void SetStmtAttr(SQLINTEGER Attribute, SDWORD Value, SQLINTEGER StringLength)   Sets the Attribute passed in to Value. StringLength specifies the length of the parameter (such as SQL_IS_INTEGER). Note that the new attribute value will override the defaults used by DBStmt. This operation must be called before the statement is initialized in order for the attributes to actually be set.  
Set prepare flag void SetPrepare(bool bPrepare)   If bPrepare is true, the statement will execute using SQLPrepare() and SQLExecute(), else it will use SQLExecDirect(). This operation must be called before the statement is initialized in order for the prepare setting to be set.  
Get prepare flag bool GetPrepare() const   Returns the prepare flag.  
Log all SQL statements executed by DTL.
EnableLog()
DisableLog()
ClearLog()
IsLogEnabled()
  Support the logging of all SQL executed by DTL through the use of DBStmt::PrintLog(tostream &o). To turn logging on, use DBStmt::EnableLog(). To turn logging off, use DBStmt::DisableLog() To clear out the SQL log, use DBStmt::ClearLog(). To inquire if the log is currently enabled, use DBStmt::IsLogEnabled(). All of these functions are static members of DBStmt. SQL logging is turned off by default.  

Notes

See also

DBConnection, DBView, IndexedDBView, ValidatedObject


[DTL Home]

Copyright 2002, Michael Gradman and Corwin Joy.

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Corwin Joy and Michael Gradman make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

SourceForge Logo

This site written using the ORB. [The ORB]