StormByte-Database 2.0.0
C++26 database module of the StormByte suite
 
Loading...
Searching...
No Matches
mssql.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Database.
5 *
6 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
7 */
8
9#pragma once
10
14
15#include <string>
16#include <string_view>
17#include <vector>
18
19struct tds_dblib_dbprocess;
20
25namespace StormByte {
30 namespace Database {
35 namespace MSSQL {
44 public:
46 MSSQL(const MSSQL&) = delete;
48 MSSQL(MSSQL&& other) noexcept;
50 MSSQL& operator=(const MSSQL&) = delete;
52 MSSQL& operator=(MSSQL&& other) noexcept;
54 ~MSSQL() noexcept override;
55
61 ExpectedRows Query(std::string_view query) noexcept override;
63 bool SilentQuery(std::string_view query) noexcept override;
64
65 protected:
75 MSSQL(std::string_view host, std::string_view user, std::string_view password,
76 std::string_view database, int port, const StormByte::Safe::Shared<Logger::Log>& logger);
77
79 bool DoSilentQuery(std::string_view query) noexcept override;
80
81 private:
82 friend class PreparedSTMT;
83 std::string m_host;
84 std::string m_user;
85 std::string m_password;
86 std::string m_database;
87 int m_port;
88 struct tds_dblib_dbprocess* m_connection;
89 std::string m_last_error;
90
92 bool DoConnect() noexcept override;
94 void DoDisconnect() noexcept override;
96 void DoPreDisconnect() noexcept override;
98 StormByte::Safe::Unique<StormByte::Database::PreparedSTMT> CreatePreparedSTMT(
99 std::string_view name, std::string_view query) noexcept override;
101 void DoBeginTransaction(IsolationLevel level) override;
102
104 static int ErrorHandler(struct tds_dblib_dbprocess* process, int severity, int database_error,
105 int operating_system_error, char* database_message, char* operating_system_message);
107 static int MessageHandler(struct tds_dblib_dbprocess* process, int message_number, int state,
108 int severity, char* text, char* server, char* procedure, int line);
110 ExpectedRows ExecuteParameterized(std::string_view query, const std::vector<Value>& parameters);
111 };
112 }
113 }
114}
Abstract backend.
Definition database.hxx:76
Microsoft SQL Server backend.
Definition mssql.hxx:43
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.
MSSQL(MSSQL &&other) noexcept
Move constructor.
MSSQL(const MSSQL &)=delete
Deleted copy constructor.
A logical SQL statement executed through sp_executesql RPC.
Definition prepared_stmt.hxx:39
Type-erased SQL value (NULL, integers, double, text, blob, bool).
Definition value.hxx:68
Expected< Rows, QueryException > ExpectedRows
Query result: Rows or QueryException.
Definition typedefs.hxx:82
IsolationLevel
Isolation for BeginTransaction().
Definition typedefs.hxx:99
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_DATABASE_PUBLIC
Definition visibility.h:54