MySQL++  3.3.0
Enumerations | Functions
manip.h File Reference

Declares the Query stream manipulators and operators. More...

#include "common.h"
#include "myset.h"
#include "stadapter.h"
#include <iostream>

Go to the source code of this file.


enum  mysqlpp::quote_type0 { mysqlpp::quote }
enum  mysqlpp::quote_only_type0 { mysqlpp::quote_only }
enum  mysqlpp::quote_double_only_type0 { mysqlpp::quote_double_only }
enum  mysqlpp::escape_type0 { escape }
enum  mysqlpp::do_nothing_type0 { mysqlpp::do_nothing }
enum  mysqlpp::ignore_type0 { mysqlpp::ignore }


SQLQueryParms & mysqlpp::operator<< (escape_type2 p, SQLTypeAdapter &in)
 Inserts a SQLTypeAdapter into a stream, escaping special SQL characters. More...
ostream & mysqlpp::operator<< (escape_type1 o, const SQLTypeAdapter &in)
 Inserts anything that can be converted to SQLTypeAdapter into a stream, escaping special SQL characters as needed.

Detailed Description

Declares the Query stream manipulators and operators.

These manipulators let you automatically quote elements or escape characters that are special in SQL when inserting them into a Query stream. They make it easier to build syntactically-correct SQL queries.

This file also includes special operator<< definitions for a few key MySQL++ data types, since we know when to do automatic quoting and escaping for these types. This only works with Query streams, not regular std::ostreams, since we're only concerned with making correct SQL, not with presentation matters.

test/test_manip.cpp exercises the mechanisms defined here.

Enumeration Type Documentation

◆ do_nothing_type0

The 'do_nothing' manipulator.

Does exactly what it says: nothing. Used as a dummy manipulator when you are required to use some manipulator but don't want anything to be done to the following item. When used with SQLQueryParms it will make sure that it does not get formatted in any way, overriding any setting set by the template query.


insert into a std::ostream to override manipulation of next item

◆ escape_type0

The 'escape' manipulator.

SQL-escapes following argument if it is of a data type that may require escaping when inserted into a Query or SQLQueryParms stream. This is useful with string types, for example, to avoid bad SQL when they contain special characters like single quotes, nulls, and newlines. Data types like integers which never benefit from escaping don't get run through the escaping routine even if you ask for it.

◆ ignore_type0

The 'ignore' manipulator.

Only valid when used with SQLQueryParms. It's a dummy manipulator like the do_nothing manipulator, except that it will not override formatting set by the template query. It is simply ignored.


insert into a std::ostream as a dummy manipulator

◆ quote_double_only_type0

The 'double_quote_only' manipulator.

Similar to quote_only manipulator, except that it uses double quotes instead of single quotes.

You might care to use it when you have MySQL's ANSI_QUOTES mode enabled. In that mode, single quotes are used only for string literals, and double quotes for identifiers. Otherwise, quote_only and quote are quite sufficient.


insert into a std::ostream to double-quote next item

◆ quote_only_type0

The 'quote_only' manipulator.

Similar to quote manipulator, except that it doesn't escape special SQL characters.


insert into a std::ostream to single-quote next item

◆ quote_type0

The standard 'quote' manipulator. It is the most widely useful manipulator in MySQL++.

Insert this manipulator into a Query or SQLQueryParms stream to put single quotes around the next item in the stream, and escape any characters within it that are special in SQL, if the data type of the next item in the stream may require it. By contrast, Date objects only require escaping, not quoting, and integers never require either. The manipulators won't do work they know is not necessary to ensure syntactially-correct SQL.


insert into a Query stream to single-quote and escape next item

Function Documentation

◆ operator<<()

MYSQLPP_EXPORT SQLQueryParms & mysqlpp::operator<< ( escape_type2  p,
SQLTypeAdapter in 

Inserts a SQLTypeAdapter into a stream, escaping special SQL characters.

We actually only do the escaping if in.escape_q() returns true but in.dont_escape is not. If that is not the case, we insert the string data directly.