|
Lightweight 0.20261105.1
|
#include "../../DataBinder/Core.hpp"#include "../../SqlBindingTypes.hpp"#include "../../SqlError.hpp"#include "../Dispatch.hpp"#include "Diagnostics.hpp"#include "Handles.hpp"#include "SqlOdbcPrelude.hpp"#include <algorithm>#include <cstddef>#include <format>#include <string>#include <utility>#include <sql.h>#include <sqlext.h>Go to the source code of this file.
Functions | |
| template<typename Ops , typename Container , std::size_t UnitBytes, std::size_t TerminatorUnits> | |
| SqlResult | Lightweight::Driver::Odbc::RestoreBoundBuffer (SqlOutputColumnPreFetch &step, ::Lightweight::Driver::StatementHandle &statement) |
The pre-fetch step of PlanBoundBufferRestore: grows the container back to the bound size and re-binds the column if its storage moved. | |
| void | Lightweight::Driver::Odbc::ThrowBoundValueNotReadable (SQLHSTMT stmt, SqlColumnIndex column, SQLLEN totalLength) |
| Fails the fetch of a bound value longer than its buffer that the driver cannot read again. | |
| template<typename Ops , std::size_t UnitBytes, std::size_t TerminatorUnits, typename Container , typename GetData > | |
| std::size_t | Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength (SQLHSTMT stmt, SqlColumnIndex column, SQLSMALLINT cType, Container *result, SQLLEN *indicator, GetData const &getData, std::size_t maxBytes=::Lightweight::detail::MaxUnknownLengthValueBytes) |
Reads a bound value again in full that the driver reported longer than its buffer without saying how long (SQL_NO_TOTAL), in chunks through getData, doubling result as it goes. | |
| template<typename Ops , std::size_t UnitBytes, std::size_t TerminatorUnits, typename Container > | |
| std::size_t | Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength (SQLHSTMT stmt, SqlColumnIndex column, SQLSMALLINT cType, Container *result, SQLLEN *indicator) |
ReadBoundValueOfUnknownLength reading through SQLGetData. | |
| template<typename Ops , std::size_t UnitBytes, std::size_t TerminatorUnits, typename Container > | |
| void | Lightweight::Driver::Odbc::PlanBoundBufferRestore (SqlColumnIndex column, SQLSMALLINT cType, Container *result, SQLLEN *indicator, SqlDataBinderCallback &cb) |
| Keeps an output column that is bound straight into a growable container bound for every fetch of the result set. | |
The ODBC driver's part of binding an output column straight into a growable container: the pre-fetch step that restores the bound buffer before every fetch, the declared-length lookup that sizes it where the driver cannot read a bound column again, and the re-read of a bound value of unknown length. The leaf binders' ODBC overloads (strings, binary) use them; the native SQLite3 driver reads every bound column afresh for each row and needs none of them.
Definition in file BoundOutputColumn.hpp.
| SqlResult Lightweight::Driver::Odbc::RestoreBoundBuffer | ( | SqlOutputColumnPreFetch & | step, |
| ::Lightweight::Driver::StatementHandle & | statement | ||
| ) |
The pre-fetch step of PlanBoundBufferRestore: grows the container back to the bound size and re-binds the column if its storage moved.
| Ops | SqlBasicStringOperations-shaped buffer operations of Container. |
| UnitBytes | Bytes per element of the bound buffer. |
| TerminatorUnits | Elements the bound buffer has beyond its size for the driver's terminator. |
| step | The planned step. |
| statement | The statement the column is bound on (an ODBC statement: only the ODBC binders plan the step). |
SqlResult::Success, or the result of re-binding the column. | std::bad_alloc | When growing the container back allocates (its storage was moved out); the fetch reports that as HY001. |
Definition at line 44 of file BoundOutputColumn.hpp.
References Lightweight::SqlOutputColumnPreFetch::boundData, Lightweight::SqlOutputColumnPreFetch::boundSize, Lightweight::SqlOutputColumnPreFetch::column, Lightweight::SqlOutputColumnPreFetch::cType, Lightweight::Driver::Odbc::Statement::handle, Lightweight::SqlOutputColumnPreFetch::indicator, Lightweight::Driver::Odbc::RestoreBoundBuffer(), Lightweight::SqlOutputColumnPreFetch::target, and Lightweight::Driver::VisitRequired().
Referenced by Lightweight::Driver::Odbc::RestoreBoundBuffer().
|
inline |
Fails the fetch of a bound value longer than its buffer that the driver cannot read again.
The binders' post-processing reads such a value with SQLGetData; a driver without SQL_GD_BOUND (MS SQL Server) refuses that for a bound column. Rather than return the value truncated to the buffer, the fetch fails with this error (SQLSTATE 22001).
| stmt | The statement the column is bound on (its diagnostic names the driver's reason). |
| column | The 1-based column index. |
| totalLength | The value's length as the driver reported it, in bytes, or SQL_NO_TOTAL. |
Definition at line 89 of file BoundOutputColumn.hpp.
References Lightweight::Driver::Diagnose(), Lightweight::Driver::Odbc::Statement::handle, Lightweight::SqlErrorInfo::sqlState, and Lightweight::Driver::Odbc::ThrowBoundValueNotReadable().
Referenced by Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength(), and Lightweight::Driver::Odbc::ThrowBoundValueNotReadable().
| std::size_t Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength | ( | SQLHSTMT | stmt, |
| SqlColumnIndex | column, | ||
| SQLSMALLINT | cType, | ||
| Container * | result, | ||
| SQLLEN * | indicator, | ||
| GetData const & | getData, | ||
| std::size_t | maxBytes = ::Lightweight::detail::MaxUnknownLengthValueBytes |
||
| ) |
Reads a bound value again in full that the driver reported longer than its buffer without saying how long (SQL_NO_TOTAL), in chunks through getData, doubling result as it goes.
Only a row whose value overflowed its bound buffer gets here. The container keeps its grown size, so the caller decides what the value's length means for it, and re-binds the column if the container's storage moved (see PlanBoundBufferRestore), also when this throws.
| Ops | SqlBasicStringOperations-shaped buffer operations of Container. |
| UnitBytes | Bytes per element of the buffer. |
| TerminatorUnits | Elements the bound buffer has beyond its size for the driver's terminator. |
| stmt | The statement the column is bound on (for the driver's diagnostic). |
| column | The 1-based column index. |
| cType | The C data type the column is bound as; a character type takes one element of each chunk for its terminator. |
| result | The bound container. |
| indicator | The column's length/indicator buffer; set to the value's length in bytes. |
| getData | Reads the next chunk: SQLGetData of the column as cType, given the target, its length in bytes and the indicator. |
| maxBytes | The most bytes the container grows to. |
indicator at SQL_NULL_DATA (a column unbound after a failed re-bind is read through here, NULL rows included). | SqlException | 22001 when the driver cannot read the bound column again (see ThrowBoundValueNotReadable) or the value exceeds maxBytes; HY000 when the driver reports a length that contradicts the call. |
Definition at line 132 of file BoundOutputColumn.hpp.
References Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength(), and Lightweight::Driver::Odbc::ThrowBoundValueNotReadable().
Referenced by Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength(), and Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength().
| std::size_t Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength | ( | SQLHSTMT | stmt, |
| SqlColumnIndex | column, | ||
| SQLSMALLINT | cType, | ||
| Container * | result, | ||
| SQLLEN * | indicator | ||
| ) |
ReadBoundValueOfUnknownLength reading through SQLGetData.
Definition at line 185 of file BoundOutputColumn.hpp.
References Lightweight::Driver::Odbc::ReadBoundValueOfUnknownLength().
| void Lightweight::Driver::Odbc::PlanBoundBufferRestore | ( | SqlColumnIndex | column, |
| SQLSMALLINT | cType, | ||
| Container * | result, | ||
| SQLLEN * | indicator, | ||
| SqlDataBinderCallback & | cb | ||
| ) |
Keeps an output column that is bound straight into a growable container bound for every fetch of the result set.
The binder's post-processing shrinks the container to each row's length, so before the next fetch it is grown back to the bound size. When its storage moved — a truncation re-fetch grew it, or the caller moved the value out — the column is re-bound to the new storage, at the larger of the old bound size and the container's current size. Per row this is a size compare and a pointer compare when nothing changed; growing back within the retained capacity allocates nothing, and planning the step allocates nothing either (see SqlOutputColumnPreFetch).
| Ops | SqlBasicStringOperations-shaped buffer operations of Container. |
| UnitBytes | Bytes per element of the bound buffer. |
| TerminatorUnits | Elements the bound buffer has beyond its size for the driver's terminator. |
| column | The 1-based column index. |
| cType | The C data type the column is bound as. |
| result | The bound container. |
| indicator | The column's length/indicator buffer. |
| cb | The binder callback the step is planned on. |
Definition at line 213 of file BoundOutputColumn.hpp.
References Lightweight::Driver::Odbc::PlanBoundBufferRestore(), Lightweight::SqlDataBinderCallback::PlanPreFetchOutputColumn(), and Lightweight::SqlOutputColumnPreFetch::run.
Referenced by Lightweight::Driver::Odbc::PlanBoundBufferRestore().