Skip to content

Commit 7fcb0f5

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 7fcb0f5

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

src/test/Statement.cpp

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

178-
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true)};
178+
// Create a dialect-1 database so that NUMERIC(18, 2) maps to DOUBLE PRECISION.
179+
const std::vector<std::uint8_t> dialect1Dpb = {
180+
isc_dpb_version1,
181+
isc_dpb_sql_dialect,
182+
4,
183+
1,
184+
0,
185+
0,
186+
0,
187+
};
188+
189+
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setDpb(dialect1Dpb)};
179190
FbDropDatabase attachmentDrop{attachment};
180191

181192
Transaction transaction{attachment};
182-
Statement stmt{
183-
attachment, transaction, "select 1 from rdb$database", StatementOptions().setDialect(SQL_DIALECT_CURRENT)};
193+
// In SQL dialect 1, NUMERIC(18,2) is mapped to DOUBLE PRECISION instead of
194+
// a scaled integer, so the output descriptor reports DOUBLE and getDouble()
195+
// retrieves the value correctly.
196+
Statement stmt{attachment, transaction, "select cast(1234.56 as numeric(18, 2)) from rdb$database",
197+
StatementOptions().setDialect(1u)};
184198

185199
BOOST_CHECK(stmt.isValid());
186-
BOOST_CHECK(stmt.execute(transaction));
187-
BOOST_CHECK_EQUAL(stmt.getInt32(0).value(), 1);
200+
BOOST_CHECK(stmt.getOutputDescriptors()[0].adjustedType == DescriptorAdjustedType::DOUBLE);
201+
BOOST_REQUIRE(stmt.execute(transaction));
202+
auto value = stmt.getDouble(0);
203+
BOOST_REQUIRE(value.has_value());
204+
BOOST_CHECK_CLOSE(*value, 1234.56, 0.001);
188205
}
189206

190207
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)