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

#include <SqlDynamicNumeric.hpp>

Classes

struct  Literal
 A decimal column's text, as delivered by a single SQLGetData call. More...
 

Static Public Member Functions

static LIGHTWEIGHT_FORCE_INLINE SQLRETURN InputParameter (SQLHSTMT stmt, SQLUSMALLINT column, SqlDynamicNumeric const &value, SqlDataBinderCallback &cb) noexcept
 Binds the value as an input parameter, rendered as an exact decimal literal.
 
static LIGHTWEIGHT_FORCE_INLINE Literal ReadLiteral (SQLHSTMT stmt, SQLUSMALLINT column, SQLLEN *indicator, std::span< char > buffer) noexcept
 
static LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDynamicNumeric > FromColumnLiteral (SQLHSTMT stmt, SQLUSMALLINT column, std::string_view literal) noexcept
 
static LIGHTWEIGHT_FORCE_INLINE SQLRETURN TryGetColumn (SQLHSTMT stmt, SQLUSMALLINT column, SqlDynamicNumeric *result, SQLLEN *indicator, SqlDataBinderCallback const &) noexcept
 
static LIGHTWEIGHT_FORCE_INLINE SQLRETURN GetColumn (SQLHSTMT stmt, SQLUSMALLINT column, SqlDynamicNumeric *result, SQLLEN *indicator, SqlDataBinderCallback const &cb)
 
static LIGHTWEIGHT_FORCE_INLINE std::string Inspect (SqlDynamicNumeric const &value)
 Renders the value for SQL trace logs.
 

Static Public Attributes

static constexpr auto ColumnType = SqlColumnTypeDefinitions::Decimal { .precision = 38, .scale = 0 }
 Widest decimal ODBC admits, so no supported backend can overflow the bind buffer.
 

Detailed Description

Binds SqlDynamicNumeric as an exact decimal literal.

Text is deliberately the wire format in both directions. SQL_C_NUMERIC needs the application to publish precision and scale on the descriptor before each call and is honoured inconsistently — the SQL Server driver returns scale-0 values without it and the SQLite driver has no native support at all, which is why SqlDataBinder<SqlNumeric<P, S>> routes both backends around it. Every supported driver converts between a decimal column and its literal exactly, with no binary floating-point step, so this path keeps all digits on all backends.

Definition at line 337 of file SqlDynamicNumeric.hpp.

Member Function Documentation

◆ InputParameter()

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

Binds the value as an input parameter, rendered as an exact decimal literal.

Definition at line 343 of file SqlDynamicNumeric.hpp.

◆ ReadLiteral()

static LIGHTWEIGHT_FORCE_INLINE Literal Lightweight::SqlDataBinder< SqlDynamicNumeric >::ReadLiteral ( SQLHSTMT  stmt,
SQLUSMALLINT  column,
SQLLEN *  indicator,
std::span< char >  buffer 
)
inlinestaticnoexcept

Reads the column's decimal literal into buffer, issuing exactly one SQLGetData.

ODBC allows a second SQLGetData on the same column only while a character or binary value is still being delivered in parts. Once it has arrived in full, a conforming driver answers SQL_NO_DATA — SQL Server's does. So a caller that wants the value exactly and, failing that, approximately must derive both from this one read rather than retrieving the column twice.

Parameters
stmtThe ODBC statement handle to read from.
columnThe 1-based index of the column to read.
indicatorWhere to report the length; may be null, in which case the length is still needed internally and is discarded afterwards.
bufferStorage for the text; Literal::text points into it, so it must outlive the returned value. 128 bytes is always enough: ODBC caps DECIMAL precision at 38, leaving room for the sign, decimal point, terminator and driver padding.

Definition at line 399 of file SqlDynamicNumeric.hpp.

◆ FromColumnLiteral()

static LIGHTWEIGHT_FORCE_INLINE std::optional< SqlDynamicNumeric > Lightweight::SqlDataBinder< SqlDynamicNumeric >::FromColumnLiteral ( SQLHSTMT  stmt,
SQLUSMALLINT  column,
std::string_view  literal 
)
inlinestaticnoexcept

Converts a decimal literal into an exact value, using the column's declared precision and scale.

Return values
std::nulloptThe value needs more digits than the unscaled 64-bit carrier holds; see SqlMaxDynamicNumericPrecision.

Definition at line 439 of file SqlDynamicNumeric.hpp.

References Lightweight::SqlDynamicNumeric::FromString().

◆ TryGetColumn()

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

Retrieves the column as an exact decimal without throwing, for callers that can degrade.

Return values
SQL_ERRORThe driver truncated the literal, or the value needs more digits than the unscaled 64-bit carrier holds (see SqlMaxDynamicNumericPrecision). No ODBC diagnostic is posted for this — the driver did not fail, the value simply does not fit — so read the return code rather than the statement's last error. GetColumn turns it into a described exception; SqlVariant reuses ReadLiteral and falls back to double instead.

Definition at line 470 of file SqlDynamicNumeric.hpp.

◆ GetColumn()

static LIGHTWEIGHT_FORCE_INLINE SQLRETURN Lightweight::SqlDataBinder< SqlDynamicNumeric >::GetColumn ( SQLHSTMT  stmt,
SQLUSMALLINT  column,
SqlDynamicNumeric *  result,
SQLLEN *  indicator,
SqlDataBinderCallback const &  cb 
)
inlinestatic

Retrieves the column as an exact decimal, preserving every digit the column declares.

Exceptions
SqlExceptionWhen the value cannot be represented exactly. The driver posts no diagnostic in that case — it did not fail — so this synthesizes one rather than letting the caller surface an empty, or worse a stale, error from the handle.

Definition at line 499 of file SqlDynamicNumeric.hpp.

References Lightweight::SqlErrorInfo::nativeErrorCode.

◆ Inspect()

static LIGHTWEIGHT_FORCE_INLINE std::string Lightweight::SqlDataBinder< SqlDynamicNumeric >::Inspect ( SqlDynamicNumeric const &  value)
inlinestatic

Renders the value for SQL trace logs.

Definition at line 519 of file SqlDynamicNumeric.hpp.

References Lightweight::SqlDynamicNumeric::ToString().

Member Data Documentation

◆ ColumnType

constexpr auto Lightweight::SqlDataBinder< SqlDynamicNumeric >::ColumnType = SqlColumnTypeDefinitions::Decimal { .precision = 38, .scale = 0 }
staticconstexpr

Widest decimal ODBC admits, so no supported backend can overflow the bind buffer.

Definition at line 340 of file SqlDynamicNumeric.hpp.


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