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

mysqlpp::SQLQuery Class Reference

The base class for mysqlpp::Query. More...

#include <sql_query.h>

Inheritance diagram for mysqlpp::SQLQuery:

Inheritance graph
[legend]
Collaboration diagram for mysqlpp::SQLQuery:

Collaboration graph
[legend]
List of all members.

Public Methods

 SQLQuery ()
 Default constructor.

 SQLQuery (const SQLQuery &q)
 Create a query as a copy of another.

void parse ()
 Treat the contents of the query string as a template query.

std::string error () const
 Return the last error message that was set.

bool success () const
 Return true if the last query was successful.

 operator bool ()
 Return true if the last query was successful.

bool operator! ()
 Return true if the last query failed.

void reset ()
 Reset the query object so that it can be reused.

template<class T> SQLQuery & update (const T &o, const T &n)
 Build an UPDATE SQL query.

template<class T> SQLQuery & insert (const T &v)
 Build an INSERT SQL query for one record.

template<class Iter> SQLQuery & insert (Iter first, Iter last)
 Build an INSERT SQL query for multiple records.

template<class T> SQLQuery & replace (const T &v)
 Build a REPLACE SQL query.

std::string str ()
 Get built query as a null-terminated C++ string.

std::string str (query_reset r)
 Get built query as a null-terminated C++ string.

std::string str (SQLQueryParms &p)
 Get built query as a null-terminated C++ string.

std::string str (SQLQueryParms &p, query_reset r)
 Get built query as a null-terminated C++ string.


Public Attributes

SQLQueryParms def
 The default template parameters.


Protected Types

typedef const SQLStringss
 to keep parameters lists short

typedef SQLQueryParms parms
 abstraction; remove when Query and SQLQuery merge


Protected Methods

void proc (SQLQueryParms &p)
 Process a parameterized query list.


Protected Attributes

bool Success
 if true, last query succeeded

char * errmsg
 string explaining last query error

std::vector< SQLParseElementparsed
 List of template query parameters.

std::vector< std::string > parsed_names
 Maps template parameter position values to the corresponding parameter name.

std::map< std::string, int > parsed_nums
 Maps template parameter names to their position value.


Detailed Description

The base class for mysqlpp::Query.

One uses an object of this class to form queries that can be sent to the database server via the mysqlpp::Connection object.

This class is subclassed from std::stringstream. This means that you can form a SQL query using C++ stream idioms without having to create your own stringstream object and then dump that into the query object. And of course, it gets you all the benefits of C++ streams, such as type safety, which sprintf() and such do not offer. Although you can read from this object as you would any other stream, this is not recommended. It may fail in strange ways, and there is no support offered if you break it by doing so.

If you seek within the stream in any way, be sure to reset the stream pointer to the end before calling any of the SQLQuery-specific methods except for error() and success().


Member Function Documentation

std::string mysqlpp::SQLQuery::error   const [inline]
 

Return the last error message that was set.

This function has no real meaning at this level. It's overridden with useful behavior in the Query subclass.

template<class Iter>
SQLQuery& mysqlpp::SQLQuery::insert Iter    first,
Iter    last
[inline]
 

Build an INSERT SQL query for multiple records.

Parameters:
first  iterator pointing to first SSQLS to insert
last  iterator pointing to record past last SSQLS to insert

Reimplemented in mysqlpp::Query.

template<class T>
SQLQuery& mysqlpp::SQLQuery::insert const T &    v [inline]
 

Build an INSERT SQL query for one record.

Parameters:
v  SSQLS which will be inserted into v.table()

Reimplemented in mysqlpp::Query.

void mysqlpp::SQLQuery::parse  
 

Treat the contents of the query string as a template query.

This method sets up the internal structures used by all of the other members that accept template query parameters. See the "Template Queries" chapter in the user manual for more information.

template<class T>
SQLQuery& mysqlpp::SQLQuery::replace const T &    v [inline]
 

Build a REPLACE SQL query.

Parameters:
v  SSQLS containing data to insert into the table, or which will replace an existing record if this record matches another on a unique index

Reimplemented in mysqlpp::Query.

void mysqlpp::SQLQuery::reset  
 

Reset the query object so that it can be reused.

This erases the query string and the contents of the parameterized query element list.

std::string mysqlpp::SQLQuery::str SQLQueryParms   p,
query_reset    r
 

Get built query as a null-terminated C++ string.

Parameters:
p  template query parameters to use, overriding the ones this object holds, if any
r  if equal to RESET_QUERY, query object is cleared after this call

std::string mysqlpp::SQLQuery::str SQLQueryParms   p
 

Get built query as a null-terminated C++ string.

Parameters:
p  template query parameters to use, overriding the ones this object holds, if any

std::string mysqlpp::SQLQuery::str query_reset    r [inline]
 

Get built query as a null-terminated C++ string.

Parameters:
r  if equal to RESET_QUERY, query object is cleared after this call

template<class T>
SQLQuery& mysqlpp::SQLQuery::update const T &    o,
const T &    n
[inline]
 

Build an UPDATE SQL query.

Parameters:
o  SSQLS containing data to match in table
n  SSQLS that will replace any records in o.table() that match o

Reimplemented in mysqlpp::Query.


Member Data Documentation

SQLQueryParms mysqlpp::SQLQuery::def
 

The default template parameters.

Used for filling in parameterized queries.


The documentation for this class was generated from the following files:
Generated on Thu May 26 09:40:39 2005 for MySQL++ by doxygen1.2.18