tdslite latest
C++ API reference
Loading...
Searching...
No Matches
tdsl::detail::command_context< NetImpl > Struct Template Reference

Helper type to execute SQL commands. More...

#include <tdslite/detail/tdsl_command_context.hpp>

Classes

struct  command_options
 
struct  query_result
 

Public Types

using tds_context_type = tds_context< NetImpl >
 
using column_metadata_cref = const tdsl::tds_colmetadata_token &
 
using row_cref = const tdsl::tdsl_row &
 
using row_callback_fn_t = void(*)(void *, column_metadata_cref, row_cref)
 
using execute_rpc_result = tdsl::expected< tdsl::uint32_t, e_rpc_error_code >
 

Public Member Functions

 command_context (tds_context_type &ctx, const command_options &opts={}) noexcept
 Default c-tor.
 
 ~command_context () noexcept
 Unregister the callbacks registered by this context.
 
 command_context (const command_context &)=delete
 
command_context & operator= (const command_context &)=delete
 
template<typename T , traits::enable_when::same_any_of< T, string_view, wstring_view, struct progmem_string_view > = true>
auto execute_query (T command, row_callback_fn_t row_callback=+[](void *, const tds_colmetadata_token &, const tdsl_row &) -> void {}, void *rcb_uptr=nullptr) noexcept -> query_result
 Execute a query.
 
template<typename T , traits::enable_when::same_any_of< T, string_view, wstring_view, struct progmem_string_view > = true>
execute_rpc_result execute_rpc (T command, tdsl::span< sql_parameter_binding > params={}, e_rpc_mode mode=e_rpc_mode::executesql, row_callback_fn_t row_callback=+[](void *, const tds_colmetadata_token &, const tdsl_row &) -> void {}, void *rcb_uptr=nullptr) noexcept
 Perform a remote procedure call (e.g.
 

Static Public Member Functions

static token_handler_result token_handler (void *uptr, e_tds_message_token_type token_type, tdsl::binary_reader< tdsl::endian::little > &rr) noexcept
 Token handler for command_context.
 

Detailed Description

template<typename NetImpl>
struct tdsl::detail::command_context< NetImpl >

Helper type to execute SQL commands.

The context is designed to be constructed on demand.

Template Parameters
NetImplNetwork implementation type

Member Typedef Documentation

◆ tds_context_type

template<typename NetImpl >
using tdsl::detail::command_context< NetImpl >::tds_context_type = tds_context<NetImpl>

◆ column_metadata_cref

template<typename NetImpl >
using tdsl::detail::command_context< NetImpl >::column_metadata_cref = const tdsl::tds_colmetadata_token &

◆ row_cref

template<typename NetImpl >
using tdsl::detail::command_context< NetImpl >::row_cref = const tdsl::tdsl_row &

◆ row_callback_fn_t

template<typename NetImpl >
using tdsl::detail::command_context< NetImpl >::row_callback_fn_t = void (*)(void *, column_metadata_cref, row_cref)

◆ execute_rpc_result

template<typename NetImpl >
using tdsl::detail::command_context< NetImpl >::execute_rpc_result = tdsl::expected<tdsl::uint32_t, e_rpc_error_code>

Constructor & Destructor Documentation

◆ command_context() [1/2]

template<typename NetImpl >
tdsl::detail::command_context< NetImpl >::command_context ( tds_context_type &  ctx,
const command_options &  opts = {} 
)
inlinenoexcept

Default c-tor.

Parameters
[in]ctxThe TDS context associated with the command

◆ ~command_context()

template<typename NetImpl >
tdsl::detail::command_context< NetImpl >::~command_context ( )
inlinenoexcept

Unregister the callbacks registered by this context.

The tds_context outlives the command context, so the callbacks must not keep pointing to this object after it is destroyed. Otherwise, a subsequent DONE token (e.g. one received during a later login) would be delivered to a dangling pointer.

◆ command_context() [2/2]

template<typename NetImpl >
tdsl::detail::command_context< NetImpl >::command_context ( const command_context< NetImpl > &  )
delete

Member Function Documentation

◆ operator=()

template<typename NetImpl >
command_context & tdsl::detail::command_context< NetImpl >::operator= ( const command_context< NetImpl > &  )
delete

◆ execute_query()

template<typename NetImpl >
template<typename T , traits::enable_when::same_any_of< T, string_view, wstring_view, struct progmem_string_view > = true>
auto tdsl::detail::command_context< NetImpl >::execute_query ( T  command,
row_callback_fn_t  row_callback = +[](void *, const tds_colmetadata_token &,                                                 const tdsl_row &) -> void {},
void *  rcb_uptr = nullptr 
) -> query_result
inlinenoexcept

Execute a query.

Template Parameters
TAuto-deduced string type (char_span or u16char_span)
Parameters
[in]commandSQL command to execute
[in]row_callbackRow callback function (optional)
[in]rcb_uptrRow callback user pointer (optional)

The result set returned by query command can be read by providing a row callback function

Returns
Query result (number of rows affected, status). If the command does not fit into the network buffer, nothing is sent and request_too_large is set. The command must leave 8 bytes of the buffer free, for the packet header.

◆ execute_rpc()

template<typename NetImpl >
template<typename T , traits::enable_when::same_any_of< T, string_view, wstring_view, struct progmem_string_view > = true>
execute_rpc_result tdsl::detail::command_context< NetImpl >::execute_rpc ( T  command,
tdsl::span< sql_parameter_binding >  params = {},
e_rpc_mode  mode = e_rpc_mode::executesql,
row_callback_fn_t  row_callback = +[](void *, const tds_colmetadata_token &,                                                 const tdsl_row &) -> void {},
void *  rcb_uptr = nullptr 
)
inlinenoexcept

Perform a remote procedure call (e.g.

execute a stored procedure or a parameterized query)

Template Parameters
TString view type
Parameters
[in]commandCommand to execute
[in]paramsParameters of the command, if any
[in]modeRPC execution mode
[in]row_callbackRow callback function (optional)
[in]rcb_uptrRow callback user pointer (optional)

The result set returned by query command can be read by providing a row callback function

Returns
e_rpc_error_code::invalid_mode if mode value is invalid or not supported
e_rpc_error_code::invalid_parameter if a parameter has an unsupported type, or an invalid size (not executed)
e_rpc_error_code::request_too_large if the request does not fit into the network buffer (less the 8 bytes kept for the packet header), or command is longer than 4000 characters (not executed)
e_rpc_error_code::invalid_response if the response could not be processed completely
e_rpc_error_code::server_error if the server reported an error while executing the request
e_rpc_error_code::network_error if sending the request or receiving the response failed
rows_affected if successful

◆ token_handler()

template<typename NetImpl >
static token_handler_result tdsl::detail::command_context< NetImpl >::token_handler ( void *  uptr,
e_tds_message_token_type  token_type,
tdsl::binary_reader< tdsl::endian::little > &  rr 
)
inlinestaticnoexcept

Token handler for command_context.

Handles COLMETADATA & ROW token types.

Parameters
[in]uptrUser-ptr (command context instance)
[in]token_typeType of the token to handle
[in]rrBinary reader
Returns
token-specific handler result for COLMETADATA & ROW tokens
default token handler result, which is unhandled

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