@@ -235,6 +235,67 @@ BOOST_AUTO_TEST_CASE(constructorProvidesMetadataHandles)
235235 BOOST_CHECK (outputDescriptor.adjustedType == DescriptorAdjustedType::STRING );
236236}
237237
238+ BOOST_AUTO_TEST_CASE (descriptorMetadataFields)
239+ {
240+ const auto database = getTempFile (" Statement-descriptorMetadataFields.fdb" );
241+
242+ Attachment attachment{CLIENT , database, AttachmentOptions ().setCreateDatabase (true )};
243+ FbDropDatabase attachmentDrop{attachment};
244+
245+ Transaction transaction{attachment};
246+
247+ Statement createTable{attachment, transaction,
248+ " create table test_meta ("
249+ " id integer not null,"
250+ " name varchar(100),"
251+ " amount numeric(18, 2),"
252+ " data blob sub_type text"
253+ " )" };
254+ createTable.execute (transaction);
255+ transaction.commit ();
256+
257+ Transaction transaction2{attachment};
258+
259+ Statement select{attachment, transaction2, " select t.id as pk, t.name as label, t.amount, t.data from test_meta t" };
260+
261+ const auto & descriptors = select.getOutputDescriptors ();
262+ BOOST_REQUIRE_EQUAL (descriptors.size (), 4U );
263+
264+ // Column 0: t.id as pk
265+ BOOST_CHECK_EQUAL (descriptors[0 ].name , " ID" );
266+ BOOST_CHECK_EQUAL (descriptors[0 ].alias , " PK" );
267+ BOOST_CHECK_EQUAL (descriptors[0 ].relation , " TEST_META" );
268+ BOOST_CHECK (descriptors[0 ].subType == 0 );
269+
270+ // Column 1: t.name as label
271+ BOOST_CHECK_EQUAL (descriptors[1 ].name , " NAME" );
272+ BOOST_CHECK_EQUAL (descriptors[1 ].alias , " LABEL" );
273+ BOOST_CHECK_EQUAL (descriptors[1 ].relation , " TEST_META" );
274+ BOOST_CHECK (descriptors[1 ].adjustedType == DescriptorAdjustedType::STRING );
275+
276+ // Column 2: t.amount (no alias, numeric)
277+ BOOST_CHECK_EQUAL (descriptors[2 ].name , " AMOUNT" );
278+ BOOST_CHECK_EQUAL (descriptors[2 ].alias , " AMOUNT" );
279+ BOOST_CHECK_EQUAL (descriptors[2 ].relation , " TEST_META" );
280+
281+ // Column 3: t.data (blob sub_type text)
282+ BOOST_CHECK_EQUAL (descriptors[3 ].name , " DATA" );
283+ BOOST_CHECK_EQUAL (descriptors[3 ].alias , " DATA" );
284+ BOOST_CHECK_EQUAL (descriptors[3 ].relation , " TEST_META" );
285+ BOOST_CHECK_EQUAL (descriptors[3 ].subType , 1 );
286+
287+ // Input descriptors for a parameterized query
288+ Statement paramSelect{attachment, transaction2, " select t.id from test_meta t where t.id = ?" };
289+
290+ const auto & inDescriptors = paramSelect.getInputDescriptors ();
291+ BOOST_REQUIRE_EQUAL (inDescriptors.size (), 1U );
292+
293+ // Input parameters have empty name/relation/alias
294+ BOOST_CHECK (inDescriptors[0 ].name .empty ());
295+ BOOST_CHECK (inDescriptors[0 ].relation .empty ());
296+ BOOST_CHECK (inDescriptors[0 ].alias .empty ());
297+ }
298+
238299BOOST_AUTO_TEST_SUITE_END ()
239300
240301
0 commit comments