libodbc++  0.2.5
Public Member Functions | List of all members
odbc::PreparedStatement Class Reference

A prepared statement. More...

#include <preparedstatement.h>

Inheritance diagram for odbc::PreparedStatement:
odbc::Statement odbc::ErrorHandler odbc::CallableStatement

Public Member Functions

virtual ~PreparedStatement ()
 Destructor.
 
void clearParameters ()
 Clears the parameters. More...
 
bool execute ()
 Executes this statement. More...
 
ResultSetexecuteQuery ()
 Executes this statement, assuming it returns a ResultSet. More...
 
int executeUpdate ()
 Executes this statement, assuming it returns an update count.
 
void setDouble (int idx, double val)
 Sets a parameter value to a double. More...
 
void setBoolean (int idx, bool val)
 Sets a parameter value to a bool. More...
 
void setByte (int idx, signed char val)
 Sets a parameter value to signed char. More...
 
void setBytes (int idx, const Bytes &val)
 Sets a parameter value to a chunk of bytes. More...
 
void setDate (int idx, const Date &val)
 Sets a parameter value to a Date. More...
 
void setFloat (int idx, float val)
 Sets a parameter value to a float. More...
 
void setInt (int idx, int val)
 Sets a parameter value to an int. More...
 
void setLong (int idx, Long val)
 Sets a parameter value to a Long. More...
 
void setShort (int idx, short val)
 Sets a parameter value to a short. More...
 
void setString (int idx, const std::string &val)
 Sets a parameter value to a string. More...
 
void setTime (int idx, const Time &val)
 Sets a parameter value to a Time. More...
 
void setTimestamp (int idx, const Timestamp &val)
 Sets a parameter value to a Timestamp. More...
 
void setAsciiStream (int idx, std::istream *s, int len)
 Sets a parameter value to an ascii stream. More...
 
void setBinaryStream (int idx, std::istream *s, int len)
 Sets a parameter value to a binary stream. More...
 
void setNull (int idx, int sqlType)
 Sets a parameter value to NULL. More...
 
- Public Member Functions inherited from odbc::Statement
virtual ~Statement ()
 Destructor. More...
 
ConnectiongetConnection ()
 Returns the connection that created this statement.
 
void cancel ()
 Cancel an ongoing operation that was executed in another thread.
 
virtual bool execute (const std::string &sql)
 Execute a given SQL statement. More...
 
virtual ResultSetexecuteQuery (const std::string &sql)
 Execute an SQL statement, expected to return a resultset. More...
 
virtual int executeUpdate (const std::string &sql)
 Execute an SQL statement, expected to return an update count. More...
 
int getUpdateCount ()
 Fetch the current result as an update count. More...
 
ResultSetgetResultSet ()
 Fetch the current result as a ResultSet.
 
bool getMoreResults ()
 Check if there are more results available on this statment. More...
 
void setCursorName (const std::string &name)
 Set the cursor name for this statement.
 
int getFetchSize ()
 Fetch the current fetch size (also called rowset size) for resultsets created by this statement.
 
void setFetchSize (int size)
 Set the current fetch size for resultsets created by this statement.
 
int getResultSetConcurrency ()
 Get the concurrency type for resultsets created by this statement.
 
int getResultSetType ()
 Get the type for resultsets created by this statement.
 
int getQueryTimeout ()
 Get the query timeout for this statement.
 
void setQueryTimeout (int seconds)
 Set the query timeout for this statement.
 
int getMaxRows ()
 Get the maximum number of rows to return in a resultset.
 
void setMaxRows (int maxRows)
 Set the maximum number of rows to return in a resultset.
 
int getMaxFieldSize ()
 Get the maximum field size for resultsets create by this statement.
 
void setMaxFieldSize (int maxFieldSize)
 Set the maximum field size for resultsets create by this statement.
 
void setEscapeProcessing (bool on)
 Sets escape processing on or off. More...
 
bool getEscapeProcessing ()
 Gets the current escape processing setting. More...
 
void close ()
 Closes all result sets from this execution. More...
 
- Public Member Functions inherited from odbc::ErrorHandler
void clearWarnings ()
 Clears all the warnings stored in this object.
 
WarningList * getWarnings ()
 Fetches all the warnings in this object. More...
 
virtual ~ErrorHandler ()
 Destructor.
 

Additional Inherited Members

- Protected Member Functions inherited from odbc::ErrorHandler
 ErrorHandler (bool collectWarnings=true)
 Constructor.
 

Detailed Description

A prepared statement.

A prepared statement is precompiled by the driver and/or datasource, and can be executed multiple times with different parameters.

Parameters are set using the setXXX methods. Note that it's advisable to use the set method compatible with the parameter's SQL type - for example, for a Types::DATE, setDate() should be used. Question marks ("?") are used in the SQL statement to represent a parameter, for example:

std::auto_ptr<PreparedStatement> pstmt(con->prepareStatement
   ("INSERT INTO SOMETABLE(AN_INTEGER_COL,A_VARCHAR_COL) VALUES(?,?)"));
pstmt->setInt(1,10);
pstmt->setString(2,"Hello, world!");
int affectedRows=pstmt->executeUpdate();
See Also
Connection::prepareStatement()

Member Function Documentation

void odbc::PreparedStatement::clearParameters ( )

Clears the parameters.

The set of parameters stays around until they are set again. To explicitly clear them (and thus release buffers held by the driver), this method should be called.

bool odbc::PreparedStatement::execute ( )

Executes this statement.

Returns
True if the result is a ResultSet, false if it's an update count or unknown.
ResultSet* odbc::PreparedStatement::executeQuery ( )

Executes this statement, assuming it returns a ResultSet.

Example: std::auto_ptr<ResultSet> rs(pstmt->executeQuery(s));

void odbc::PreparedStatement::setAsciiStream ( int  idx,
std::istream *  s,
int  len 
)

Sets a parameter value to an ascii stream.

Parameters
idxThe parameter index, starting at 1
sThe stream to assign
lenThe number of bytes available in the stream
void odbc::PreparedStatement::setBinaryStream ( int  idx,
std::istream *  s,
int  len 
)

Sets a parameter value to a binary stream.

Parameters
idxThe parameter index, starting at 1
sThe stream to assign
lenThe number of bytes available in the stream
void odbc::PreparedStatement::setBoolean ( int  idx,
bool  val 
)

Sets a parameter value to a bool.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setByte ( int  idx,
signed char  val 
)

Sets a parameter value to signed char.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setBytes ( int  idx,
const Bytes val 
)

Sets a parameter value to a chunk of bytes.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setDate ( int  idx,
const Date val 
)

Sets a parameter value to a Date.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setDouble ( int  idx,
double  val 
)

Sets a parameter value to a double.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setFloat ( int  idx,
float  val 
)

Sets a parameter value to a float.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setInt ( int  idx,
int  val 
)

Sets a parameter value to an int.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setLong ( int  idx,
Long  val 
)

Sets a parameter value to a Long.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setNull ( int  idx,
int  sqlType 
)

Sets a parameter value to NULL.

Parameters
idxThe parameter index, starting at 1
sqlTypeThe SQL type of the parameter
See Also
Types
void odbc::PreparedStatement::setShort ( int  idx,
short  val 
)

Sets a parameter value to a short.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setString ( int  idx,
const std::string &  val 
)

Sets a parameter value to a string.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setTime ( int  idx,
const Time val 
)

Sets a parameter value to a Time.

Parameters
idxThe parameter index, starting at 1
valThe value to set
void odbc::PreparedStatement::setTimestamp ( int  idx,
const Timestamp val 
)

Sets a parameter value to a Timestamp.

Parameters
idxThe parameter index, starting at 1
valThe value to set

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

Go back to the libodbc++ homepage