|
Lightweight 0.20261105.1
|
#include "../../Api.hpp"#include "../../SqlBindingTypes.hpp"#include "../../SqlConnectInfo.hpp"#include "../../SqlError.hpp"#include "../../SqlServerType.hpp"#include "Catalog.hpp"#include "Handles.hpp"#include "SqlOdbcPrelude.hpp"#include "Statement.hpp"#include <expected>#include <source_location>#include <string>#include <utility>#include <sql.h>#include <sqlext.h>Go to the source code of this file.
Functions | |
| LIGHTWEIGHT_API void | Lightweight::Driver::Odbc::Allocate (Connection &connection) noexcept |
Allocates an environment handle set to ODBC 3 and a connection handle on it, unless connection already holds an environment handle. | |
| LIGHTWEIGHT_API std::expected< void, SqlErrorInfo > | Lightweight::Driver::Odbc::Close (Connection &connection, CloseDiagnostic diagnostic) noexcept |
Closes the connection: disconnects it, frees its connection and environment handles and leaves connection empty. | |
| LIGHTWEIGHT_API std::string | Lightweight::Driver::Odbc::DriverNameOf (Connection const &connection, SqlConnectionString const &connectionString) |
Names the driver connectionString reaches without connecting: its DRIVER, else the driver the driver manager lists for its DSN (SQLDataSources), else nothing. | |
| LIGHTWEIGHT_API SqlResult | Lightweight::Driver::Odbc::Disconnect (Connection &connection) noexcept |
Ends the session of the connection (SQLDisconnect), keeping its handles for the next connect. | |
| LIGHTWEIGHT_FORCE_INLINE bool | Lightweight::Driver::Odbc::IsAllocated (Connection const &connection) noexcept |
Tells whether connection holds a connection handle (connected or not). | |
| LIGHTWEIGHT_API bool | Lightweight::Driver::Odbc::IsAlive (Connection const &connection) noexcept |
Tells whether the driver still considers the connection alive (SQL_ATTR_CONNECTION_DEAD). | |
| LIGHTWEIGHT_API SqlErrorInfo | Lightweight::Driver::Odbc::LastError (Connection const &connection) |
| Reads the first diagnostic record of the connection handle. | |
| LIGHTWEIGHT_API std::string | Lightweight::Driver::Odbc::ServerName (Connection const &connection) |
The name of the DBMS the connection is connected to (SQL_DBMS_NAME). | |
| LIGHTWEIGHT_API std::string | Lightweight::Driver::Odbc::ServerVersion (Connection const &connection) |
The version of the DBMS the connection is connected to (SQL_DBMS_VER). | |
| LIGHTWEIGHT_API std::string | Lightweight::Driver::Odbc::DriverName (Connection const &connection) |
The file name of the ODBC driver the connection runs on (SQL_DRIVER_NAME). | |
| LIGHTWEIGHT_API std::string | Lightweight::Driver::Odbc::DatabaseName (Connection const &connection) |
The name of the database in use (SQL_DATABASE_NAME). | |
| LIGHTWEIGHT_API std::string | Lightweight::Driver::Odbc::UserName (Connection const &connection) |
The name of the user the connection is logged in as (SQL_USER_NAME). | |
| LIGHTWEIGHT_API bool | Lightweight::Driver::Odbc::TransactionActive (Connection const &connection) noexcept |
| Tells whether a transaction is open, i.e. autocommit is off. | |
| LIGHTWEIGHT_API bool | Lightweight::Driver::Odbc::TransactionsAllowed (Connection const &connection) noexcept |
Tells whether the data source supports transactions (SQL_TXN_CAPABLE). | |
| LIGHTWEIGHT_API SqlResult | Lightweight::Driver::Odbc::SetAutoCommit (Connection &connection, bool enabled) noexcept |
| Switches autocommit mode on or off. | |
| LIGHTWEIGHT_API SqlResult | Lightweight::Driver::Odbc::Commit (Connection &connection) noexcept |
| Commits the open transaction. | |
| LIGHTWEIGHT_API SqlResult | Lightweight::Driver::Odbc::Rollback (Connection &connection) noexcept |
| Rolls back the open transaction. | |
| LIGHTWEIGHT_API SqlResult | Lightweight::Driver::Odbc::SetIsolation (Connection &connection, SqlIsolationMode mode) noexcept |
| Sets the transaction isolation level of the connection. | |
| LIGHTWEIGHT_API bool | Lightweight::Driver::Odbc::RollbackOpenTransaction (Connection &connection) noexcept |
Rolls back the open transaction and switches autocommit back on (RestoreAutoCommitAfterRollback), stopping at the first step that fails. | |
| detail::OdbcCallOutcome | Lightweight::Driver::Odbc::CheckResult (Connection const &connection, SqlResult result, std::source_location sourceLocation) |
The non-throwing, fault-seam-aware verdict on result of a call on connection (see detail::CheckOdbcConnectionCall()). | |
| LIGHTWEIGHT_API bool | Lightweight::Driver::Odbc::ReadsBoundColumnsAgain (Connection const &connection) noexcept |
Tells whether the driver can read a column bound with SQLBindCol again with SQLGetData (SQL_GD_BOUND in SQL_GETDATA_EXTENSIONS). | |
| LIGHTWEIGHT_API::Lightweight::detail::NarrowTextBinding | Lightweight::Driver::Odbc::NarrowTextBinding (Connection const &connection, SqlServerType serverType, SqlConnectInfo const &connectInfo) |
Tells how narrow strings are bound on a connection to serverType. | |
| LIGHTWEIGHT_API std::expected< void, SqlErrorInfo > | Lightweight::Driver::Odbc::Connect (Connection &connection, SqlConnectionString const &connectionString, std::source_location location) |
Connects through a connection string (SQLDriverConnect) and switches autocommit on. | |
| LIGHTWEIGHT_API std::expected< void, SqlErrorInfo > | Lightweight::Driver::Odbc::Connect (Connection &connection, SqlConnectionDataSource const &dataSource, std::source_location location) |
Connects to an ODBC data source (SQLConnect) and switches autocommit on. | |
| LIGHTWEIGHT_API bool | Lightweight::Driver::Odbc::AcceptsWideQueryText (Connection const &connection) noexcept |
Tells whether the driver behind connection receives wide text unchanged. | |
| LIGHTWEIGHT_API SqlResult | Lightweight::Driver::Odbc::RestoreAutoCommitAfterRollback (Connection &connection) noexcept |
| Switches autocommit back on after SqlConnection::RollbackOpenTransaction() rolled back. | |
| LIGHTWEIGHT_API void | Lightweight::Driver::Odbc::RegisterTextEntry (Connection const &connection, bool acceptsWideQueryText) noexcept |
| Records whether the connection's driver takes text through the W entry points, so that the diagnostics of the connection, and of every statement allocated on it later, are read accordingly. | |
| LIGHTWEIGHT_API void | Lightweight::Driver::Odbc::RememberTextEntry (SqlConnectionString const &connectionString, bool acceptsWideQueryText) noexcept |
| Records, process-wide, whether the driver a connection string names accepts wide text, so a later Connect() through it chooses its entry point before connecting. Best effort. | |
| LIGHTWEIGHT_API void | Lightweight::Driver::Odbc::RememberTextEntry (SqlConnectionDataSource const &dataSource, bool acceptsWideQueryText) noexcept |
| Records, process-wide, whether the driver behind a data source accepts wide text, so a later Connect() to it chooses its entry point before connecting. Best effort. | |
The connection and transaction operations of the ODBC driver: everything SqlConnection and SqlTransaction ask an ODBC connection handle to do. The first group is the connection half of the Lightweight::Driver::SqlDriver concept; the second group is ODBC-only (connecting through a connection string or a data source, and the per-driver choice between the W and the ANSI entry points).
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. Calls whose result the caller checks hand it back as Lightweight::SqlResult, so the caller keeps its check at the same point.
Definition in file Connection.hpp.
|
noexcept |
Allocates an environment handle set to ODBC 3 and a connection handle on it, unless connection already holds an environment handle.
The results are not reported: a handle that failed to allocate stays null, and the connect that follows reports the failure. A connection whose environment handle exists but whose connection handle failed to allocate is left as it is.
| connection | The connection to allocate the handles of. |
References Lightweight::Driver::Allocate().
|
noexcept |
Closes the connection: disconnects it, frees its connection and environment handles and leaves connection empty.
The handles are freed whatever the disconnect reports; a refused disconnect (e.g. the SQLite ODBC driver's 25000 "unfinished statements" while statements are allocated) is reported, with the diagnostic read before the connection handle is freed.
| connection | The connection; it must own its handles (not be borrowed). |
| diagnostic | Whether the diagnostic of a refused disconnect is read: a handle never connected refuses with 08003 ("connection not open"), which is not read (CloseDiagnostic::Skip). |
References Lightweight::Driver::Close().
| LIGHTWEIGHT_API std::string Lightweight::Driver::Odbc::DriverNameOf | ( | Connection const & | connection, |
| SqlConnectionString const & | connectionString | ||
| ) |
Names the driver connectionString reaches without connecting: its DRIVER, else the driver the driver manager lists for its DSN (SQLDataSources), else nothing.
| connection | The connection; its environment handle is asked for the data sources. |
| connectionString | The connection string to connect from. |
References Lightweight::Driver::DriverNameOf().
|
noexcept |
Ends the session of the connection (SQLDisconnect), keeping its handles for the next connect.
A successful disconnect also forgets that the connection handle takes text through the ANSI entry points (see RegisterTextEntry()). A refused one leaves the session, and that record, as they were.
| connection | The connection; may hold no connection handle, which is nothing to end. |
SQLDisconnect; SqlResult::Success without a connection handle. References Lightweight::Driver::Disconnect().
|
inlinenoexcept |
Tells whether connection holds a connection handle (connected or not).
| connection | The connection. |
true unless the connection handle is null. Definition at line 83 of file Connection.hpp.
References Lightweight::Driver::IsAllocated().
|
noexcept |
Tells whether the driver still considers the connection alive (SQL_ATTR_CONNECTION_DEAD).
| connection | The connection. |
true when the attribute could be read and reports a live connection. References Lightweight::Driver::IsAlive().
| LIGHTWEIGHT_API SqlErrorInfo Lightweight::Driver::Odbc::LastError | ( | Connection const & | connection | ) |
Reads the first diagnostic record of the connection handle.
Unlike Diagnose(Connection const&), never falls back to the environment handle.
| connection | The connection. |
References Lightweight::Driver::LastError().
| LIGHTWEIGHT_API std::string Lightweight::Driver::Odbc::ServerName | ( | Connection const & | connection | ) |
The name of the DBMS the connection is connected to (SQL_DBMS_NAME).
| connection | The connected connection. |
References Lightweight::Driver::ServerName().
| LIGHTWEIGHT_API std::string Lightweight::Driver::Odbc::ServerVersion | ( | Connection const & | connection | ) |
The version of the DBMS the connection is connected to (SQL_DBMS_VER).
| connection | The connected connection. |
References Lightweight::Driver::ServerVersion().
| LIGHTWEIGHT_API std::string Lightweight::Driver::Odbc::DriverName | ( | Connection const & | connection | ) |
The file name of the ODBC driver the connection runs on (SQL_DRIVER_NAME).
| connection | The connected connection. |
References Lightweight::Driver::DriverName().
| LIGHTWEIGHT_API std::string Lightweight::Driver::Odbc::DatabaseName | ( | Connection const & | connection | ) |
The name of the database in use (SQL_DATABASE_NAME).
| connection | The connected connection. |
References Lightweight::Driver::DatabaseName().
| LIGHTWEIGHT_API std::string Lightweight::Driver::Odbc::UserName | ( | Connection const & | connection | ) |
The name of the user the connection is logged in as (SQL_USER_NAME).
| connection | The connected connection. |
References Lightweight::Driver::UserName().
|
noexcept |
Tells whether a transaction is open, i.e. autocommit is off.
| connection | The connection. |
true when the autocommit attribute was read without diagnostics and is off. References Lightweight::Driver::TransactionActive().
|
noexcept |
Tells whether the data source supports transactions (SQL_TXN_CAPABLE).
| connection | The connected connection. |
true when the capability was read without diagnostics and is not SQL_TC_NONE. References Lightweight::Driver::TransactionsAllowed().
|
noexcept |
Switches autocommit mode on or off.
| connection | The connection. |
| enabled | Whether every statement commits on its own. |
SQLSetConnectAttr. References Lightweight::Driver::SetAutoCommit().
|
noexcept |
Commits the open transaction.
| connection | The connection. |
SQLEndTran. References Lightweight::Driver::Commit().
|
noexcept |
Rolls back the open transaction.
| connection | The connection. |
SQLEndTran. References Lightweight::Driver::Rollback().
|
noexcept |
Sets the transaction isolation level of the connection.
| connection | The connection. |
| mode | The isolation level; not SqlIsolationMode::DriverDefault, which has no ODBC value. |
SQLSetConnectAttr. References Lightweight::Driver::SetIsolation().
|
noexcept |
Rolls back the open transaction and switches autocommit back on (RestoreAutoCommitAfterRollback), stopping at the first step that fails.
| connection | The connection, with a transaction open. |
References Lightweight::Driver::RollbackOpenTransaction().
|
inline |
The non-throwing, fault-seam-aware verdict on result of a call on connection (see detail::CheckOdbcConnectionCall()).
| connection | The connection result came from. |
| result | The result to check. |
| sourceLocation | Where the check originated; forwarded to the fault source. |
Definition at line 170 of file Connection.hpp.
References Lightweight::Driver::CheckResult(), and Lightweight::Driver::Odbc::Connection::dbc.
|
noexcept |
Tells whether the driver can read a column bound with SQLBindCol again with SQLGetData (SQL_GD_BOUND in SQL_GETDATA_EXTENSIONS).
| connection | The connected connection. |
true when the driver reports SQL_GD_BOUND; false when it does not, or cannot be asked. References Lightweight::Driver::ReadsBoundColumnsAgain().
| LIGHTWEIGHT_API::Lightweight::detail::NarrowTextBinding Lightweight::Driver::Odbc::NarrowTextBinding | ( | Connection const & | connection, |
| SqlServerType | serverType, | ||
| SqlConnectInfo const & | connectInfo | ||
| ) |
Tells how narrow strings are bound on a connection to serverType.
The SQLite ODBC driver's OEMCP option (Windows only) makes it convert SQL_C_CHAR with the thread's ANSI code page. The driver takes the option from the connection string, then from the data source's profile; when neither sets it, it is on for a data-source connect (SQLConnect) and off for a connection string. Every other case is detail::NarrowTextBindingOf(serverType).
| connection | The connected connection. |
| serverType | The connected backend. |
| connectInfo | What the connection was connected from: a connection string, or a data source. |
| LIGHTWEIGHT_API std::expected< void, SqlErrorInfo > Lightweight::Driver::Odbc::Connect | ( | Connection & | connection, |
| SqlConnectionString const & | connectionString, | ||
| std::source_location | location | ||
| ) |
Connects through a connection string (SQLDriverConnect) and switches autocommit on.
The session the connection handle had must have been ended first (Disconnect()). A connection string holding non-ASCII text goes to the W or the ANSI entry point as RememberTextEntry() recorded for its driver; failures are not reported to the logger.
| connection | The connection; its handles must be allocated. |
| connectionString | The connection string. |
| location | Where the connect originated; the fault seam sees it as the location of the connection checks. Deliberately without a default: the fault-seam tests match these checks by the caller's function name. |
References Lightweight::Driver::Connect().
| LIGHTWEIGHT_API std::expected< void, SqlErrorInfo > Lightweight::Driver::Odbc::Connect | ( | Connection & | connection, |
| SqlConnectionDataSource const & | dataSource, | ||
| std::source_location | location | ||
| ) |
Connects to an ODBC data source (SQLConnect) and switches autocommit on.
The session the connection handle had must have been ended first (Disconnect()). Sets the login timeout and, on an explicit request, the SQL Server encryption attribute. Every failure but running out of memory is reported to the logger.
| connection | The connection; its handles must be allocated. |
| dataSource | The data source, credentials, timeout and encryption request. |
| location | Where the connect originated; the fault seam sees it as the location of the connection checks. Deliberately without a default: the fault-seam tests match these checks by the caller's function name. |
References Lightweight::Driver::Connect().
|
noexcept |
Tells whether the driver behind connection receives wide text unchanged.
Off Windows, the driver echoes, through SQLNativeSqlW and without a server round trip, a statement holding a CJK character: a driver manager narrowing wide text for an ANSI-only driver cannot carry it. The Windows driver manager converts wide text for such a driver to the ANSI code page it expects, so there the wide entry points are always the right ones.
| connection | The connected connection. |
true when the W entry points carry text intact, including when the driver cannot echo it. References Lightweight::Driver::AcceptsWideQueryText().
|
noexcept |
Switches autocommit back on after SqlConnection::RollbackOpenTransaction() rolled back.
Deliberately keeps the wide entry point (SQLSetConnectAttrW) this call site has always used, whereas SetAutoCommit() keeps the ANSI one SqlTransaction has always used.
| connection | The connection. |
SQLSetConnectAttrW. References Lightweight::Driver::Odbc::RestoreAutoCommitAfterRollback().
Referenced by Lightweight::Driver::Odbc::RestoreAutoCommitAfterRollback().
|
noexcept |
Records whether the connection's driver takes text through the W entry points, so that the diagnostics of the connection, and of every statement allocated on it later, are read accordingly.
| connection | The connected connection. |
| acceptsWideQueryText | What AcceptsWideQueryText() found. |
References Lightweight::Driver::RegisterTextEntry().
|
noexcept |
Records, process-wide, whether the driver a connection string names accepts wide text, so a later Connect() through it chooses its entry point before connecting. Best effort.
| connectionString | The connection string a connection was established with. |
| acceptsWideQueryText | What AcceptsWideQueryText() found for that connection. |
References Lightweight::Driver::Odbc::RememberTextEntry().
Referenced by Lightweight::Driver::Odbc::RememberTextEntry(), and Lightweight::Driver::Odbc::RememberTextEntry().
|
noexcept |
Records, process-wide, whether the driver behind a data source accepts wide text, so a later Connect() to it chooses its entry point before connecting. Best effort.
| dataSource | The data source a connection was established to. |
| acceptsWideQueryText | What AcceptsWideQueryText() found for that connection. |
References Lightweight::Driver::Odbc::RememberTextEntry().