Lightweight 0.20260921.0
Loading...
Searching...
No Matches
Lightweight::SqlDataBinder< char > Struct Reference

#include <Primitives.hpp>

Static Public Member Functions

static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter (SQLHSTMT stmt, SQLUSMALLINT column, char const &value, SqlDataBinderCallback &cb) noexcept
 
static LIGHTWEIGHT_FORCE_INLINE SQLRETURN BatchInputParameter (SQLHSTMT stmt, SQLUSMALLINT column, char const *values, size_t rowCount, SqlDataBinderCallback &cb, SQLLEN *indicators=nullptr) noexcept
 
static SQLRETURN OutputColumn (SQLHSTMT stmt, SQLUSMALLINT column, char *result, SQLLEN *indicator, SqlDataBinderCallback &cb) noexcept
 
static SQLRETURN GetColumn (SQLHSTMT stmt, SQLUSMALLINT column, char *result, SQLLEN *indicator, SqlDataBinderCallback const &) noexcept
 
static LIGHTWEIGHT_FORCE_INLINE std::string Inspect (char value)
 

Static Public Attributes

static constexpr SqlColumnTypeDefinition ColumnType = SqlColumnTypeDefinitions::Char { 1 }
 The column type a char maps to.
 

Detailed Description

Binds a single char as a one-character CHAR(1) value.

Unlike the numeric primitives, char maps to a character type (SQL_C_CHAR / SQL_CHAR), whose ODBC contract differs from fixed-width data in three ways, each of which this binder honours:

  • On input, the column size is the length in characters and must not be zero (MS SQL Server rejects zero with HY104 "Invalid precision value").
  • On input, the value is not NUL-terminated, so its length must be passed through the indicator — without one the driver reads the value as a NUL-terminated string, past the end of the char.
  • On output, the driver NUL-terminates what it writes, so the buffer needs room for one more byte than the value; a one-byte buffer receives nothing.

Definition at line 104 of file Primitives.hpp.

Member Function Documentation

◆ InputParameter()

static LIGHTWEIGHT_FORCE_INLINE SQLRETURN Lightweight::SqlDataBinder< char >::InputParameter ( SQLHSTMT  stmt,
SQLUSMALLINT  column,
char const &  value,
SqlDataBinderCallback &  cb 
)
inlinestaticnoexcept

Binds a single char as an input parameter.

Parameters
stmtThe ODBC statement handle.
columnThe 1-based parameter index.
valueThe character to bind; it must outlive the statement's execution.
cbProvides the length indicator, which must also outlive the execution.
Returns
The ODBC return code of SQLBindParameter.

Definition at line 116 of file Primitives.hpp.

◆ BatchInputParameter()

static LIGHTWEIGHT_FORCE_INLINE SQLRETURN Lightweight::SqlDataBinder< char >::BatchInputParameter ( SQLHSTMT  stmt,
SQLUSMALLINT  column,
char const *  values,
size_t  rowCount,
SqlDataBinderCallback &  cb,
SQLLEN *  indicators = nullptr 
)
inlinestaticnoexcept

Binds a contiguous (column-wise) array of characters as an input parameter.

Parameters
stmtThe ODBC statement handle.
columnThe 1-based parameter index.
valuesThe first of rowCount characters; they must outlive the statement's execution.
rowCountThe number of rows in the batch.
cbProvides the per-row length indicators when indicators is not given.
indicatorsOptional per-row indicator array (the length, or SQL_NULL_DATA). When null, every row is bound as one character.
Returns
The ODBC return code of SQLBindParameter.

Definition at line 137 of file Primitives.hpp.

References Lightweight::SqlDataBinderCallback::ProvideInputIndicators().

◆ OutputColumn()

static SQLRETURN Lightweight::SqlDataBinder< char >::OutputColumn ( SQLHSTMT  stmt,
SQLUSMALLINT  column,
char *  result,
SQLLEN *  indicator,
SqlDataBinderCallback &  cb 
)
inlinestaticnoexcept

Binds result as the output column column, filled in on every fetch.

The driver writes into a NUL-terminated staging buffer, which a post-process callback copies into result; a NULL leaves result untouched (std::optional<char> resets itself on it).

Parameters
stmtThe ODBC statement handle.
columnThe 1-based column index.
resultReceives the character; it must outlive the fetches.
indicatorReceives the length, or SQL_NULL_DATA.
cbHolds the staging buffer and runs the copy after each fetch.
Returns
The ODBC return code of SQLBindCol.

Definition at line 172 of file Primitives.hpp.

◆ GetColumn()

static SQLRETURN Lightweight::SqlDataBinder< char >::GetColumn ( SQLHSTMT  stmt,
SQLUSMALLINT  column,
char *  result,
SQLLEN *  indicator,
SqlDataBinderCallback const &   
)
inlinestaticnoexcept

Reads the character in column column of the current row.

Parameters
stmtThe ODBC statement handle.
columnThe 1-based column index.
resultReceives the character; left untouched on NULL.
indicatorReceives the length, or SQL_NULL_DATA.
Returns
The ODBC return code of SQLGetData.

Definition at line 191 of file Primitives.hpp.

◆ Inspect()

static LIGHTWEIGHT_FORCE_INLINE std::string Lightweight::SqlDataBinder< char >::Inspect ( char  value)
inlinestatic
Parameters
valueThe character to render.
Returns
value as a one-character string.

Definition at line 203 of file Primitives.hpp.

Member Data Documentation

◆ ColumnType

constexpr SqlColumnTypeDefinition Lightweight::SqlDataBinder< char >::ColumnType = SqlColumnTypeDefinitions::Char { 1 }
staticconstexpr

The column type a char maps to.

Definition at line 107 of file Primitives.hpp.


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