ThinSQLite++
A thin, safe and convenient modern C++ wrapper for SQLite API.
Loading...
Searching...
No Matches
context Class Referencefinal

SQL Function Context Object. More...

Inheritance diagram for context:
handle< sqlite3_context, context >

Public Member Functions

 ~context () noexcept=delete
 Contexts are never destroyed by user code.
 
void * aggregate_context (int size) noexcept
 Allocate memory for aggregate function context.
 
class databasedatabase () const noexcept
 Retrieve database connection for the context.
 
void error (const std::string_view &value) noexcept
 Cause the implemented SQL function to throw an SQL exception.
 
void error (const std::u8string_view &value) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void error (int error_code) noexcept
 Changes the error code returned by function evaluation.
 
void error_nomem () noexcept
 Causes the implemented SQL function to throw an SQL exception indicating that a memory allocation failed.
 
void error_toobig () noexcept
 Causes the implemented SQL function to throw an SQL exception indicating that a string or BLOB is too long to represent.
 
void result (std::nullptr_t) noexcept
 Return NULL from the implemented SQL function.
 
void result (int value) noexcept
 Return an int from the implemented SQL function.
 
void result (int64_t value) noexcept
 Return an int64_t from implemented SQL function.
 
void result (double value) noexcept
 Return a double from implemented SQL function.
 
void result (const std::string_view &value) noexcept
 Return a string by value from the implemented SQL function.
 
void result (const std::u8string_view &value) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void result_reference (const std::string_view &value) noexcept
 Return a string by reference from the implemented SQL function.
 
void result_reference (const std::u8string_view &value) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void result_reference (const std::string_view &value, void(*unref)(const char *)) noexcept
 Return a string by reference from the implemented SQL function.
 
void result_reference (const std::u8string_view &value, void(*unref)(const char8_t *)) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void result (const blob_view &value) noexcept
 Return a blob by value from the implemented SQL function.
 
void result_reference (const blob_view &value) noexcept
 Return a blob by reference from the implemented SQL function.
 
void result_reference (const blob_view &value, void(*unref)(const std::byte *) noexcept) noexcept
 Return a blob by reference from the implemented SQL function.
 
void result (const zero_blob &value) noexcept
 Return a blob of zeroes from the implemented SQL function.
 
template<class T >
void result (T *ptr, const char *type, void(*destroy)(T *)) noexcept
 
 
template<class T >
void result (std::unique_ptr< T > ptr) noexcept
 Return a custom pointer from the implemented SQL function.
 
void result (const value &val) noexcept
 Return a copy of the passed value from the implemented SQL function.
 
void result_subtype (unsigned value) noexcept
 Sets the subtype of the result of the implemented SQL function.
 
template<class T >
T * get_auxdata (int arg) const noexcept
 Get auxiliary data associated with argument values.
 
template<class T >
void set_auxdata (int arg, T *data, void(*destroy)(T *) noexcept) noexcept
 Associate auxiliary data with argument values.
 
template<class T >
T * user_data () noexcept
 Return the function's user data.
 
bool vtab_nochange () const noexcept
 Return if a value being fetched as part of an UPDATE operation during which the column value will not change.
 
void operator delete (void *) noexcept
 Operator delete for a fake pointer is no-op.
 
sqlite3_contextc_ptr () const noexcept
 Access the real underlying SQLite type.
 

Static Public Member Functions

static contextfrom (sqlite3_context *obj) noexcept
 Create fake pointer from the underlying SQLite one.
 

Detailed Description

SQL Function Context Object.

This is a fake wrapper class for sqlite3_context.

#include <thinsqlitepp/context.hpp>

Member Function Documentation

◆ aggregate_context()

void * aggregate_context ( int size)
inlinenoexcept

Allocate memory for aggregate function context.

Equivalent to sqlite3_aggregate_context

◆ database()

class database & database ( ) const
inlinenoexcept

Retrieve database connection for the context.

Equivalent to sqlite3_aggregate_context

◆ error() [1/2]

void error ( const std::string_view & value)
inlinenoexcept

Cause the implemented SQL function to throw an SQL exception.

Equivalent to sqlite3_result_error

◆ error() [2/2]

void error ( int error_code)
inlinenoexcept

Changes the error code returned by function evaluation.

Equivalent to sqlite3_result_error_code

This call is useful to propagate SQLite error codes out of function evaluation. Note that calling error(const std::string_view &) after this call will reset error code to SQLITE_ERROR

◆ error_nomem()

void error_nomem ( )
inlinenoexcept

Causes the implemented SQL function to throw an SQL exception indicating that a memory allocation failed.

Equivalent to sqlite3_result_error_nomem

◆ error_toobig()

void error_toobig ( )
inlinenoexcept

Causes the implemented SQL function to throw an SQL exception indicating that a string or BLOB is too long to represent.

Equivalent to sqlite3_result_error_toobig

◆ result() [1/10]

void result ( std::nullptr_t )
inlinenoexcept

Return NULL from the implemented SQL function.

Equivalent to sqlite3_result_null

◆ result() [2/10]

void result ( int value)
inlinenoexcept

Return an int from the implemented SQL function.

Equivalent to sqlite3_result_int

◆ result() [3/10]

void result ( int64_t value)
inlinenoexcept

Return an int64_t from implemented SQL function.

Equivalent to sqlite3_result_int64

◆ result() [4/10]

void result ( double value)
inlinenoexcept

Return a double from implemented SQL function.

Equivalent to sqlite3_result_double

◆ result() [5/10]

void result ( const std::string_view & value)
inlinenoexcept

Return a string by value from the implemented SQL function.

Equivalent to ::sqlite3_result_text(..., SQLITE_TRANSIENT)

The string content is copied and does not need to persist.

◆ result_reference() [1/4]

void result_reference ( const std::string_view & value)
inlinenoexcept

Return a string by reference from the implemented SQL function.

Equivalent to ::sqlite3_result_text(..., SQLITE_STATIC)

The string content is used by reference and so must be present in memory as long as SQLite library remain used.

◆ result_reference() [2/4]

void result_reference ( const std::string_view & value,
void(* unref )(const char *) )
inlinenoexcept

Return a string by reference from the implemented SQL function.

Equivalent to ::sqlite3_result_text(..., unref)

The string content is used by reference.

Parameters
valuereference to string to return
unrefcalled when the reference is no longer needed. Its argument will be the pointer returned from value.data()

◆ result() [6/10]

void result ( const blob_view & value)
inlinenoexcept

Return a blob by value from the implemented SQL function.

Equivalent to ::sqlite3_result_blob(..., SQLITE_TRANSIENT)

The blob content is copied and does not need to persist.

◆ result_reference() [3/4]

void result_reference ( const blob_view & value)
inlinenoexcept

Return a blob by reference from the implemented SQL function.

Equivalent to ::sqlite3_result_blob(..., SQLITE_STATIC)

The blob content is used by reference and so must be present in memory as long as SQLite library remain used.

◆ result_reference() [4/4]

void result_reference ( const blob_view & value,
void(* unref )(const std::byte *) noexcept )
inlinenoexcept

Return a blob by reference from the implemented SQL function.

Equivalent to ::sqlite3_result_blob(..., unref)

The blob content is used by reference.

Parameters
valuereference to blob to return
unrefcalled when the reference is no longer needed. Its argument is the pointer returned from value.data()

◆ result() [7/10]

void result ( const zero_blob & value)
inlinenoexcept

Return a blob of zeroes from the implemented SQL function.

Equivalent to sqlite3_result_zeroblob()

◆ result() [8/10]

template<class T >
void result ( T * ptr,
const char * type,
void(* destroy )(T *) )
inlinenoexcept

Return a custom pointer from the implemented SQL function.

Equivalent to sqlite3_result_pointer()

◆ result() [9/10]

template<class T >
void result ( std::unique_ptr< T > ptr)
inlinenoexcept

Return a custom pointer from the implemented SQL function.

Equivalent to sqlite3_result_pointer()

This is a safer overload of result(T * , const char * , void( * )(T * )) that takes a pointer via std::unique_ptr ownership transfer. The inferred "type" for sqlite3_result_pointer is typeid(T).name().

◆ result() [10/10]

void result ( const value & val)
inlinenoexcept

Return a copy of the passed value from the implemented SQL function.

Equivalent to sqlite3_result_value

◆ result_subtype()

void result_subtype ( unsigned value)
inlinenoexcept

Sets the subtype of the result of the implemented SQL function.

Equivalent to sqlite3_result_subtype

Since
SQLite 3.9

◆ get_auxdata()

template<class T >
T * get_auxdata ( int arg) const
inlinenoexcept

Get auxiliary data associated with argument values.

Equivalent to sqlite3_get_auxdata

Template Parameters
Ttype of the data

◆ set_auxdata()

template<class T >
void set_auxdata ( int arg,
T * data,
void(* destroy )(T *) noexcept )
inlinenoexcept

Associate auxiliary data with argument values.

Equivalent to sqlite3_set_auxdata

Template Parameters
Ttype of the data

◆ user_data()

template<class T >
T * user_data ( )
inlinenoexcept

Return the function's user data.

Equivalent to sqlite3_user_data

User data can be associated with a function during creation.

See also
database::create_function

◆ vtab_nochange()

bool vtab_nochange ( ) const
inlinenoexcept

Return if a value being fetched as part of an UPDATE operation during which the column value will not change.

Equivalent to sqlite3_vtab_nochange