Skip to content

Commit 83806af

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 83806af

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

src/test/Statement.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,30 @@ 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, "create table test_dialect (amount numeric(18, 2))"};
184+
createTable.execute(transaction);
185+
transaction.commit();
186+
} // scope
187+
188+
{ // scope
189+
Transaction transaction{attachment};
190+
Statement insert{attachment, transaction, "insert into test_dialect values (cast(1234.56 as numeric(18, 2)))"};
191+
insert.execute(transaction);
192+
transaction.commit();
193+
} // scope
194+
181195
Transaction transaction{attachment};
182-
Statement stmt{
183-
attachment, transaction, "select 1 from rdb$database", StatementOptions().setDialect(SQL_DIALECT_CURRENT)};
196+
// In SQL dialect 1, NUMERIC(18,2) is mapped to DOUBLE PRECISION instead of
197+
// a scaled integer, so getDouble() retrieves the value correctly.
198+
Statement stmt{attachment, transaction, "select amount from test_dialect", StatementOptions().setDialect(1u)};
184199

185200
BOOST_CHECK(stmt.isValid());
186-
BOOST_CHECK(stmt.execute(transaction));
187-
BOOST_CHECK_EQUAL(stmt.getInt32(0).value(), 1);
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)