libpqxx  7.5.1
pqxx::params Class Reference

Build a parameter list for a parameterised or prepared statement. More...

#include <prepared_statement.hxx>

Public Member Functions

 params ()=default
 
template<typename... Args>
constexpr params (Args &&...args)
 Create a params pre-populated with args. Feel free to add more later. More...
 
void reserve (std::size_t)
 
auto size () const
 
auto ssize () const
 
void append ()
 Append a null value. More...
 
void append (zview)
 Append a non-null zview parameter. More...
 
void append (std::string const &)
 Append a non-null string parameter. More...
 
void append (std::string &&)
 Append a non-null string parameter. More...
 
void append (std::basic_string_view< std::byte >)
 Append a non-null binary parameter. More...
 
void append (std::basic_string< std::byte > const &)
 Append a non-null binary parameter. More...
 
void append (std::basic_string< std::byte > &&)
 Append a non-null binary parameter. More...
 
void append (binarystring const &value)
 
template<typename IT , typename ACCESSOR >
void append (pqxx::internal::dynamic_params< IT, ACCESSOR > const &value)
 Append all parameters from value. More...
 
void append (params const &value)
 
void append (params &&value)
 
template<typename TYPE >
void append (TYPE const &value)
 Append a non-null parameter, converting it to its string representation. More...
 
template<typename RANGE >
void append_multi (RANGE &range)
 Append all elements of range as parameters. More...
 
pqxx::internal::c_params make_c_params () const
 For internal use: Generate a params object for use in calls. More...
 

Detailed Description

Build a parameter list for a parameterised or prepared statement.

When calling a parameterised statement or a prepared statement, you can pass parameters into the statement directly in the invocation, as additional arguments to exec_prepared or exec_params. But in complex cases, sometimes that's just not convenient.

In those situations, you can create a params and append your parameters into that, one by one. Then you pass the params to exec_prepared or exec_params.

Combinations also work: if you have a params containing a string parameter, and you call exec_params with an int argument followed by your params, you'll be passing the int as the first parameter and the string as the second. You can even insert a params in a params, or pass two params objects to a statement.

Constructor & Destructor Documentation

◆ params() [1/2]

pqxx::params::params ( )
default

◆ params() [2/2]

template<typename... Args>
constexpr pqxx::params::params ( Args &&...  args)

Create a params pre-populated with args. Feel free to add more later.

Member Function Documentation

◆ append() [1/12]

void pqxx::params::append ( )

Append a null value.

◆ append() [2/12]

void pqxx::params::append ( zview  value)

Append a non-null zview parameter.

The underlying data must stay valid for as long as the params remains active.

◆ append() [3/12]

void pqxx::params::append ( std::string const &  value)

Append a non-null string parameter.

Copies the underlying data into internal storage. For best efficiency, use the zview variant if you can, or std::move().

◆ append() [4/12]

void pqxx::params::append ( std::string &&  value)

Append a non-null string parameter.

◆ append() [5/12]

void pqxx::params::append ( std::basic_string_view< std::byte >  value)

Append a non-null binary parameter.

The underlying data must stay valid for as long as the params remains active.

◆ append() [6/12]

void pqxx::params::append ( std::basic_string< std::byte > const &  value)

Append a non-null binary parameter.

Copies the underlying data into internal storage. For best efficiency, use the std::basic_string_view<std::byte> variant if you can, or std::move().

◆ append() [7/12]

void pqxx::params::append ( std::basic_string< std::byte > &&  value)

Append a non-null binary parameter.

◆ append() [8/12]

void pqxx::params::append ( binarystring const &  value)
Deprecated:
Append binarystring parameter.

The binarystring must stay valid for as long as the params remains active.

References pqxx::binarystring::bytes_view().

◆ append() [9/12]

template<typename IT , typename ACCESSOR >
void pqxx::params::append ( pqxx::internal::dynamic_params< IT, ACCESSOR > const &  value)

Append all parameters from value.

◆ append() [10/12]

void pqxx::params::append ( params const &  value)

References reserve().

◆ append() [11/12]

void pqxx::params::append ( params &&  value)

References reserve().

◆ append() [12/12]

template<typename TYPE >
void pqxx::params::append ( TYPE const &  value)

Append a non-null parameter, converting it to its string representation.

References pqxx::ignore_unused(), pqxx::is_null(), and pqxx::to_string().

◆ append_multi()

template<typename RANGE >
void pqxx::params::append_multi ( RANGE &  range)

Append all elements of range as parameters.

◆ make_c_params()

pqxx::internal::c_params pqxx::params::make_c_params ( ) const

For internal use: Generate a params object for use in calls.

The params object encapsulates the pointers which we will need to pass to libpq when calling a parameterised or prepared statement.

The pointers in the params will refer to storage owned by either the params object, or the caller. This is not a problem because a c_params object is guaranteed to live only while the call is going on. As soon as we climb back out of that call tree, we're done with that data.

References pqxx::param_format(), and pqxx::internal::ssize().

Referenced by pqxx::transaction_base::exec_prepared(), and pqxx::transaction_base::stream().

◆ reserve()

void pqxx::params::reserve ( std::size_t  n)

Referenced by append().

◆ size()

auto pqxx::params::size ( ) const

◆ ssize()

auto pqxx::params::ssize ( ) const

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