Skip to content

Commit 306b2a3

Browse files
committed
Add AttachmentOptions::forcedWrites
1 parent 8df5569 commit 306b2a3

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/fb-cpp/Attachment.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Attachment::Attachment(Client& client, const std::string& uri, const AttachmentO
5757
if (const auto sqlDialect = options.getSqlDialect())
5858
dpbBuilder->insertInt(&statusWrapper, isc_dpb_sql_dialect, static_cast<int>(*sqlDialect));
5959

60+
if (const auto forcedWrites = options.getForcedWrites())
61+
dpbBuilder->insertInt(&statusWrapper, isc_dpb_force_write, *forcedWrites ? 1 : 0);
62+
6063
auto dispatcher = fbRef(master->getDispatcher());
6164
const auto dpbBuffer = dpbBuilder->getBuffer(&statusWrapper);
6265
const auto dpbBufferLen = dpbBuilder->getBufferLength(&statusWrapper);

src/fb-cpp/Attachment.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,30 @@ namespace fbcpp
176176
return *this;
177177
}
178178

179+
///
180+
/// Returns whether forced writes should be enabled when creating the database.
181+
///
182+
const std::optional<bool>& getForcedWrites() const
183+
{
184+
return forcedWrites;
185+
}
186+
187+
///
188+
/// Sets whether forced writes should be enabled when creating the database.
189+
///
190+
AttachmentOptions& setForcedWrites(bool value)
191+
{
192+
forcedWrites = value;
193+
return *this;
194+
}
195+
179196
private:
180197
std::optional<std::string> connectionCharSet;
181198
std::optional<std::string> userName;
182199
std::optional<std::string> password;
183200
std::optional<std::string> role;
184201
std::optional<std::uint32_t> sqlDialect;
202+
std::optional<bool> forcedWrites;
185203
std::vector<std::uint8_t> dpb;
186204
bool createDatabase = false;
187205
};

src/test/Attachment.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "TestUtil.h"
2626
#include "fb-cpp/Attachment.h"
2727
#include "fb-cpp/Exception.h"
28+
#include "fb-cpp/Statement.h"
29+
#include "fb-cpp/Transaction.h"
2830
#include <exception>
2931

3032

@@ -69,6 +71,26 @@ BOOST_AUTO_TEST_CASE(sqlDialectSetterGetter)
6971
BOOST_CHECK_EQUAL(*options.getSqlDialect(), 1u);
7072
}
7173

74+
BOOST_AUTO_TEST_CASE(forcedWritesDefault)
75+
{
76+
AttachmentOptions options;
77+
BOOST_CHECK(!options.getForcedWrites().has_value());
78+
}
79+
80+
BOOST_AUTO_TEST_CASE(createDatabaseWithForcedWritesOff)
81+
{
82+
const auto database = getTempFile("Attachment-createDatabaseWithForcedWritesOff.fdb");
83+
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)};
84+
FbDropDatabase attachmentDrop{attachment};
85+
86+
Transaction transaction{attachment};
87+
Statement stmt{attachment, transaction, "select mon$forced_writes from mon$database"};
88+
BOOST_REQUIRE(stmt.execute(transaction));
89+
BOOST_REQUIRE(stmt.getInt32(0).has_value());
90+
BOOST_CHECK_EQUAL(*stmt.getInt32(0), 0);
91+
transaction.commit();
92+
}
93+
7294
BOOST_AUTO_TEST_CASE(isNotValidAfterMove)
7395
{
7496
const auto database = getTempFile("Attachment-isNotValidAfterMove.fdb");

0 commit comments

Comments
 (0)