libpqxx  7.9.0
pqxx::placeholders< COUNTER > Class Template Reference

Generate parameter placeholders for use in an SQL statement. More...

#include <params.hxx>

Public Member Functions

 placeholders ()
 
constexpr zview view () const &noexcept
 Read an ephemeral version of the current placeholder text. More...
 
std::string get () const
 Read the current placeholder text, as a std::string. More...
 
void next () &
 Move on to the next parameter. More...
 
COUNTER count () const noexcept
 Return the current placeholder number. The initial placeholder is 1. More...
 

Static Public Attributes

static constexpr unsigned int max_params
 Maximum number of parameters we support. More...
 

Detailed Description

template<typename COUNTER = unsigned int>
class pqxx::placeholders< COUNTER >

Generate parameter placeholders for use in an SQL statement.

When you want to pass parameters to a prepared statement or a parameterised statement, you insert placeholders into the SQL. During invocation, the database replaces those with the respective parameter values you passed.

The placeholders look like $1 (for the first parameter value), $2 (for the second), and so on. You can just write those directly in your statement. But for those rare cases where it becomes difficult to track which number a placeholder should have, you can use a placeholders object to count and generate them in order.

Constructor & Destructor Documentation

◆ placeholders()

template<typename COUNTER = unsigned int>
pqxx::placeholders< COUNTER >::placeholders ( )

Member Function Documentation

◆ count()

template<typename COUNTER = unsigned int>
COUNTER pqxx::placeholders< COUNTER >::count ( ) const
noexcept

Return the current placeholder number. The initial placeholder is 1.

◆ get()

template<typename COUNTER = unsigned int>
std::string pqxx::placeholders< COUNTER >::get ( ) const

Read the current placeholder text, as a std::string.

This will be slightly slower than converting to a zview. With most C++ implementations however, until you get into ridiculous numbers of parameters, the string will benefit from the Short String Optimization, or SSO.

◆ next()

template<typename COUNTER = unsigned int>
void pqxx::placeholders< COUNTER >::next ( ) &

◆ view()

template<typename COUNTER = unsigned int>
constexpr zview pqxx::placeholders< COUNTER >::view ( ) const &
constexprnoexcept

Read an ephemeral version of the current placeholder text.

Warning
Changing the current placeholder number will overwrite this. Use the view immediately, or lose it.

Member Data Documentation

◆ max_params

template<typename COUNTER = unsigned int>
constexpr unsigned int pqxx::placeholders< COUNTER >::max_params
staticconstexpr
Initial value:
{
(std::numeric_limits<COUNTER>::max)()}

Maximum number of parameters we support.

Referenced by pqxx::placeholders< COUNTER >::next().


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