Skip to content

Commit 06f5f4e

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 06f5f4e

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

src/test/Statement.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,33 @@ BOOST_AUTO_TEST_CASE(constructorWithExplicitDialect)
178178
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true)};
179179
FbDropDatabase attachmentDrop{attachment};
180180

181+
{ // scope
182+
Transaction transaction{attachment};
183+
Statement createTable{attachment, transaction,
184+
"create table test_dialect (amount numeric(18, 2))"};
185+
createTable.execute(transaction);
186+
transaction.commit();
187+
} // scope
188+
189+
{ // scope
190+
Transaction transaction{attachment};
191+
Statement insert{attachment, transaction,
192+
"insert into test_dialect values (cast(1234.56 as numeric(18, 2)))"};
193+
insert.execute(transaction);
194+
transaction.commit();
195+
} // scope
196+
181197
Transaction transaction{attachment};
182-
Statement stmt{
183-
attachment, transaction, "select 1 from rdb$database", StatementOptions().setDialect(SQL_DIALECT_CURRENT)};
198+
// In SQL dialect 1, NUMERIC(18,2) is mapped to DOUBLE PRECISION instead of
199+
// a scaled integer, so getDouble() retrieves the value correctly.
200+
Statement stmt{attachment, transaction, "select amount from test_dialect",
201+
StatementOptions().setDialect(1u)};
184202

185203
BOOST_CHECK(stmt.isValid());
186-
BOOST_CHECK(stmt.execute(transaction));
187-
BOOST_CHECK_EQUAL(stmt.getInt32(0).value(), 1);
204+
BOOST_REQUIRE(stmt.execute(transaction));
205+
auto value = stmt.getDouble(0);
206+
BOOST_REQUIRE(value.has_value());
207+
BOOST_CHECK_CLOSE(*value, 1234.56, 0.001);
188208
}
189209

190210
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)