Skip to content

Commit fcde0f8

Browse files
committed
Add AttachmentOptions::sqlDialect
1 parent 9f6d80e commit fcde0f8

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

src/fb-cpp/Attachment.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Attachment::Attachment(Client& client, const std::string& uri, const AttachmentO
5454
if (const auto role = options.getRole())
5555
dpbBuilder->insertString(&statusWrapper, isc_dpb_sql_role_name, role->c_str());
5656

57+
if (const auto sqlDialect = options.getSqlDialect())
58+
dpbBuilder->insertInt(&statusWrapper, isc_dpb_sql_dialect, static_cast<int>(*sqlDialect));
59+
5760
auto dispatcher = fbRef(master->getDispatcher());
5861
const auto dpbBuffer = dpbBuilder->getBuffer(&statusWrapper);
5962
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
@@ -116,6 +116,23 @@ namespace fbcpp
116116
return *this;
117117
}
118118

119+
///
120+
/// Returns the SQL dialect which will be used to connect to the database.
121+
///
122+
const std::optional<std::uint32_t>& getSqlDialect() const
123+
{
124+
return sqlDialect;
125+
}
126+
127+
///
128+
/// Sets the SQL dialect which will be used to connect to the database.
129+
///
130+
AttachmentOptions& setSqlDialect(std::uint32_t value)
131+
{
132+
sqlDialect = value;
133+
return *this;
134+
}
135+
119136
///
120137
/// Returns the DPB (Database Parameter Block) which will be used to connect to the database.
121138
///
@@ -164,6 +181,7 @@ namespace fbcpp
164181
std::optional<std::string> userName;
165182
std::optional<std::string> password;
166183
std::optional<std::string> role;
184+
std::optional<std::uint32_t> sqlDialect;
167185
std::vector<std::uint8_t> dpb;
168186
bool createDatabase = false;
169187
};

src/test/Attachment.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ BOOST_AUTO_TEST_CASE(dropDatabase)
5959
BOOST_CHECK_THROW(Attachment(CLIENT, database), DatabaseException);
6060
}
6161

62+
BOOST_AUTO_TEST_CASE(sqlDialectSetterGetter)
63+
{
64+
AttachmentOptions options;
65+
BOOST_CHECK(!options.getSqlDialect().has_value());
66+
67+
options.setSqlDialect(1u);
68+
BOOST_REQUIRE(options.getSqlDialect().has_value());
69+
BOOST_CHECK_EQUAL(*options.getSqlDialect(), 1u);
70+
}
71+
6272
BOOST_AUTO_TEST_CASE(isNotValidAfterMove)
6373
{
6474
const auto database = getTempFile("Attachment-isNotValidAfterMove.fdb");

src/test/Statement.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,8 @@ BOOST_AUTO_TEST_CASE(constructorWithExplicitDialect)
175175
{
176176
const auto database = getTempFile("Statement-constructorWithExplicitDialect.fdb");
177177

178-
// Firebird 5 requires that statement dialect matches the database dialect, so
179-
// the test database must be created with dialect 1.
180-
const std::vector<std::uint8_t> dialect1Dpb = {
181-
isc_dpb_version1,
182-
isc_dpb_sql_dialect,
183-
4,
184-
1,
185-
0,
186-
0,
187-
0,
188-
};
189-
190-
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setDpb(dialect1Dpb)};
178+
// Connect using dialect 1.
179+
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setSqlDialect(1u)};
191180
FbDropDatabase attachmentDrop{attachment};
192181

193182
Transaction transaction{attachment};

0 commit comments

Comments
 (0)