Lightweight 0.20261105.1
Loading...
Searching...
No Matches
Statement.hpp File Reference
#include "../../Api.hpp"
#include "../../SqlBindingTypes.hpp"
#include "../../SqlError.hpp"
#include "Diagnostics.hpp"
#include "Handles.hpp"
#include "SqlOdbcPrelude.hpp"
#include <array>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <expected>
#include <optional>
#include <source_location>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include <sql.h>
#include <sqlext.h>

Go to the source code of this file.

Classes

struct  Lightweight::Driver::Odbc::ColumnDescription
 What DescribeColumn reports about a result column. More...
 
struct  Lightweight::Driver::Odbc::ParameterArrayLayout
 The layout of the parameter array that is being bound. More...
 

Typedefs

using Lightweight::Driver::Odbc::ProcessedCount = SQLULEN
 The count a driver writes back through a parameter-array or row-array attribute pointer (SQL_ATTR_PARAMS_PROCESSED_PTR, SQL_ATTR_ROWS_FETCHED_PTR).
 
using Lightweight::Driver::Odbc::RowStatus = SQLUSMALLINT
 One element of a parameter-status or row-status array (SQL_ATTR_PARAM_STATUS_PTR, SQL_ATTR_ROW_STATUS_PTR).
 

Functions

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::Allocate (Connection const &connection, Statement &stmt) noexcept
 Allocates a statement handle on connection.
 
LIGHTWEIGHT_API void Lightweight::Driver::Odbc::Free (Statement &stmt) noexcept
 Frees the statement handle and leaves stmt empty.
 
LIGHTWEIGHT_API void Lightweight::Driver::Odbc::Abandon (Statement &stmt) noexcept
 Gives up a statement handle whose connection session ended, and leaves stmt empty.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::Prepare (Statement &stmt, std::string_view query, bool wideQueryText)
 Prepares query on the statement.
 
LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::Execute (Statement &stmt) noexcept
 Executes the prepared statement with the currently bound parameters.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::ExecuteDirect (Statement &stmt, std::string_view query, bool wideQueryText)
 Executes query directly, without preparing it.
 
LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::Fetch (Statement &stmt) noexcept
 Fetches the next row of the result set into the bound columns.
 
LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::MoreResults (Statement &stmt) noexcept
 Advances to the next pending result set.
 
LIGHTWEIGHT_API void Lightweight::Driver::Odbc::CloseCursor (Statement &stmt) noexcept
 Closes the cursor of a result set that was read to its end (SQLCloseCursor). Pending result sets are left alone; the result is not reported.
 
LIGHTWEIGHT_API void Lightweight::Driver::Odbc::ReleaseCursor (Statement &stmt) noexcept
 Closes any open cursor and discards its pending rows (SQLFreeStmt with SQL_CLOSE), so the handle can run another query. Pending result sets are left alone; the result is not reported.
 
void Lightweight::Driver::Odbc::DiscardResults (Statement &stmt) noexcept
 Drains every pending result set (SQLMoreResults until SQL_NO_DATA or an error), then closes the cursor (ReleaseCursor), so the handle can run another query. An error met while draining ends the drain and is not reported.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::UnbindColumns (Statement &stmt) noexcept
 Unbinds every bound result column (SQLFreeStmt with SQL_UNBIND).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::ResetParameters (Statement &stmt) noexcept
 Drops every parameter binding (SQLFreeStmt with SQL_RESET_PARAMS).
 
LIGHTWEIGHT_API void Lightweight::Driver::Odbc::ResetParameterArrays (Statement &stmt) noexcept
 Restores single-row, column-bound parameter binding (the ODBC default) and unbinds the parameter status and processed-count pointers. The results are not reported: resetting to defaults on a live handle does not meaningfully fail.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::NumResultColumns (Statement const &stmt, std::int16_t &count) noexcept
 Reports the number of columns of the current result set.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::NumParameters (Statement const &stmt, std::int16_t &count) noexcept
 Reports the number of parameters of the prepared statement.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::NumRowsAffected (Statement const &stmt, std::ptrdiff_t &count) noexcept
 Reports the number of rows the last executed statement affected.
 
LIGHTWEIGHT_API std::expected< std::string, SqlErrorInfo > Lightweight::Driver::Odbc::ColumnName (Statement const &stmt, SqlColumnIndex column)
 The name of a result column, as the driver describes it.
 
LIGHTWEIGHT_API std::expected< SqlResultColumnType, SqlErrorInfo > Lightweight::Driver::Odbc::ColumnType (Statement const &stmt, SqlColumnIndex column)
 The SQL data type of a result column, as the driver describes it.
 
LIGHTWEIGHT_API SqlResultColumnType Lightweight::Driver::Odbc::ToResultColumnType (std::int16_t sqlType) noexcept
 Maps an ODBC SQL_* type code onto the driver-neutral SqlResultColumnType.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::SetQueryTimeout (Statement &stmt, std::chrono::seconds timeout) noexcept
 Sets the query timeout of the statement.
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::QueryTimeout (Statement const &stmt, std::chrono::seconds &timeout) noexcept
 Reports the query timeout of the statement.
 
SQLRETURN Lightweight::Driver::Odbc::DescribeResultColumnSqlType (SQLHSTMT stmt, SqlColumnIndex column, SQLSMALLINT *columnType) noexcept
 
std::optional< SQLSMALLINT > Lightweight::Driver::Odbc::DescribeResultColumnSqlType (SQLHSTMT stmt, SqlColumnIndex column) noexcept
 
std::optional< std::int16_t > Lightweight::Driver::Odbc::DescribeResultColumnSqlType (Statement const &stmt, SqlColumnIndex column) noexcept
 
ParameterArrayLayout Lightweight::Driver::Odbc::CurrentParameterArrayLayout (Statement const &stmt, std::size_t valueSize, std::size_t columnWiseRowCount) noexcept
 
detail::OdbcCallOutcome Lightweight::Driver::Odbc::CheckResult (Statement const &stmt, SqlResult result, std::source_location sourceLocation)
 The non-throwing, fault-seam-aware verdict on result (see detail::CheckOdbcCall()).
 
SqlResultColumnType Lightweight::Driver::Odbc::CatalogColumnType (Statement const &stmt, int dataType) noexcept
 The type a DATA_TYPE code of a catalog result set (SQLColumns, ...) stands for: the code mapped as ToResultColumnType maps a code SQLDescribeCol reports.
 
LIGHTWEIGHT_API std::size_t Lightweight::Driver::Odbc::DeclaredBoundColumnSize (Statement const &stmt, SqlColumnIndex column, SqlOutputColumnLength length) noexcept
 The declared length of output column column as a bound buffer size: between detail::DefaultBoundColumnSize and detail::MaxDeclaredBoundColumnSize, and detail::DefaultBoundColumnSize for a length the driver does not report or one above the maximum (a MAX or LONG column). One SQLColAttribute call.
 
SqlResult Lightweight::Driver::Odbc::DescribeColumn (Statement const &stmt, SqlColumnIndex column, SqlColumnDescription &description) noexcept
 Describes a result column (SQLDescribeCol): the Lightweight::Driver::SqlDriver concept's form, with the type mapped by ToResultColumnType.
 
LIGHTWEIGHT_API void Lightweight::Driver::Odbc::RegisterAnsiOnly (Statement const &stmt, Connection const &connection) noexcept
 Records stmt as belonging to a connection whose driver takes text only through the ANSI entry points, so that its diagnostics are read through those as well.
 
LIGHTWEIGHT_API void Lightweight::Driver::Odbc::ResetRowArrayAttributes (Statement &stmt) noexcept
 Restores single-row, column-bound fetching and unbinds the row status and rows-fetched pointers. The results are not reported. Part of the Lightweight::Driver::SqlDriver concept.
 
template<typename Check >
void Lightweight::Driver::Odbc::SetColumnWiseParameterArray (Statement &stmt, std::size_t rowCount, void *bindOffset, Check const &check)
 Sets up column-wise parameter-array binding of rowCount parameter sets.
 
template<typename Check >
void Lightweight::Driver::Odbc::SetRowWiseParameterArray (Statement &stmt, std::size_t rowCount, std::size_t rowStride, ProcessedCount *processedCount, Check const &check)
 Sets up row-wise parameter-array binding of rowCount parameter sets, rowStride bytes apart.
 
template<typename Check >
void Lightweight::Driver::Odbc::SetParameterStatusArrays (Statement &stmt, RowStatus *paramStatus, ProcessedCount *processedCount, Check const &check)
 Binds the arrays the driver reports per-parameter-set status and the processed count into.
 
template<typename Check >
void Lightweight::Driver::Odbc::SetRowArray (Statement &stmt, std::size_t rowBindType, std::size_t arrayDepth, RowStatus *rowStatus, ProcessedCount *rowsFetched, Check const &check)
 Sets up row-array fetching of up to arrayDepth rows per FetchNextBlock.
 
LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::BindColumn (Statement &stmt, SqlColumnIndex column, std::int16_t cType, void *buffer, SqlIndicator bufferLength, SqlIndicator *indicators) noexcept
 Binds a result column to a buffer (SQLBindCol).
 
LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::BindTextColumn (Statement &stmt, SqlColumnIndex column, char *buffer, SqlIndicator bufferLength, SqlIndicator *indicators) noexcept
 Binds a result column to a narrow character buffer (SQL_C_CHAR).
 
LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::BindUtf16TextParameter (Statement &stmt, std::uint16_t parameter, char16_t *text, std::size_t columnSize, SqlIndicator &lengthIndicator) noexcept
 Binds UTF-16 text as an input parameter of SQL type SQL_WVARCHAR (SQLBindParameter with SQL_C_WCHAR). lengthIndicator serves as both the buffer length and the length indicator.
 
LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::FetchNextBlock (Statement &stmt) noexcept
 Fetches the next block of rows into the row-array bound columns (SQLFetchScroll, SQL_FETCH_NEXT).
 
LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::DescribeColumn (Statement const &stmt, SqlColumnIndex column, ColumnDescription &description) noexcept
 Describes a result column (SQLDescribeCol).
 
LIGHTWEIGHT_API std::vector< std::int16_t > Lightweight::Driver::Odbc::DescribeParameterTypes (Statement const &stmt, std::size_t count)
 Describes the declared SQL type of each of the first count parameters (SQLDescribeParam).
 
LIGHTWEIGHT_API std::int16_t Lightweight::Driver::Odbc::BoundParameterCount (Statement const &stmt) noexcept
 The number of parameters currently bound on the statement, read from its application parameter descriptor.
 

Variables

constexpr RowStatus Lightweight::Driver::Odbc::ParamStatusUnused = SQL_PARAM_UNUSED
 The parameter status of a parameter set the driver did not process (SQL_PARAM_UNUSED).
 
constexpr RowStatus Lightweight::Driver::Odbc::ParamStatusError = SQL_PARAM_ERROR
 The parameter status of a parameter set that failed (SQL_PARAM_ERROR).
 
constexpr RowStatus Lightweight::Driver::Odbc::RowStatusError = SQL_ROW_ERROR
 The row status of a fetched row the driver could not convert (SQL_ROW_ERROR).
 
constexpr std::int16_t Lightweight::Driver::Odbc::UnknownParameterType = SQL_UNKNOWN_TYPE
 The declared SQL type DescribeParameterTypes reports for a parameter it could not describe.
 

Detailed Description

The statement operations of the ODBC driver: everything SqlStatement and its cursors ask an ODBC statement handle to do. The first group is the statement half of the Lightweight::Driver::SqlDriver concept; the second group is ODBC-only (parameter and row arrays, column binding, describing), used by code paths that exist only for the ODBC driver.

Every function is a thin wrapper: the same ODBC calls with the same arguments in the same order as the code it was moved from, and the return code handed back as Lightweight::SqlResult so that the caller decides how to check it (and keeps the fault seam of RequireSuccess at its call site).

Definition in file Statement.hpp.

Typedef Documentation

◆ ProcessedCount

The count a driver writes back through a parameter-array or row-array attribute pointer (SQL_ATTR_PARAMS_PROCESSED_PTR, SQL_ATTR_ROWS_FETCHED_PTR).

Definition at line 44 of file Statement.hpp.

◆ RowStatus

using Lightweight::Driver::Odbc::RowStatus = typedef SQLUSMALLINT

One element of a parameter-status or row-status array (SQL_ATTR_PARAM_STATUS_PTR, SQL_ATTR_ROW_STATUS_PTR).

Definition at line 48 of file Statement.hpp.

Function Documentation

◆ Allocate()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::Allocate ( Connection const &  connection,
Statement &  stmt 
)
noexcept

Allocates a statement handle on connection.

Parameters
connectionThe connection to allocate on.
stmtReceives the handle; it is written whatever the result (null on failure).
Returns
The result of SQLAllocHandle.

References Lightweight::Driver::Allocate().

◆ Free()

LIGHTWEIGHT_API void Lightweight::Driver::Odbc::Free ( Statement &  stmt)
noexcept

Frees the statement handle and leaves stmt empty.

Parameters
stmtThe statement to free; may be empty.

References Lightweight::Driver::Free().

◆ Abandon()

LIGHTWEIGHT_API void Lightweight::Driver::Odbc::Abandon ( Statement &  stmt)
noexcept

Gives up a statement handle whose connection session ended, and leaves stmt empty.

The driver freed the handle with the session (Close(), a re-connect), so it is not freed again: only the record that its diagnostics are read through the ANSI entry points is dropped.

Parameters
stmtThe statement; may be empty.

References Lightweight::Driver::Abandon().

◆ Prepare()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::Prepare ( Statement &  stmt,
std::string_view  query,
bool  wideQueryText 
)

Prepares query on the statement.

Parameters
stmtThe statement.
queryThe SQL text, UTF-8.
wideQueryTextWhether to hand the text to the W entry point (as UTF-16); otherwise the ANSI entry point gets the UTF-8 bytes unchanged (see SqlConnection::AcceptsWideQueryText()).
Returns
The result of SQLPrepare.

◆ Execute()

LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::Execute ( Statement &  stmt)
inlinenoexcept

Executes the prepared statement with the currently bound parameters.

Parameters
stmtThe statement.
Returns
The result of SQLExecute; SqlResult::NoData for a searched UPDATE/DELETE that matched no rows.

Definition at line 123 of file Statement.hpp.

◆ ExecuteDirect()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::ExecuteDirect ( Statement &  stmt,
std::string_view  query,
bool  wideQueryText 
)

Executes query directly, without preparing it.

Parameters
stmtThe statement.
queryThe SQL text, UTF-8.
wideQueryTextAs for Prepare.
Returns
The result of SQLExecDirect.

◆ Fetch()

LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::Fetch ( Statement &  stmt)
inlinenoexcept

Fetches the next row of the result set into the bound columns.

Parameters
stmtThe statement.
Returns
The result of SQLFetch; SqlResult::NoData past the last row.

Definition at line 138 of file Statement.hpp.

◆ MoreResults()

LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::MoreResults ( Statement &  stmt)
inlinenoexcept

Advances to the next pending result set.

Parameters
stmtThe statement.
Returns
The result of SQLMoreResults; SqlResult::NoData when none is pending.

Definition at line 146 of file Statement.hpp.

References Lightweight::Driver::MoreResults().

◆ CloseCursor()

LIGHTWEIGHT_API void Lightweight::Driver::Odbc::CloseCursor ( Statement &  stmt)
noexcept

Closes the cursor of a result set that was read to its end (SQLCloseCursor). Pending result sets are left alone; the result is not reported.

Parameters
stmtThe statement.

References Lightweight::Driver::CloseCursor().

◆ ReleaseCursor()

LIGHTWEIGHT_API void Lightweight::Driver::Odbc::ReleaseCursor ( Statement &  stmt)
noexcept

Closes any open cursor and discards its pending rows (SQLFreeStmt with SQL_CLOSE), so the handle can run another query. Pending result sets are left alone; the result is not reported.

Parameters
stmtThe statement.
Note
Not part of the Lightweight::Driver::SqlDriver concept: DiscardResults covers it there.

References Lightweight::Driver::Odbc::ReleaseCursor().

Referenced by Lightweight::Driver::Odbc::DiscardResults(), and Lightweight::Driver::Odbc::ReleaseCursor().

◆ DiscardResults()

void Lightweight::Driver::Odbc::DiscardResults ( Statement &  stmt)
inlinenoexcept

Drains every pending result set (SQLMoreResults until SQL_NO_DATA or an error), then closes the cursor (ReleaseCursor), so the handle can run another query. An error met while draining ends the drain and is not reported.

Parameters
stmtThe statement.

Definition at line 166 of file Statement.hpp.

References Lightweight::Driver::DiscardResults(), Lightweight::Driver::MoreResults(), and Lightweight::Driver::Odbc::ReleaseCursor().

◆ UnbindColumns()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::UnbindColumns ( Statement &  stmt)
noexcept

Unbinds every bound result column (SQLFreeStmt with SQL_UNBIND).

Parameters
stmtThe statement.
Returns
The result of SQLFreeStmt.

References Lightweight::Driver::UnbindColumns().

◆ ResetParameters()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::ResetParameters ( Statement &  stmt)
noexcept

Drops every parameter binding (SQLFreeStmt with SQL_RESET_PARAMS).

Parameters
stmtThe statement.
Returns
The result of SQLFreeStmt.

References Lightweight::Driver::ResetParameters().

◆ ResetParameterArrays()

LIGHTWEIGHT_API void Lightweight::Driver::Odbc::ResetParameterArrays ( Statement &  stmt)
noexcept

Restores single-row, column-bound parameter binding (the ODBC default) and unbinds the parameter status and processed-count pointers. The results are not reported: resetting to defaults on a live handle does not meaningfully fail.

Parameters
stmtThe statement.

References Lightweight::Driver::ResetParameterArrays().

◆ NumResultColumns()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::NumResultColumns ( Statement const &  stmt,
std::int16_t &  count 
)
noexcept

Reports the number of columns of the current result set.

Parameters
stmtThe statement.
countReceives the column count (0 for a statement that produced no result set).
Returns
The result of SQLNumResultCols.

References Lightweight::Driver::NumResultColumns().

◆ NumParameters()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::NumParameters ( Statement const &  stmt,
std::int16_t &  count 
)
noexcept

Reports the number of parameters of the prepared statement.

Parameters
stmtThe statement.
countReceives the parameter count.
Returns
The result of SQLNumParams.

References Lightweight::Driver::NumParameters().

◆ NumRowsAffected()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::NumRowsAffected ( Statement const &  stmt,
std::ptrdiff_t &  count 
)
noexcept

Reports the number of rows the last executed statement affected.

Parameters
stmtThe statement.
countReceives the row count; -1 when the driver cannot tell.
Returns
The result of SQLRowCount.

References Lightweight::Driver::NumRowsAffected().

◆ ColumnName()

LIGHTWEIGHT_API std::expected< std::string, SqlErrorInfo > Lightweight::Driver::Odbc::ColumnName ( Statement const &  stmt,
SqlColumnIndex  column 
)

The name of a result column, as the driver describes it.

Parameters
stmtThe statement, with a result set.
columnThe 1-based result column.
Returns
The column name in UTF-8, or the statement's diagnostics if the column cannot be described.
Note
Not part of the Lightweight::Driver::SqlDriver concept: no driver-neutral caller needs it.

References Lightweight::Driver::Odbc::ColumnName().

Referenced by Lightweight::Driver::Odbc::ColumnName().

◆ ColumnType()

LIGHTWEIGHT_API std::expected< SqlResultColumnType, SqlErrorInfo > Lightweight::Driver::Odbc::ColumnType ( Statement const &  stmt,
SqlColumnIndex  column 
)

The SQL data type of a result column, as the driver describes it.

Parameters
stmtThe statement, with a result set.
columnThe 1-based result column.
Returns
The type, SqlResultColumnType::Unknown for a type without an enumerator, or the statement's diagnostics if the column cannot be described.

References Lightweight::Driver::ColumnType().

◆ ToResultColumnType()

LIGHTWEIGHT_API SqlResultColumnType Lightweight::Driver::Odbc::ToResultColumnType ( std::int16_t  sqlType)
noexcept

Maps an ODBC SQL_* type code onto the driver-neutral SqlResultColumnType.

Parameters
sqlTypeThe SQL_* type code, as DescribeColumn reports it.
Returns
The mapped type, SqlResultColumnType::Unknown for a code without an enumerator.

References Lightweight::Driver::Odbc::ToResultColumnType().

Referenced by Lightweight::Driver::Odbc::CatalogColumnType(), Lightweight::Driver::Odbc::DescribeColumn(), and Lightweight::Driver::Odbc::ToResultColumnType().

◆ SetQueryTimeout()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::SetQueryTimeout ( Statement &  stmt,
std::chrono::seconds  timeout 
)
noexcept

Sets the query timeout of the statement.

Parameters
stmtThe statement.
timeoutThe timeout; zero means none.
Returns
The result of SQLSetStmtAttr.

References Lightweight::Driver::SetQueryTimeout().

◆ QueryTimeout()

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::QueryTimeout ( Statement const &  stmt,
std::chrono::seconds &  timeout 
)
noexcept

Reports the query timeout of the statement.

Parameters
stmtThe statement.
timeoutReceives the timeout; zero means none.
Returns
The result of SQLGetStmtAttr.

References Lightweight::Driver::QueryTimeout().

◆ DescribeResultColumnSqlType() [1/3]

SQLRETURN Lightweight::Driver::Odbc::DescribeResultColumnSqlType ( SQLHSTMT  stmt,
SqlColumnIndex  column,
SQLSMALLINT *  columnType 
)
inlinenoexcept

Asks the driver for the concise SQL type of result column column with SQLDescribeColW.

SQLDescribeCol reports the concise SQL type code (e.g. SQL_TYPE_DATE, SQL_TYPE_TIME, SQL_TYPE_TIMESTAMP). It is asked rather than SQLColAttribute(SQL_DESC_CONCISE_TYPE), which the SQLite driver answers with SQL_WCHAR for a BLOB column. The W variant keeps the ODBC call surface on the Unicode-app path the rest of the library uses. The column name is not needed, but a real buffer with its true length is passed: psqlODBC under unixODBC fails a null or zero-length name buffer with HY001 ("Could not allocate memory for column name"). On the stack, and a name longer than it is only truncated (01004, a success).

Parameters
stmtThe statement handle.
columnThe 1-based column index.
columnTypeReceives the SQL type.
Returns
The driver's return code.

Definition at line 256 of file Statement.hpp.

References Lightweight::Driver::DescribeResultColumnSqlType().

◆ DescribeResultColumnSqlType() [2/3]

std::optional< SQLSMALLINT > Lightweight::Driver::Odbc::DescribeResultColumnSqlType ( SQLHSTMT  stmt,
SqlColumnIndex  column 
)
inlinenoexcept

Asks the driver for the concise SQL type of result column column (see the overload above).

Parameters
stmtThe statement handle.
columnThe 1-based column index.
Returns
The SQL type, or std::nullopt when the driver cannot describe the column.

Definition at line 278 of file Statement.hpp.

References Lightweight::Driver::DescribeResultColumnSqlType().

◆ DescribeResultColumnSqlType() [3/3]

std::optional< std::int16_t > Lightweight::Driver::Odbc::DescribeResultColumnSqlType ( Statement const &  stmt,
SqlColumnIndex  column 
)
inlinenoexcept

Asks the driver for the concise SQL type of result column column (see the overloads above): the Lightweight::Driver::SqlDriver concept's form, which SqlStatement caches for the leaf binders.

Parameters
stmtThe statement.
columnThe 1-based column index.
Returns
The SQL type, or std::nullopt when the driver cannot describe the column.

Definition at line 291 of file Statement.hpp.

References Lightweight::Driver::DescribeResultColumnSqlType().

◆ CurrentParameterArrayLayout()

ParameterArrayLayout Lightweight::Driver::Odbc::CurrentParameterArrayLayout ( Statement const &  stmt,
std::size_t  valueSize,
std::size_t  columnWiseRowCount 
)
inlinenoexcept

Reads the layout of the parameter array the statement is bound with.

Parameters
stmtThe statement whose parameters are being bound.
valueSizeThe size of one value, which is the stride of a column-wise array.
columnWiseRowCountThe row count of a column-wise (or single-row) binding.
Returns
The row size and parameter set size of a row-wise binding, otherwise the column-wise layout.

Definition at line 312 of file Statement.hpp.

References Lightweight::Driver::Odbc::CurrentParameterArrayLayout(), and Lightweight::Driver::Odbc::ParameterArrayLayout::rowStride.

Referenced by Lightweight::Driver::Odbc::CurrentParameterArrayLayout().

◆ CheckResult()

detail::OdbcCallOutcome Lightweight::Driver::Odbc::CheckResult ( Statement const &  stmt,
SqlResult  result,
std::source_location  sourceLocation 
)
inline

The non-throwing, fault-seam-aware verdict on result (see detail::CheckOdbcCall()).

Parameters
stmtThe statement result came from.
resultThe result to check.
sourceLocationWhere the check originated; forwarded to the fault source.
Returns
The verdict, plus the injected diagnostic when one was injected.

Definition at line 335 of file Statement.hpp.

References Lightweight::Driver::CheckResult(), and Lightweight::Driver::Odbc::Statement::handle.

◆ CatalogColumnType()

SqlResultColumnType Lightweight::Driver::Odbc::CatalogColumnType ( Statement const &  stmt,
int  dataType 
)
inlinenoexcept

The type a DATA_TYPE code of a catalog result set (SQLColumns, ...) stands for: the code mapped as ToResultColumnType maps a code SQLDescribeCol reports.

Parameters
stmtThe statement holding the catalog result set (unused: the codes are ODBC's).
dataTypeThe SQL_* code, as read from the result set.
Returns
The mapped type; SqlResultColumnType::Unknown for a code without an enumerator, or outside the range of an SQLSMALLINT.

Definition at line 348 of file Statement.hpp.

References Lightweight::Driver::CatalogColumnType(), and Lightweight::Driver::Odbc::ToResultColumnType().

◆ DeclaredBoundColumnSize()

LIGHTWEIGHT_API std::size_t Lightweight::Driver::Odbc::DeclaredBoundColumnSize ( Statement const &  stmt,
SqlColumnIndex  column,
SqlOutputColumnLength  length 
)
noexcept

The declared length of output column column as a bound buffer size: between detail::DefaultBoundColumnSize and detail::MaxDeclaredBoundColumnSize, and detail::DefaultBoundColumnSize for a length the driver does not report or one above the maximum (a MAX or LONG column). One SQLColAttribute call.

Parameters
stmtThe statement holding the result set.
columnThe 1-based column index.
lengthWhich declared length to ask for.
Returns
The number of elements to bind, without a terminator.

References Lightweight::Driver::DeclaredBoundColumnSize(), and Lightweight::Driver::DescribeColumn().

◆ DescribeColumn() [1/2]

SqlResult Lightweight::Driver::Odbc::DescribeColumn ( Statement const &  stmt,
SqlColumnIndex  column,
SqlColumnDescription &  description 
)
inlinenoexcept

Describes a result column (SQLDescribeCol): the Lightweight::Driver::SqlDriver concept's form, with the type mapped by ToResultColumnType.

Parameters
stmtThe statement, with a result set.
columnThe 1-based result column.
descriptionReceives the description.
Returns
The result of SQLDescribeCol.

Definition at line 533 of file Statement.hpp.

References Lightweight::Driver::DescribeColumn(), Lightweight::Driver::Odbc::ToResultColumnType(), and Lightweight::Driver::SqlColumnDescription::type.

◆ RegisterAnsiOnly()

LIGHTWEIGHT_API void Lightweight::Driver::Odbc::RegisterAnsiOnly ( Statement const &  stmt,
Connection const &  connection 
)
noexcept

Records stmt as belonging to a connection whose driver takes text only through the ANSI entry points, so that its diagnostics are read through those as well.

Parameters
stmtThe freshly allocated statement.
connectionThe connection it was allocated on.

References Lightweight::Driver::RegisterAnsiOnly().

◆ ResetRowArrayAttributes()

LIGHTWEIGHT_API void Lightweight::Driver::Odbc::ResetRowArrayAttributes ( Statement &  stmt)
noexcept

Restores single-row, column-bound fetching and unbinds the row status and rows-fetched pointers. The results are not reported. Part of the Lightweight::Driver::SqlDriver concept.

Parameters
stmtThe statement.

References Lightweight::Driver::ResetRowArrayAttributes().

◆ SetColumnWiseParameterArray()

template<typename Check >
void Lightweight::Driver::Odbc::SetColumnWiseParameterArray ( Statement &  stmt,
std::size_t  rowCount,
void *  bindOffset,
Check const &  check 
)

Sets up column-wise parameter-array binding of rowCount parameter sets.

Parameters
stmtThe statement.
rowCountThe number of parameter sets.
bindOffsetThe SQL_ATTR_PARAM_BIND_OFFSET_PTR value.
checkCalled with each attribute's result, right after setting it; throwing stops the setup.

Definition at line 399 of file Statement.hpp.

References Lightweight::Driver::Odbc::Statement::handle, and Lightweight::Driver::Odbc::SetColumnWiseParameterArray().

Referenced by Lightweight::Driver::Odbc::SetColumnWiseParameterArray().

◆ SetRowWiseParameterArray()

template<typename Check >
void Lightweight::Driver::Odbc::SetRowWiseParameterArray ( Statement &  stmt,
std::size_t  rowCount,
std::size_t  rowStride,
ProcessedCount *  processedCount,
Check const &  check 
)

Sets up row-wise parameter-array binding of rowCount parameter sets, rowStride bytes apart.

Parameters
stmtThe statement.
rowCountThe number of parameter sets.
rowStrideThe byte distance between two consecutive parameter sets.
processedCountReceives the number of parameter sets the driver processed.
checkCalled with each attribute's result, right after setting it; throwing stops the setup.

Definition at line 414 of file Statement.hpp.

References Lightweight::Driver::Odbc::Statement::handle, and Lightweight::Driver::Odbc::SetRowWiseParameterArray().

Referenced by Lightweight::Driver::Odbc::SetRowWiseParameterArray().

◆ SetParameterStatusArrays()

template<typename Check >
void Lightweight::Driver::Odbc::SetParameterStatusArrays ( Statement &  stmt,
RowStatus *  paramStatus,
ProcessedCount *  processedCount,
Check const &  check 
)

Binds the arrays the driver reports per-parameter-set status and the processed count into.

Parameters
stmtThe statement.
paramStatusReceives one status per parameter set.
processedCountReceives the number of parameter sets the driver processed.
checkCalled with each attribute's result, right after setting it; throwing stops the setup.

Definition at line 430 of file Statement.hpp.

References Lightweight::Driver::Odbc::Statement::handle, and Lightweight::Driver::Odbc::SetParameterStatusArrays().

Referenced by Lightweight::Driver::Odbc::SetParameterStatusArrays().

◆ SetRowArray()

template<typename Check >
void Lightweight::Driver::Odbc::SetRowArray ( Statement &  stmt,
std::size_t  rowBindType,
std::size_t  arrayDepth,
RowStatus *  rowStatus,
ProcessedCount *  rowsFetched,
Check const &  check 
)

Sets up row-array fetching of up to arrayDepth rows per FetchNextBlock.

Parameters
stmtThe statement.
rowBindTypeThe SQL_ATTR_ROW_BIND_TYPE: 0 (SQL_BIND_BY_COLUMN) for column-wise binding, otherwise the byte distance between two consecutive bound rows.
arrayDepthThe number of rows per block.
rowStatusReceives one status per fetched row.
rowsFetchedReceives the number of rows of the last fetched block.
checkCalled with each attribute's result, right after setting it; throwing stops the setup.

Definition at line 445 of file Statement.hpp.

References Lightweight::Driver::Odbc::Statement::handle, and Lightweight::Driver::Odbc::SetRowArray().

Referenced by Lightweight::Driver::Odbc::SetRowArray().

◆ BindColumn()

LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::BindColumn ( Statement &  stmt,
SqlColumnIndex  column,
std::int16_t  cType,
void *  buffer,
SqlIndicator  bufferLength,
SqlIndicator *  indicators 
)
inlinenoexcept

Binds a result column to a buffer (SQLBindCol).

Parameters
stmtThe statement.
columnThe 1-based result column.
cTypeThe SQL_C_* type to bind as.
bufferThe (first row's) value buffer.
bufferLengthThe byte length of one row's value buffer; ignored for fixed-size C types.
indicatorsThe (first row's) length indicator.
Returns
The result of SQLBindCol.

Definition at line 466 of file Statement.hpp.

References Lightweight::Driver::Odbc::BindColumn().

Referenced by Lightweight::Driver::Odbc::BindColumn(), and Lightweight::Driver::Odbc::BindTextColumn().

◆ BindTextColumn()

LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::BindTextColumn ( Statement &  stmt,
SqlColumnIndex  column,
char *  buffer,
SqlIndicator  bufferLength,
SqlIndicator *  indicators 
)
inlinenoexcept

Binds a result column to a narrow character buffer (SQL_C_CHAR).

Parameters
stmtThe statement.
columnThe 1-based result column.
bufferThe (first row's) character buffer.
bufferLengthThe byte length of one row's buffer, including the NUL terminator.
indicatorsThe (first row's) length indicator.
Returns
The result of SQLBindCol.

Definition at line 483 of file Statement.hpp.

References Lightweight::Driver::Odbc::BindColumn(), and Lightweight::Driver::Odbc::BindTextColumn().

Referenced by Lightweight::Driver::Odbc::BindTextColumn().

◆ BindUtf16TextParameter()

LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::BindUtf16TextParameter ( Statement &  stmt,
std::uint16_t  parameter,
char16_t *  text,
std::size_t  columnSize,
SqlIndicator &  lengthIndicator 
)
inlinenoexcept

Binds UTF-16 text as an input parameter of SQL type SQL_WVARCHAR (SQLBindParameter with SQL_C_WCHAR). lengthIndicator serves as both the buffer length and the length indicator.

Parameters
stmtThe statement.
parameterThe 1-based parameter.
textThe text; must stay alive until the statement is executed.
columnSizeThe declared column size of the parameter.
lengthIndicatorThe byte length of text; must stay alive until the statement is executed. Shared code passes a length >= 0 only: the other drivers do not give ODBC's special lengths a meaning (the native SQLite3 driver fails a negative one with HY090).
Returns
The result of SQLBindParameter.
Note
Part of the Lightweight::Driver::SqlDriver concept: SqlSchema binds the names of its SQL Server catalog queries (sys.*) through it, without naming the driver.

Definition at line 501 of file Statement.hpp.

References Lightweight::Driver::Odbc::BindUtf16TextParameter().

Referenced by Lightweight::Driver::Odbc::BindUtf16TextParameter().

◆ FetchNextBlock()

LIGHTWEIGHT_FORCE_INLINE SqlResult Lightweight::Driver::Odbc::FetchNextBlock ( Statement &  stmt)
inlinenoexcept

Fetches the next block of rows into the row-array bound columns (SQLFetchScroll, SQL_FETCH_NEXT).

Parameters
stmtThe statement.
Returns
The result of SQLFetchScroll; SqlResult::NoData past the last row.

Definition at line 519 of file Statement.hpp.

References Lightweight::Driver::Odbc::FetchNextBlock().

Referenced by Lightweight::Driver::Odbc::FetchNextBlock().

◆ DescribeColumn() [2/2]

LIGHTWEIGHT_API SqlResult Lightweight::Driver::Odbc::DescribeColumn ( Statement const &  stmt,
SqlColumnIndex  column,
ColumnDescription &  description 
)
noexcept

Describes a result column (SQLDescribeCol).

Parameters
stmtThe statement, with a result set.
columnThe 1-based result column.
descriptionReceives the description.
Returns
The result of SQLDescribeCol.

References Lightweight::Driver::DescribeColumn().

◆ DescribeParameterTypes()

LIGHTWEIGHT_API std::vector< std::int16_t > Lightweight::Driver::Odbc::DescribeParameterTypes ( Statement const &  stmt,
std::size_t  count 
)

Describes the declared SQL type of each of the first count parameters (SQLDescribeParam).

Parameters
stmtThe prepared statement.
countThe number of parameters to describe.
Returns
One SQL_* type per parameter, UnknownParameterType where the driver could not say.

References Lightweight::Driver::DescribeParameterTypes().

◆ BoundParameterCount()

LIGHTWEIGHT_API std::int16_t Lightweight::Driver::Odbc::BoundParameterCount ( Statement const &  stmt)
noexcept

The number of parameters currently bound on the statement, read from its application parameter descriptor.

Parameters
stmtThe statement.
Returns
The bound parameter count, or -1 if the descriptor cannot be read.

References Lightweight::Driver::BoundParameterCount().

Variable Documentation

◆ ParamStatusUnused

constexpr RowStatus Lightweight::Driver::Odbc::ParamStatusUnused = SQL_PARAM_UNUSED
inlineconstexpr

The parameter status of a parameter set the driver did not process (SQL_PARAM_UNUSED).

Definition at line 51 of file Statement.hpp.

◆ ParamStatusError

constexpr RowStatus Lightweight::Driver::Odbc::ParamStatusError = SQL_PARAM_ERROR
inlineconstexpr

The parameter status of a parameter set that failed (SQL_PARAM_ERROR).

Definition at line 54 of file Statement.hpp.

◆ RowStatusError

constexpr RowStatus Lightweight::Driver::Odbc::RowStatusError = SQL_ROW_ERROR
inlineconstexpr

The row status of a fetched row the driver could not convert (SQL_ROW_ERROR).

Definition at line 57 of file Statement.hpp.

◆ UnknownParameterType

constexpr std::int16_t Lightweight::Driver::Odbc::UnknownParameterType = SQL_UNKNOWN_TYPE
inlineconstexpr

The declared SQL type DescribeParameterTypes reports for a parameter it could not describe.

Definition at line 60 of file Statement.hpp.