@@ -158,6 +158,57 @@ BOOST_AUTO_TEST_CASE(unsupportedStatementsThrow)
158158 BOOST_CHECK_THROW (Statement (attachment, transaction, " rollback" ), FbCppException);
159159}
160160
161+ BOOST_AUTO_TEST_CASE (dialectDefaultIsCurrent)
162+ {
163+ StatementOptions options;
164+ BOOST_CHECK_EQUAL (options.getDialect (), SQL_DIALECT_CURRENT );
165+ }
166+
167+ BOOST_AUTO_TEST_CASE (dialectSetterGetter)
168+ {
169+ StatementOptions options;
170+ options.setDialect (1u );
171+ BOOST_CHECK_EQUAL (options.getDialect (), 1u );
172+ }
173+
174+ BOOST_AUTO_TEST_CASE (constructorWithExplicitDialect)
175+ {
176+ const auto database = getTempFile (" Statement-constructorWithExplicitDialect.fdb" );
177+
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)};
191+ FbDropDatabase attachmentDrop{attachment};
192+
193+ Transaction transaction{attachment};
194+
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 )};
204+ BOOST_CHECK (stmt.isValid ());
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 );
210+ }
211+
161212BOOST_AUTO_TEST_SUITE_END ()
162213
163214
0 commit comments