The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

SQLquery Class Reference

SQLquery provides a way to represent a query string, and its parameters in a type-safe way. More...

#include <m_sqlv2.h>

Inheritance diagram for SQLquery:

Inheritance graph
[legend]
Collaboration diagram for SQLquery:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SQLquery (const std::string &query)
 Initialize an SQLquery with a given format string only.
 SQLquery (const std::string &query, const ParamL &params)
 Initialize an SQLquery with a format string and parameters.
template<typename T>
SQLqueryoperator, (const T &foo)
 An overloaded operator for pushing parameters onto the parameter list.
template<typename T>
SQLqueryoperator% (const T &foo)
 An overloaded operator for pushing parameters onto the parameter list.

Public Attributes

std::string q
 The query 'format string'.
ParamL p
 The query parameter list There should be one parameter for every ? character within the format string shown above.

Detailed Description

SQLquery provides a way to represent a query string, and its parameters in a type-safe way.

C++ has no native type-safe way of having a variable number of arguments to a function, the workaround for this isn't easy to describe simply, but in a nutshell what's really happening when - from the above example - you do this:

SQLrequest foo = SQLrequest(this, target, "databaseid", SQLquery("SELECT (foo, bar) FROM rawr WHERE foo = '?' AND bar = ?", "Hello", "42"));

what's actually happening is functionally this:

SQLrequest foo = SQLrequest(this, target, "databaseid", query("SELECT (foo, bar) FROM rawr WHERE foo = '?' AND bar = ?").addparam("Hello").addparam("42"));

with 'query()' returning a reference to an object with a 'addparam()' member function which in turn returns a reference to that object. There are actually four ways you can create a SQLrequest..all have their disadvantages and advantages. In the real implementations the 'query()' function is replaced by the constructor of another class 'SQLquery' which holds the query string and a ParamL (std::deque<std::string>) of query parameters. This is essentially the same as the above example except 'addparam()' is replaced by operator,(). The full syntax for this method is:

SQLrequest foo = SQLrequest(this, target, "databaseid", (SQLquery("SELECT.. ?"), parameter, parameter));

Definition at line 152 of file m_sqlv2.h.


Constructor & Destructor Documentation

SQLquery::SQLquery const std::string query  )  [inline]
 

Initialize an SQLquery with a given format string only.

Definition at line 166 of file m_sqlv2.h.

SQLquery::SQLquery const std::string query,
const ParamL params
[inline]
 

Initialize an SQLquery with a format string and parameters.

If you provide parameters, you must initialize the list yourself if you choose to do it via this method, using std::deque::push_back().

Definition at line 175 of file m_sqlv2.h.


Member Function Documentation

template<typename T>
SQLquery& SQLquery::operator% const T &  foo  )  [inline]
 

An overloaded operator for pushing parameters onto the parameter list.

This has higher precedence than 'operator,' and can save on parenthesis.

Definition at line 191 of file m_sqlv2.h.

References ConvToStr(), and p.

template<typename T>
SQLquery& SQLquery::operator, const T &  foo  )  [inline]
 

An overloaded operator for pushing parameters onto the parameter list.

Definition at line 182 of file m_sqlv2.h.

References ConvToStr(), and p.


Member Data Documentation

ParamL SQLquery::p
 

The query parameter list There should be one parameter for every ? character within the format string shown above.

Definition at line 162 of file m_sqlv2.h.

Referenced by SQLConnection::DoLeadingQuery(), SQLConn::DoQuery(), operator%(), operator,(), and SQLConn::Query().

std::string SQLquery::q
 

The query 'format string'.

Definition at line 157 of file m_sqlv2.h.

Referenced by SQLConn::DoConnectedPoll(), SQLConnection::DoLeadingQuery(), SQLConn::DoQuery(), and SQLConn::Query().


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