Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

look::DbQuery Class Reference

A class for managing a database query/SQL statement. More...

#include <dbquery.h>

List of all members.

Public Types

enum  QueryState {
  Q_CREATED, Q_PREPARED, Q_EXECUTED, Q_CURSOR_OPEN,
  Q_FINISHED
}

Public Methods

 DbQuery (const LookString &theQueryText="", DbConnection *theConnection=NULL)
 Constructor. More...

virtual ~DbQuery ()
 Destructor.

bool Prepare (void)
 Prepare. More...

bool Describe (void)
 Describe. Prepare calls this for you. More...

bool Execute (void)
 Execute. More...

long ColumnCount (void) const
 How many columns are in our query? More...

long RowCount (bool countNow=false)
 How many rows are in the result set. More...

LookString GetColumnName (long theColumnNo)
 Get the name of a column. More...

bool GetColumnNullable (long theColumnNo)
 Is the column nullable? More...

long GetColumnTypeID (long theColumnNo)
 What type will the data in the column be? More...

DbRowFetch ()
 Fetch the next row. More...

DbRowGetRow (long theRowNumber)
 Get row from cache. More...

void Close (void)
 Close our cursor.

void AddParameter (LookTypeBase *theParameter, bool isLong=false)
 Add a parameter. More...

void ClearParameters (void)
 Clear out all the parameters added so far.

void UseRowCache (void)
int GetNRowsAffected (void)

Protected Methods

void UploadParameters (void)
 Upload parameters (called by Execute()).

void TidyCursor (void)
bool IsPrepared (void) const
bool IsExecuted (void) const
bool CursorIsOpen (void) const

Protected Attributes

DbConnectionitsConnection
bool itOwnsConnection
LookString itsQueryText
QueryState itsState
long itsCurrentRowNumber
long itsRowCount
bool itHasRowCache
DbRowitsLastFetchedRow
DbRowPtrList itsRows
LookTypePtrList itsParameters
long itsLongParameterIndex
LOOK_STMT itsStmt
int itsRowsAffected

Static Protected Attributes

long itsNextStatementId


Detailed Description

A class for managing a database query/SQL statement.

A DbQuery is associated with a SQL Statement.

At the very least you need to Prepare() and Execute() it.

You may need to Fetch() rows.

Parameters can be used in the SQL statement - these must be marked with ? (eg "select * from columns where name = ?").

You must delete all queries on a connection before the connection.

The global connection must have been set before using this class (DbConnection::SetGlobalConnection()).


Constructor & Destructor Documentation

look::DbQuery::DbQuery ( const LookString & theQueryText = "",
DbConnection * theConnection = NULL )
 

Constructor.

If the connection is DbConnection::PERSISTENT_READ_ONLY a new connection is made just for this query.

Parameters:
theQueryText   The SQL statement.
theConnection   If this is null, the global connection is used (DbConnection::GetGlobalConnection()).


Member Function Documentation

void look::DbQuery::AddParameter ( LookTypeBase * theParameter,
bool isLong = false )
 

Add a parameter.

isLong is required for at least odbc and oci - long (as in database LONG, not integer long) parameters are treated slightly differently.

Parameters:
theParameter   The parameter. DbQuery takes its own copy.
isLong   Is the parameter a LONG? (or LONG RAW, etc)

long look::DbQuery::ColumnCount ( void ) const
 

How many columns are in our query?

The query must have been Prepare()d and probably ought to have results (!).

Eg "SELECT * FROM DUAL" on oracle will give 1.

Returns:
Number of columns.

bool look::DbQuery::Describe ( void )
 

Describe. Prepare calls this for you.

This shouldn't really be public - to describe a SQL Statement you ought to call Prepare().

Returns:
true if lookDbDescribe succeeded.

bool look::DbQuery::Execute ( void )
 

Execute.

Actually execute the statement.

If successful, the query state will be Q_CURSOR_OPEN if there are results to be returned, or Q_EXECUTED if none.

Any rows in the row cache will be cleared.

Returns:
true for success, false otherwise. DbError will contain any error.

DbRow * look::DbQuery::Fetch ( void )
 

Fetch the next row.

Returns:
Pointer to a new row fetched. If the rows are cached, this pointer is valid until the next Execute() or the DbQuery is deleted. Otherwise the pointer is valid until the next Fetch() or the DbQuery is deleted. (do not delete this pointer)

If there are no more rows to fetch, this returns 0 (null).

LookString look::DbQuery::GetColumnName ( long theColumnNo )
 

Get the name of a column.

Prepare() must have been called.

Parameters:
theColumnNo   Column index, 0 based.
Returns:
Column name

bool look::DbQuery::GetColumnNullable ( long theColumnNo )
 

Is the column nullable?

Prepare() must have been called.

Parameters:
theColumnNo   Column index, 0 based.
Returns:
true for NULL/WITH NULL, false for NOT NULL

long look::DbQuery::GetColumnTypeID ( long theColumnNo )
 

What type will the data in the column be?

Prepare() must have been called.

Parameters:
theColumnNo   Column index, 0 based.
Returns:
The ID of the datatype to be used, as defined in looktypes.h. This is a superset of the actual types, as for example LookLongStringID will actually be returned as a LookString.

DbRow * look::DbQuery::GetRow ( long theRowNumber )
 

Get row from cache.

Get theRowNumberth row from the row cache. If necessary, fetches are done to get the rows before. If there are insufficient rows, return 0.

The query must have been Execute()d and must have a row cache.

Returns:
Pointer to the row. This is valid until the next Execute() or the query is deleted.

bool look::DbQuery::Prepare ( void )
 

Prepare.

You need to call this before Execute().

Returns:
true for success, false otherwise. DbError will contain any error.

long look::DbQuery::RowCount ( bool countNow = false )
 

How many rows are in the result set.

The query must have been Prepare()d (and Execute()d?).

Parameters:
countNow   If true, all the rows are Fetch()ed. If there is no row cache, all these fetched rows will be thrown away.
Returns:
-1 if unknown, otherwise how many rows.


The documentation for this class was generated from the following files:
Generated at Thu Jan 17 12:53:08 2002 for liblookdb by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001