fastcgi++
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
ASql::QueryPar Class Reference

Parent class for storing query data to be passed and retrieved from statements. More...

#include <query.hpp>

Inheritance diagram for ASql::QueryPar:
ASql::Query< Parameters, Results, ParametersParent, ResultsParent > ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type > ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type > ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, void > ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Parameters > >::type, void > ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type > ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type > ASql::Query< void, void, void, void >

List of all members.

Classes

struct  SharedData
 Sub-structure to store shared data for the query. More...

Public Member Functions

 QueryPar (const QueryPar &x)
 Calling the copy constructor will not set FLAG_ORIGINAL or create new shared data.
 ~QueryPar ()
 If the original object and keepalive is not turned on, cancel() is called.
unsigned int insertId () const
 Returns the insert ID returned from the query or 0 if nothing.
unsigned int rows () const
 Returns the rows affected/available from the query or 0 if nothing.
bool busy () const
 Returns true if copies of this query still exist (query is still working in another thread).
Error error () const
 Return the error object associated with the query.
void setCallback (boost::function< void()> callback=boost::function< void()>())
 Set the callback function to be called at the end of the query.
bool isCallback ()
 Return true if a callback is associated with this query.
boost::function< void()> getCallback ()
 Get the callback function.
void keepAlive (bool x)
 Set true if you want the query to not be cancelled when the original object is destroyed.
void cancel ()
 Call this function to cancel the query.
void enableRows ()
 Call this function to enable the retrieval of a row count (affected/available rows)
void enableInsertId ()
 Call this function to enable the retrieval of an auto-increment insert ID.
void reset ()
 Resets the object as though it was destroyed and reconstructed anew.

Protected Member Functions

 QueryPar (bool singleParameters, bool singleResults)
 Constructed by derived classes.
void setResults (void *results)
 Set's the shared data to point to the passed pointer.
void setParameters (void *parameters)
 Set's the shared data to point to the passed pointer.
void * relinquishResults ()
 Relinquishes control over the result data.
void * relinquishParameters ()
 Relinquishes control over the parameter data.
void * results ()
 Return a void pointer to the result set.
const void * results () const
 Return a const void pointer to the result set.
void * parameters ()
 Return a void pointer to the parameter set.
const void * parameters () const
 Return a const void pointer to the parameter set.

Private Types

enum  Flags { FLAG_ORIGINAL = 1, FLAG_KEEPALIVE = 1<<1 }

Private Member Functions

void callback ()
 Lock and call the callback function of it exists.
void clearResults ()
void clearParameters ()

Private Attributes

boost::shared_ptr< SharedDatam_sharedData
 Shared pointer to query data.
unsigned char m_flags
 Flags for individual query object.

Friends

class ConnectionPar

Detailed Description

Parent class for storing query data to be passed and retrieved from statements.

Most of the data is stored in a shared data structure that is referenced by copies of a QueryPar object. The only non-shared data stored in the class is the m_flags object which set's two possible flags. If the query is built from the default constructor, the FLAG_ORIGINAL flag is set. This serves the purpose of keeping track of which query object actually owns the original data. With this, one can have the query cancelled in it's handler thread if the original query object goes out of scope in it's own thread. If one wishes to avoid this behaviour they can have the FLAG_KEEPALIVE flag set with the keepAlive() function.

See also:
Query

Definition at line 27 of file query.hpp.


Member Enumeration Documentation

enum ASql::QueryPar::Flags [private]
Enumerator:
FLAG_ORIGINAL 
FLAG_KEEPALIVE 

Definition at line 138 of file query.hpp.


Constructor & Destructor Documentation

ASql::QueryPar::QueryPar ( bool  singleParameters,
bool  singleResults 
) [inline, protected]

Constructed by derived classes.

Parameters:
[in]singleParametersSet to true if the parameter set is a single row
[in]singleResultsSet to true if the result set is a single row

Definition at line 159 of file query.hpp.

References ASql::QueryPar::SharedData::FLAG_SINGLE_PARAMETERS, ASql::QueryPar::SharedData::FLAG_SINGLE_RESULTS, and m_sharedData.

ASql::QueryPar::QueryPar ( const QueryPar x) [inline]

Calling the copy constructor will not set FLAG_ORIGINAL or create new shared data.

Parameters:
xMay be a copy or original QueryPar object.

Definition at line 242 of file query.hpp.

If the original object and keepalive is not turned on, cancel() is called.

Definition at line 245 of file query.hpp.

References cancel(), FLAG_ORIGINAL, and m_flags.


Member Function Documentation

bool ASql::QueryPar::busy ( ) const [inline]

Returns true if copies of this query still exist (query is still working in another thread).

Definition at line 263 of file query.hpp.

References m_sharedData.

void ASql::QueryPar::callback ( ) [inline, private]

Lock and call the callback function of it exists.

Definition at line 141 of file query.hpp.

References m_sharedData.

Referenced by ASql::ConnectionPar< T >::intHandler(), and setCallback().

void ASql::QueryPar::cancel ( ) [inline]

Call this function to cancel the query.

This will cancel the query at the earliest opportunity. Calling a cancel will rollback any changes in the associated transaction.

Definition at line 301 of file query.hpp.

References m_sharedData.

Referenced by ~QueryPar().

void ASql::QueryPar::clearParameters ( ) [inline, private]

Definition at line 149 of file query.hpp.

References m_sharedData.

void ASql::QueryPar::clearResults ( ) [inline, private]

Definition at line 148 of file query.hpp.

References m_sharedData.

Referenced by ASql::ConnectionPar< T >::intHandler().

void ASql::QueryPar::enableInsertId ( ) [inline]

Call this function to enable the retrieval of an auto-increment insert ID.

Definition at line 311 of file query.hpp.

References m_sharedData.

void ASql::QueryPar::enableRows ( ) [inline]

Call this function to enable the retrieval of a row count (affected/available rows)

Definition at line 304 of file query.hpp.

References m_sharedData.

Error ASql::QueryPar::error ( ) const [inline]

Return the error object associated with the query.

Note this will be a default Error object if there was no error.

Definition at line 269 of file query.hpp.

References m_sharedData.

boost::function<void()> ASql::QueryPar::getCallback ( ) [inline]

Get the callback function.

Definition at line 285 of file query.hpp.

References m_sharedData.

Referenced by ASql::ConnectionPar< T >::intHandler().

unsigned int ASql::QueryPar::insertId ( ) const [inline]

Returns the insert ID returned from the query or 0 if nothing.

Definition at line 253 of file query.hpp.

References m_sharedData.

bool ASql::QueryPar::isCallback ( ) [inline]

Return true if a callback is associated with this query.

Definition at line 282 of file query.hpp.

References m_sharedData.

Referenced by ASql::ConnectionPar< T >::intHandler().

void ASql::QueryPar::keepAlive ( bool  x) [inline]

Set true if you want the query to not be cancelled when the original object is destroyed.

Note that the default is to cancel and this must be called from the original query object.

Definition at line 294 of file query.hpp.

References FLAG_KEEPALIVE, and m_flags.

Referenced by reset().

void* ASql::QueryPar::parameters ( ) [inline, protected]

Return a void pointer to the parameter set.

Usually you would keep the original typed pointer around but if you lost it for some reason you can use this and cast it.

Reimplemented in ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Parameters > >::type, void >, ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, void >, ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >, and ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >.

Definition at line 228 of file query.hpp.

References m_sharedData.

Referenced by ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::createParameters(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::createParameters(), ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, void >::createParameters(), ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Parameters > >::type, void >::createParameters(), ASql::ConnectionPar< T >::intHandler(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::parameters(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::parameters(), ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, void >::parameters(), ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Parameters > >::type, void >::parameters(), and setParameters().

const void* ASql::QueryPar::parameters ( ) const [inline, protected]
void* ASql::QueryPar::relinquishParameters ( ) [inline, protected]

Relinquishes control over the parameter data.

Calling this will disassociate the query object (and it's copies) from the parameter data but won't delete it. Use this if you are done with your query object but want to keep your parameter data around. The end result in the query object (and it's copies) is to have no parameter data associated with it.

Returns:
Pointer to the disassociated parameter data

Reimplemented in ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Parameters > >::type, void >, ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, void >, ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >, and ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >.

Definition at line 207 of file query.hpp.

References m_sharedData.

Referenced by ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::relinquishParameters(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::relinquishParameters(), ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, void >::relinquishParameters(), and ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Parameters > >::type, void >::relinquishParameters().

void* ASql::QueryPar::relinquishResults ( ) [inline, protected]

Relinquishes control over the result data.

Calling this will disassociate the query object (and it's copies) from the result data but won't delete it. Use this if you are done with your query object but want to keep your result data around. The end result in the query object (and it's copies) is to have no result data associated with it.

Returns:
Pointer to the disassociated result data

Reimplemented in ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >, ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >, ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >, and ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >.

Definition at line 195 of file query.hpp.

References m_sharedData.

Referenced by ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::relinquishResults(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::relinquishResults(), ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::relinquishResults(), and ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::relinquishResults().

void ASql::QueryPar::reset ( ) [inline]

Resets the object as though it was destroyed and reconstructed anew.

Definition at line 318 of file query.hpp.

References FLAG_ORIGINAL, keepAlive(), m_flags, and m_sharedData.

void* ASql::QueryPar::results ( ) [inline, protected]

Return a void pointer to the result set.

Usually you would keep the original typed pointer around but if you lost it for some reason you can use this and cast it.

Reimplemented in ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >, ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >, ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >, and ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >.

Definition at line 214 of file query.hpp.

References m_sharedData.

Referenced by ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::createResults(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::createResults(), ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::createResults(), ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::createResults(), ASql::ConnectionPar< T >::intHandler(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::results(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::results(), ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::results(), ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::results(), and setResults().

const void* ASql::QueryPar::results ( ) const [inline, protected]
unsigned int ASql::QueryPar::rows ( ) const [inline]

Returns the rows affected/available from the query or 0 if nothing.

Note that if using for the number of rows from a query this will represent the number of rows available before a LIMIT.

Definition at line 260 of file query.hpp.

References m_sharedData.

void ASql::QueryPar::setCallback ( boost::function< void()>  callback = boost::function<void()>()) [inline]

Set the callback function to be called at the end of the query.

Note that this will be called even if there is an error or the query can cancelled.

Definition at line 275 of file query.hpp.

References callback(), and m_sharedData.

Referenced by ASql::ConnectionPar< T >::intHandler().

void ASql::QueryPar::setParameters ( void *  parameters) [inline, protected]

Set's the shared data to point to the passed pointer.

Note that the QueryPar class assumes responsibility for destroying the parameter set unless explicitly released with relinquishParameters().

Parameters:
[in]parametersA pointer to the parameter data

Definition at line 183 of file query.hpp.

References m_sharedData, and parameters().

Referenced by ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::createParameters(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::createParameters(), ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, void >::createParameters(), ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Parameters > >::type, void >::createParameters(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::setParameters(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::setParameters(), ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, void >::setParameters(), and ASql::Query< Parameters, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Parameters > >::type, void >::setParameters().

void ASql::QueryPar::setResults ( void *  results) [inline, protected]

Set's the shared data to point to the passed pointer.

Note that the QueryPar class assumes responsibility for destroying the result set unless explicitly released with relinquishResults().

Parameters:
[out]resultsA pointer to the result data

Definition at line 174 of file query.hpp.

References m_sharedData, and results().

Referenced by ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::createResults(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::createResults(), ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::createResults(), ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::createResults(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::setResults(), ASql::Query< Parameters, Results, typename boost::enable_if< boost::is_base_of< Data::Set, Parameters > >::type, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::setResults(), ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::Set, Results > >::type >::setResults(), and ASql::Query< void, Results, void, typename boost::enable_if< boost::is_base_of< Data::SetContainer, Results > >::type >::setResults().


Friends And Related Function Documentation

friend class ConnectionPar [friend]

Definition at line 151 of file query.hpp.


Member Data Documentation

unsigned char ASql::QueryPar::m_flags [private]

Flags for individual query object.

FLAG_ORIGINAL: Set only if this query object was constructed with the default constructor. Never set if constructed from the copy constructor.

FLAG_KEEPALIVE: Set if the query should not be cancelled if the original object goes out of scope before the query is complete.

Definition at line 136 of file query.hpp.

Referenced by keepAlive(), reset(), and ~QueryPar().

boost::shared_ptr<SharedData> ASql::QueryPar::m_sharedData [private]

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