25#ifndef FBCPP_ATTACHMENT_H
26#define FBCPP_ATTACHMENT_H
28#include "fb-cpp-export.h"
32#include "StatementOptions.h"
62 return connectionCharSet;
70 connectionCharSet = value;
111 const std::optional<std::string>&
getRole()
const
145 const std::vector<std::uint8_t>&
getDpb()
const
164 dpb = std::move(value);
173 return createDatabase;
181 createDatabase = value;
198 forcedWrites = value;
203 std::optional<std::string> connectionCharSet;
204 std::optional<std::string> userName;
205 std::optional<std::string> password;
206 std::optional<std::string> role;
207 std::optional<std::uint32_t> sqlDialect;
208 std::optional<bool> forcedWrites;
209 std::vector<std::uint8_t> dpb;
210 bool createDatabase =
false;
233 handle{std::move(o.handle)}
248 handle = std::move(o.handle);
266 disconnectOrDrop(
false);
281 return handle !=
nullptr;
328 template <
typename Params>
329 bool execute(Transaction& transaction, std::string_view sql,
const Params& params);
335 template <
typename Params>
337 Transaction& transaction, std::string_view sql,
const StatementOptions& options,
const Params& params);
343 Transaction& transaction, std::string_view sql,
unsigned maxRows,
const StatementOptions& options = {});
349 template <
typename Params>
350 RowSet queryRowSet(Transaction& transaction, std::string_view sql,
unsigned maxRows,
const Params& params);
356 template <
typename Params>
357 RowSet queryRowSet(Transaction& transaction, std::string_view sql,
unsigned maxRows,
358 const StatementOptions& options,
const Params& params);
363 template <
typename T>
364 std::optional<T> queryScalar(
365 Transaction& transaction, std::string_view sql,
const StatementOptions& options = {});
371 template <
typename T,
typename Params>
372 std::optional<T> queryScalar(Transaction& transaction, std::string_view sql,
const Params& params);
378 template <
typename T,
typename Params>
379 std::optional<T> queryScalar(
380 Transaction& transaction, std::string_view sql,
const StatementOptions& options,
const Params& params);
385 template <
typename T>
386 std::optional<T> queryFirstRowAs(
387 Transaction& transaction, std::string_view sql,
const StatementOptions& options = {});
393 template <
typename T,
typename Params>
394 std::optional<T> queryFirstRowAs(Transaction& transaction, std::string_view sql,
const Params& params);
400 template <
typename T,
typename Params>
401 std::optional<T> queryFirstRowAs(
402 Transaction& transaction, std::string_view sql,
const StatementOptions& options,
const Params& params);
405 void disconnectOrDrop(
bool drop);
406 RowSet queryPreparedRowSet(Statement& statement, Transaction& transaction,
unsigned maxRows);
410 FbRef<fb::IAttachment> handle;
413 template <
typename T>
417 auto rowSet =
queryRowSet(transaction, sql, 1u, options);
419 if (rowSet.getCount() == 0u)
422 return rowSet.getRow(0).get<std::optional<T>>(0);
425 template <
typename T>
429 auto rowSet =
queryRowSet(transaction, sql, 1u, options);
431 if (rowSet.getCount() == 0u)
434 return rowSet.getRow(0).get<T>();
438#include "Statement.h"
442 template <
typename Params>
448 template <
typename Params>
452 Statement statement{*
this, transaction, sql, options};
453 statement.set(params);
454 return statement.execute(transaction);
457 template <
typename Params>
459 Transaction& transaction, std::string_view sql,
unsigned maxRows,
const Params& params)
464 template <
typename Params>
468 Statement statement{*
this, transaction, sql, options};
469 statement.set(params);
470 return queryPreparedRowSet(statement, transaction, maxRows);
473 template <
typename T,
typename Params>
476 auto rowSet =
queryRowSet(transaction, sql, 1u, params);
478 if (rowSet.getCount() == 0u)
481 return rowSet.getRow(0).template get<std::optional<T>>(0);
484 template <
typename T,
typename Params>
488 auto rowSet =
queryRowSet(transaction, sql, 1u, options, params);
490 if (rowSet.getCount() == 0u)
493 return rowSet.getRow(0).template get<std::optional<T>>(0);
496 template <
typename T,
typename Params>
499 auto rowSet =
queryRowSet(transaction, sql, 1u, params);
501 if (rowSet.getCount() == 0u)
504 return rowSet.getRow(0).template get<T>();
507 template <
typename T,
typename Params>
511 auto rowSet =
queryRowSet(transaction, sql, 1u, options, params);
513 if (rowSet.getCount() == 0u)
516 return rowSet.getRow(0).template get<T>();
Represents options used when creating an Attachment object.
AttachmentOptions & setConnectionCharSet(const std::string &value)
Sets the character set which will be used for the connection.
const std::optional< std::string > & getPassword() const
Returns the password which will be used to connect to the database.
AttachmentOptions & setSqlDialect(std::uint32_t value)
Sets the SQL dialect which will be used to connect to the database.
AttachmentOptions & setPassword(const std::string &value)
Sets the password which will be used to connect to the database.
const std::optional< std::string > & getRole() const
Returns the role which will be used to connect to the database.
AttachmentOptions & setDpb(const std::vector< std::uint8_t > &value)
Sets the DPB (Database Parameter Block) which will be used to connect to the database.
AttachmentOptions & setRole(const std::string &value)
Sets the role which will be used to connect to the database.
AttachmentOptions & setDpb(std::vector< std::uint8_t > &&value)
Sets the DPB (Database Parameter Block) which will be used to connect to the database.
const std::vector< std::uint8_t > & getDpb() const
Returns the DPB (Database Parameter Block) which will be used to connect to the database.
AttachmentOptions & setCreateDatabase(bool value)
Sets whether the database should be created instead of connected to.
const std::optional< std::string > & getUserName() const
Returns the user name which will be used to connect to the database.
bool getCreateDatabase() const
Returns whether the database should be created instead of connected to.
const std::optional< std::string > & getConnectionCharSet() const
Returns the character set which will be used for the connection.
AttachmentOptions & setUserName(const std::string &value)
Sets the user name which will be used to connect to the database.
const std::optional< bool > & getForcedWrites() const
Returns whether forced writes should be enabled when creating the database.
AttachmentOptions & setForcedWrites(bool value)
Sets whether forced writes should be enabled when creating the database.
const std::optional< std::uint32_t > & getSqlDialect() const
Returns the SQL dialect which will be used to connect to the database.
Represents a connection to a Firebird database.
bool execute(Transaction &transaction, std::string_view sql, const StatementOptions &options={})
Prepares and executes an SQL statement using the supplied transaction.
Client & getClient() noexcept
Returns the Client object reference used to create this Attachment object.
FbRef< fb::IAttachment > getHandle() noexcept
Returns the internal Firebird IAttachment handle.
~Attachment() noexcept
Disconnects from the database.
std::optional< T > queryFirstRowAs(Transaction &transaction, std::string_view sql, const StatementOptions &options={})
Prepares and executes a query using the supplied transaction and returns the first row mapped as T.
Attachment(Attachment &&o) noexcept
Move constructor.
bool isValid() noexcept
Returns whether the Attachment object is valid.
std::optional< T > queryScalar(Transaction &transaction, std::string_view sql, const StatementOptions &options={})
Prepares and executes a query using the supplied transaction and returns the first column of the firs...
RowSet queryRowSet(Transaction &transaction, std::string_view sql, unsigned maxRows, const StatementOptions &options={})
Prepares and executes a query using the supplied transaction and returns up to maxRows rows.
Attachment & operator=(Attachment &&o) noexcept
Transfers ownership of another Attachment into this one.
Represents a Firebird client library instance.
Reference-counted smart pointer for Firebird objects using addRef/release semantics.
A disconnected buffer of rows fetched from a Statement's result set.
Represents options used when preparing a Statement.
Prepares, executes, and fetches SQL statements against a Firebird attachment.
Represents a transaction in one or more Firebird databases.