Skip to content

Commit 79043eb

Browse files
committed
Improve constructorWithExplicitDialect test to verify dialect 1 numeric-as-double behavior
In SQL dialect 1, NUMERIC(18,2) columns are described as DOUBLE PRECISION instead of scaled integers. The updated test inserts a value into a NUMERIC(18,2) table column, then selects it using s dialect-1-prepared statement and verifies that getDouble() retrieves the correct value, exercising the dialect-specific type mapping.
1 parent 3ad2069 commit 79043eb

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

src/test/Statement.cpp

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

178-
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true)};
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)};
179191
FbDropDatabase attachmentDrop{attachment};
180192

181193
Transaction transaction{attachment};
182-
Statement stmt{
183-
attachment, transaction, "select 1 from rdb$database", StatementOptions().setDialect(SQL_DIALECT_CURRENT)};
184194

195+
// SQL_DIALECT_CURRENT (3) does not match database dialect 1 and is rejected,
196+
// proving statement dialect controls the behavior.
197+
BOOST_CHECK_THROW(
198+
Statement(attachment, transaction, "select cast(1234.56 as numeric(18, 2)) from rdb$database"), FbCppException);
199+
200+
// With dialect 1 explicitly set, NUMERIC(18,2) is described as DOUBLE
201+
// PRECISION and the value is retrieved via getDouble().
202+
Statement stmt{attachment, transaction, "select cast(1234.56 as numeric(18, 2)) from rdb$database",
203+
StatementOptions().setDialect(1u)};
185204
BOOST_CHECK(stmt.isValid());
186-
BOOST_CHECK(stmt.execute(transaction));
187-
BOOST_CHECK_EQUAL(stmt.getInt32(0).value(), 1);
205+
BOOST_CHECK(stmt.getOutputDescriptors()[0].adjustedType == DescriptorAdjustedType::DOUBLE);
206+
BOOST_REQUIRE(stmt.execute(transaction));
207+
auto value = stmt.getDouble(0);
208+
BOOST_REQUIRE(value.has_value());
209+
BOOST_CHECK_CLOSE(*value, 1234.56, 0.001);
188210
}
189211

190212
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)