MySQL 9.3.0
Source Code Documentation
mysqlrouter::sqlstring Class Reference

#include <utils_sqlstring.h>

Classes

class  CustomContainerIterator
 Iterator wrapper, for serializing arrays of structures to string. More...
 
struct  sqlstringformat
 

Public Member Functions

 sqlstring ()
 
 sqlstring (const char *format_string, const sqlstringformat format=0)
 
 sqlstring (const sqlstring &copy)
 
sqlstringoperator= (const sqlstring &)=default
 
bool done () const
 
void reset (const char *format_string, const sqlstringformat format=0)
 
 operator std::string () const
 
std::string str () const
 
bool is_empty () const
 
bool operator== (const sqlstring &other) const
 
sqlstringoperator<< (const sqlstringformat)
 modifies formatting options More...
 
sqlstringoperator<< (const float val)
 replaces a ? in the format string with a float numeric value More...
 
sqlstringoperator<< (const double)
 replaces a ? in the format string with a double numeric value More...
 
sqlstringoperator<< (const std::nullptr_t)
 replaces a ? in the format string with a NULL value. More...
 
sqlstringoperator<< (const std::string &)
 replaces a ? in the format string with a quoted string value or ! with a back-quoted identifier value More...
 
sqlstringoperator<< (const char *)
 replaces a ? in the format string with a quoted string value or ! with a back-quoted identifier value is the value is NULL, ? will be replaced with a NULL. More...
 
sqlstringoperator<< (const sqlstring &)
 replaces a ? or ! with the content of the other string verbatim More...
 
sqlstringoperator<< (const std::vector< uint8_t > &v)
 replaces a ? with an array of bytes More...
 
sqlstringappend_preformatted (const sqlstring &s)
 appends a pre-formatted sqlstring to a pre-formatted sqlstring More...
 
sqlstringappend_preformatted_sep (const std::string &separator, const sqlstring &s)
 
template<typename T >
sqlstringoperator<< (const std::pair< T, T > &iterators)
 Replace ? or ! with multiple values. More...
 
template<typename T >
sqlstringoperator<< (const std::vector< T > &values)
 
template<typename T >
sqlstringoperator<< (const std::set< T > &values)
 
template<typename T >
sqlstringoperator<< (const T value)
 replaces a ? in the format string with any integer numeric value More...
 

Static Public Attributes

static const sqlstring empty {""}
 
static const sqlstring null
 
static const sqlstring end
 

Private Member Functions

std::string consume_until_next_escape ()
 
int next_escape ()
 
void lock_escape (int esc)
 
void unlock_escape ()
 
sqlstringappend (const std::string &s)
 
sqlstringformat (int esc, const char *v, int length)
 

Private Attributes

std::string _formatted
 
std::string _format_string_left
 
sqlstringformat _format
 
int _locked_escape {0}
 

Constructor & Destructor Documentation

◆ sqlstring() [1/3]

mysqlrouter::sqlstring::sqlstring ( )

◆ sqlstring() [2/3]

mysqlrouter::sqlstring::sqlstring ( const char *  format_string,
const sqlstringformat  format = 0 
)

◆ sqlstring() [3/3]

mysqlrouter::sqlstring::sqlstring ( const sqlstring copy)
default

Member Function Documentation

◆ append()

sqlstring & mysqlrouter::sqlstring::append ( const std::string &  s)
private

◆ append_preformatted()

sqlstring & mysqlrouter::sqlstring::append_preformatted ( const sqlstring s)

appends a pre-formatted sqlstring to a pre-formatted sqlstring

◆ append_preformatted_sep()

sqlstring & mysqlrouter::sqlstring::append_preformatted_sep ( const std::string &  separator,
const sqlstring s 
)

◆ consume_until_next_escape()

std::string mysqlrouter::sqlstring::consume_until_next_escape ( )
private

◆ done()

bool mysqlrouter::sqlstring::done ( ) const

◆ format()

sqlstring & mysqlrouter::sqlstring::format ( int  esc,
const char *  v,
int  length 
)
inlineprivate

◆ is_empty()

bool mysqlrouter::sqlstring::is_empty ( ) const

◆ lock_escape()

void mysqlrouter::sqlstring::lock_escape ( int  esc)
private

◆ next_escape()

int mysqlrouter::sqlstring::next_escape ( )
private

◆ operator std::string()

mysqlrouter::sqlstring::operator std::string ( ) const

◆ operator<<() [1/12]

sqlstring & mysqlrouter::sqlstring::operator<< ( const char *  v)

replaces a ? in the format string with a quoted string value or ! with a back-quoted identifier value is the value is NULL, ? will be replaced with a NULL.

! will raise an exception

◆ operator<<() [2/12]

sqlstring & mysqlrouter::sqlstring::operator<< ( const double  v)

replaces a ? in the format string with a double numeric value

◆ operator<<() [3/12]

sqlstring & mysqlrouter::sqlstring::operator<< ( const float  val)
inline

replaces a ? in the format string with a float numeric value

◆ operator<<() [4/12]

sqlstring & mysqlrouter::sqlstring::operator<< ( const sqlstring v)

replaces a ? or ! with the content of the other string verbatim

◆ operator<<() [5/12]

sqlstring & mysqlrouter::sqlstring::operator<< ( const sqlstringformat  format)

modifies formatting options

◆ operator<<() [6/12]

sqlstring & mysqlrouter::sqlstring::operator<< ( const std::nullptr_t  )

replaces a ? in the format string with a NULL value.

◆ operator<<() [7/12]

template<typename T >
sqlstring & mysqlrouter::sqlstring::operator<< ( const std::pair< T, T > &  iterators)
inline

Replace ? or ! with multiple values.

Each element of the container, is going to be applied to parameter type fetched at the start (either ? or !). Each iteam is going to be separated by comma.

Example 1:

 sqlstring s{"First=(?) Second=(!)"};
 s << std::vector<std::string>{"1","2","3"} << "a";

The resulting query: First=("1","2","3") Second=(A)

Example 2:

 sqlstring s{"First=(!) Second=(?)"};
 s << std::vector<std::string>{"1","2","3"} << "a";

The resulting query: First=(1,2,3) Second=("A")

◆ operator<<() [8/12]

template<typename T >
sqlstring & mysqlrouter::sqlstring::operator<< ( const std::set< T > &  values)
inline

◆ operator<<() [9/12]

sqlstring & mysqlrouter::sqlstring::operator<< ( const std::string &  v)

replaces a ? in the format string with a quoted string value or ! with a back-quoted identifier value

◆ operator<<() [10/12]

template<typename T >
sqlstring & mysqlrouter::sqlstring::operator<< ( const std::vector< T > &  values)
inline

◆ operator<<() [11/12]

sqlstring & mysqlrouter::sqlstring::operator<< ( const std::vector< uint8_t > &  v)

replaces a ? with an array of bytes

◆ operator<<() [12/12]

template<typename T >
sqlstring & mysqlrouter::sqlstring::operator<< ( const T  value)
inline

replaces a ? in the format string with any integer numeric value

Import to_string function which enables serialization to string, for standard types.

User can define to_string function for serialization of custom type. Both the function and the type must be located in the same namespace. Following this schema enables argument-dependent-lookup/ADL in stream operator of sqlstring (which uses the to_string).

◆ operator=()

sqlstring & mysqlrouter::sqlstring::operator= ( const sqlstring )
default

◆ operator==()

bool mysqlrouter::sqlstring::operator== ( const sqlstring other) const
inline

◆ reset()

void mysqlrouter::sqlstring::reset ( const char *  format_string,
const sqlstringformat  format = 0 
)

◆ str()

std::string mysqlrouter::sqlstring::str ( ) const

◆ unlock_escape()

void mysqlrouter::sqlstring::unlock_escape ( )
private

Member Data Documentation

◆ _format

sqlstringformat mysqlrouter::sqlstring::_format
private

◆ _format_string_left

std::string mysqlrouter::sqlstring::_format_string_left
private

◆ _formatted

std::string mysqlrouter::sqlstring::_formatted
private

◆ _locked_escape

int mysqlrouter::sqlstring::_locked_escape {0}
private

◆ empty

const sqlstring mysqlrouter::sqlstring::empty {""}
static

◆ end

const sqlstring mysqlrouter::sqlstring::end
static

◆ null

const sqlstring mysqlrouter::sqlstring::null
static

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