StormByte-Database 2.0.0
C++26 database module of the StormByte suite
 
Loading...
Searching...
No Matches
StormByte::Database::MSSQL::MSSQL Class Reference

Microsoft SQL Server backend. More...

#include <StormByte/database/mssql/mssql.hxx>

Inheritance diagram for StormByte::Database::MSSQL::MSSQL:
Collaboration diagram for StormByte::Database::MSSQL::MSSQL:

Public Member Functions

 MSSQL (const MSSQL &)=delete
 Deleted copy constructor.
 
 MSSQL (MSSQL &&other) noexcept
 Move constructor.
 
MSSQL & operator= (const MSSQL &)=delete
 Deleted copy assignment.
 
MSSQL & operator= (MSSQL &&other) noexcept
 Move assignment.
 
 ~MSSQL () noexcept override
 Disconnect and release the DB-Library process.
 
ExpectedRows Query (std::string_view query) noexcept override
 Execute a SQL batch and collect its first result set.
 
bool SilentQuery (std::string_view query) noexcept override
 Execute a SQL batch without returning rows.
 
- Public Member Functions inherited from StormByte::Database::Database
 Database (const StormByte::Safe::Shared< Logger::Log > &logger)
 Construct with an optional logger.
 
 Database (const Database &)=delete
 Copy constructor (deleted).
 
 Database (Database &&other) noexcept
 Move constructor.
 
Database & operator= (const Database &)=delete
 Copy assignment (deleted).
 
Database & operator= (Database &&other) noexcept
 Move assignment.
 
virtual ~Database () noexcept
 Destructor.
 
StormByte::Safe::Shared< Telemetry > GetTelemetry () const noexcept
 Obtain the cumulative connection telemetry handle.
 
bool Connect () noexcept
 Connect.
 
void Disconnect () noexcept
 Disconnect.
 
bool IsConnected () const noexcept
 Whether the connection is open.
 
void SetSslMode (SslMode mode) noexcept
 TLS policy for the next Connect().
 
SslMode GetSslMode () const noexcept
 Current TLS policy.
 
template<typename... Args>
ExpectedRows ExecuteSTMT (std::string_view name, Args &&...args)
 Execute a prepared statement by name.
 
Expected< Transaction, TransactionError > BeginTransaction (IsolationLevel level=IsolationLevel::Default)
 Begin a transaction.
 
void CommitTransaction ()
 Commit the current transaction.
 
void RollbackTransaction ()
 Roll back the current transaction.
 

Protected Member Functions

 MSSQL (std::string_view host, std::string_view user, std::string_view password, std::string_view database, int port, const StormByte::Safe::Shared< Logger::Log > &logger)
 Construct from copied connection settings.
 
bool DoSilentQuery (std::string_view query) noexcept override
 Execute an internal no-result query.
 
- Protected Member Functions inherited from StormByte::Database::Database
void SetTelemetry (StormByte::Safe::Shared< Telemetry > telemetry) noexcept
 Replace the telemetry implementation, normally in a concrete backend constructor.
 
void RecordBackendEvent (BackendEvent event) noexcept
 Record a categorized event reported by the active backend.
 
Telemetry::OperationScope TrackOperation (Operation operation) const noexcept
 Start timing a Database operation without invoking user callbacks.
 
void ClearPreparedSTMTs () noexcept
 Destroy all registered statements inside the Database module.
 
void PrepareSTMT (std::string_view name, std::string_view query) noexcept
 Register a prepared statement under name.
 
void DoPrepareSTMT (std::string_view name, std::string_view query) noexcept
 Same as PrepareSTMT; kept for hook symmetry.
 
virtual void DoPreConnect () noexcept
 Pre-connect hook.
 
virtual void DoPostConnect () noexcept
 Post-connect hook.
 
virtual void DoPostDisconnect () noexcept
 Post-disconnect hook.
 

Friends

class PreparedSTMT
 

Additional Inherited Members

- Protected Attributes inherited from StormByte::Database::Database
StormByte::Safe::Shared< std::recursive_mutex > m_operation_mutex
 DLL-safe owner of the connection mutex.
 
StormByte::Safe::Shared< Telemetry > m_telemetry
 Shared cumulative counters for this connection.
 
bool m_connected
 Connection state.
 
SslMode m_ssl_mode
 TLS policy for network backends.
 
StormByte::Safe::Shared< Logger::Log > m_logger
 Shared logger, safe across the DLL boundary.
 

Detailed Description

Microsoft SQL Server backend.

Note
Prepared statements execute through sp_executesql RPC with typed parameters.
The backend serializes each connection through Database's operation mutex.

Constructor & Destructor Documentation

◆ MSSQL() [1/3]

StormByte::Database::MSSQL::MSSQL::MSSQL ( const MSSQL &  )
delete

Deleted copy constructor.

◆ MSSQL() [2/3]

StormByte::Database::MSSQL::MSSQL::MSSQL ( MSSQL &&  other)
noexcept

Move constructor.

Parameters
otherBackend to move from.

◆ ~MSSQL()

StormByte::Database::MSSQL::MSSQL::~MSSQL ( )
overridenoexcept

Disconnect and release the DB-Library process.

◆ MSSQL() [3/3]

StormByte::Database::MSSQL::MSSQL::MSSQL ( std::string_view  host,
std::string_view  user,
std::string_view  password,
std::string_view  database,
int  port,
const StormByte::Safe::Shared< Logger::Log > &  logger 
)
protected

Construct from copied connection settings.

Parameters
hostServer name or address.
userSQL login; empty requests integrated authentication where supported.
passwordSQL login password.
databaseInitial database name.
portTDS TCP port, normally 1433.
loggerOptional logger.

Member Function Documentation

◆ DoSilentQuery()

bool StormByte::Database::MSSQL::MSSQL::DoSilentQuery ( std::string_view  query)
overrideprotectedvirtualnoexcept

Execute an internal no-result query.

Parameters
querySQL text.
Returns
Success.

Implements StormByte::Database::Database.

◆ operator=() [1/2]

MSSQL & StormByte::Database::MSSQL::MSSQL::operator= ( const MSSQL &  )
delete

Deleted copy assignment.

◆ operator=() [2/2]

MSSQL & StormByte::Database::MSSQL::MSSQL::operator= ( MSSQL &&  other)
noexcept

Move assignment.

Parameters
otherBackend to move from.
Returns
This backend.

◆ Query()

ExpectedRows StormByte::Database::MSSQL::MSSQL::Query ( std::string_view  query)
overridevirtualnoexcept

Execute a SQL batch and collect its first result set.

Parameters
querySQL text; embedded NUL is rejected.
Returns
Collected rows or QueryException.

Implements StormByte::Database::Database.

◆ SilentQuery()

bool StormByte::Database::MSSQL::MSSQL::SilentQuery ( std::string_view  query)
overridevirtualnoexcept

Execute a SQL batch without returning rows.

Parameters
querySQL text.
Returns
Success.

Implements StormByte::Database::Database.

Friends And Related Symbol Documentation

◆ PreparedSTMT

friend class PreparedSTMT
friend

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