25#ifndef FBCPP_ATTACHMENT_H
26#define FBCPP_ATTACHMENT_H
31#include "StatementOptions.h"
61 return connectionCharSet;
69 connectionCharSet = value;
110 const std::optional<std::string>&
getRole()
const
144 const std::vector<std::uint8_t>&
getDpb()
const
163 dpb = std::move(value);
172 return createDatabase;
180 createDatabase = value;
197 forcedWrites = value;
202 std::optional<std::string> connectionCharSet;
203 std::optional<std::string> userName;
204 std::optional<std::string> password;
205 std::optional<std::string> role;
206 std::optional<std::uint32_t> sqlDialect;
207 std::optional<bool> forcedWrites;
208 std::vector<std::uint8_t> dpb;
209 bool createDatabase =
false;
232 handle{std::move(o.handle)}
247 handle = std::move(o.handle);
265 disconnectOrDrop(
false);
280 return handle !=
nullptr;
317 template <
typename Params>
318 bool execute(Transaction& transaction, std::string_view sql,
const Params& params);
324 template <
typename Params>
326 Transaction& transaction, std::string_view sql,
const StatementOptions& options,
const Params& params);
332 Transaction& transaction, std::string_view sql,
unsigned maxRows,
const StatementOptions& options = {});
338 template <
typename Params>
339 RowSet
queryRowSet(Transaction& transaction, std::string_view sql,
unsigned maxRows,
const Params& params);
345 template <
typename Params>
346 RowSet
queryRowSet(Transaction& transaction, std::string_view sql,
unsigned maxRows,
347 const StatementOptions& options,
const Params& params);
352 template <
typename T>
354 Transaction& transaction, std::string_view sql,
const StatementOptions& options = {});
360 template <
typename T,
typename Params>
361 std::optional<T>
queryScalar(Transaction& transaction, std::string_view sql,
const Params& params);
367 template <
typename T,
typename Params>
369 Transaction& transaction, std::string_view sql,
const StatementOptions& options,
const Params& params);
374 template <
typename T>
376 Transaction& transaction, std::string_view sql,
const StatementOptions& options = {});
382 template <
typename T,
typename Params>
383 std::optional<T>
queryFirstRowAs(Transaction& transaction, std::string_view sql,
const Params& params);
389 template <
typename T,
typename Params>
391 Transaction& transaction, std::string_view sql,
const StatementOptions& options,
const Params& params);
394 void disconnectOrDrop(
bool drop);
395 RowSet queryPreparedRowSet(Statement& statement, Transaction& transaction,
unsigned maxRows);
399 FbRef<fb::IAttachment> handle;
402 template <
typename T>
406 auto rowSet =
queryRowSet(transaction, sql, 1u, options);
408 if (rowSet.getCount() == 0u)
411 return rowSet.getRow(0).get<std::optional<T>>(0);
414 template <
typename T>
418 auto rowSet =
queryRowSet(transaction, sql, 1u, options);
420 if (rowSet.getCount() == 0u)
423 return rowSet.getRow(0).get<T>();
427#include "Statement.h"
431 template <
typename Params>
437 template <
typename Params>
441 Statement statement{*
this, transaction, sql, options};
442 statement.set(params);
443 return statement.execute(transaction);
446 template <
typename Params>
448 Transaction& transaction, std::string_view sql,
unsigned maxRows,
const Params& params)
453 template <
typename Params>
457 Statement statement{*
this, transaction, sql, options};
458 statement.set(params);
459 return queryPreparedRowSet(statement, transaction, maxRows);
462 template <
typename T,
typename Params>
465 auto rowSet =
queryRowSet(transaction, sql, 1u, params);
467 if (rowSet.getCount() == 0u)
470 return rowSet.getRow(0).template get<std::optional<T>>(0);
473 template <
typename T,
typename Params>
477 auto rowSet =
queryRowSet(transaction, sql, 1u, options, params);
479 if (rowSet.getCount() == 0u)
482 return rowSet.getRow(0).template get<std::optional<T>>(0);
485 template <
typename T,
typename Params>
488 auto rowSet =
queryRowSet(transaction, sql, 1u, params);
490 if (rowSet.getCount() == 0u)
493 return rowSet.getRow(0).template get<T>();
496 template <
typename T,
typename Params>
500 auto rowSet =
queryRowSet(transaction, sql, 1u, options, params);
502 if (rowSet.getCount() == 0u)
505 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.
void disconnect()
Disconnects from the database.
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...
void dropDatabase()
Drops the database.
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.