@@ -1593,6 +1593,81 @@ TEST_F(InstanceReaderFixture, dynamic_meta_data) {
1593
1593
}
1594
1594
}
1595
1595
1596
+ TEST_F (InstanceReaderFixture, ResetDynamicMetadata) {
1597
+ ASSERT_EQ (SUCCESS, SetupECDb (" ResetDynamicMetadata.ecdb" , SchemaItem (
1598
+ R"xml( <ECSchema schemaName='TestSchema' alias='ts' version='1.0.0' xmlns='http://www.bentley.com/schemas/Bentley.ECXML.3.2'>
1599
+ <ECEntityClass typeName='A'>
1600
+ </ECEntityClass>
1601
+ <ECEntityClass typeName='B'>
1602
+ <BaseClass>A</BaseClass>
1603
+ <ECProperty propertyName='prop' typeName='int' />
1604
+ </ECEntityClass>
1605
+ <ECEntityClass typeName='C'>
1606
+ <BaseClass>A</BaseClass>
1607
+ <ECProperty propertyName='prop' typeName='double' />
1608
+ </ECEntityClass>
1609
+ </ECSchema>)xml" )));
1610
+
1611
+ auto exec = [&](Utf8CP ecsql) {
1612
+ ECSqlStatement stmt;
1613
+ EXPECT_EQ (ECSqlStatus::Success, stmt.Prepare (m_ecdb, ecsql));
1614
+ EXPECT_EQ (BE_SQLITE_DONE, stmt.Step ());
1615
+ m_ecdb.SaveChanges ();
1616
+ };
1617
+
1618
+ auto assertDefault = [](ECSqlStatement& stmt, int cl, Utf8CP displayLabel, Utf8CP propertyName) {
1619
+ ECSqlColumnInfo const * ci;
1620
+ PrimitiveECPropertyCP pr;
1621
+ Utf8CP className = " DynamicECSqlSelectClause" ;
1622
+ ci = &stmt.GetColumnInfo (cl);
1623
+ EXPECT_TRUE (ci->IsDynamic ());
1624
+ EXPECT_TRUE (ci->GetDataType ().IsPrimitive ());
1625
+ pr = ci->GetProperty ()->GetAsPrimitiveProperty ();
1626
+ EXPECT_FALSE (pr->HasId ());
1627
+ EXPECT_EQ (PrimitiveType::PRIMITIVETYPE_String, pr->GetType ());
1628
+ EXPECT_STRCASEEQ (className , pr->GetClass ().GetName ().c_str ());
1629
+ EXPECT_STRCASEEQ (propertyName , pr->GetName ().c_str ());
1630
+ EXPECT_STRCASEEQ (" " , pr->GetDescription ().c_str ());
1631
+ EXPECT_STRCASEEQ (displayLabel , pr->GetDisplayLabel ().c_str ());
1632
+ EXPECT_STRCASEEQ (" json" , pr->GetExtendedTypeName ().c_str ());
1633
+ };
1634
+
1635
+ auto assertDynamic = [](ECSqlStatement& stmt, int cl, Utf8CP displayLabel, Utf8CP propertyName, Utf8CP description, Utf8CP className, PrimitiveType t) {
1636
+ ECSqlColumnInfo const * ci;
1637
+ PrimitiveECPropertyCP pr;
1638
+ ci = &stmt.GetColumnInfo (cl);
1639
+ EXPECT_TRUE (ci->IsDynamic ());
1640
+ EXPECT_TRUE (ci->GetDataType ().IsPrimitive ());
1641
+ pr = ci->GetProperty ()->GetAsPrimitiveProperty ();
1642
+ EXPECT_TRUE (pr->HasId ());
1643
+ EXPECT_EQ (t , pr->GetType ());
1644
+ EXPECT_STRCASEEQ (className , pr->GetClass ().GetName ().c_str ());
1645
+ EXPECT_STRCASEEQ (propertyName, pr->GetName ().c_str ());
1646
+ EXPECT_STRCASEEQ (description , pr->GetDescription ().c_str ());
1647
+ EXPECT_STRCASEEQ (displayLabel, pr->GetDisplayLabel ().c_str ());
1648
+ EXPECT_STRCASEEQ (" " , pr->GetExtendedTypeName ().c_str ());
1649
+ };
1650
+
1651
+ exec (" insert into ts.B ( ecInstanceId, B.prop ) values ( 10, 100 )" );
1652
+ exec (" insert into ts.C ( ecInstanceId, C.prop ) values ( 11, 101 )" );
1653
+
1654
+ const auto sql = R"x(
1655
+ select
1656
+ $->prop
1657
+ from ts.A
1658
+ )x" ;
1659
+
1660
+ ECSqlStatement stmt;
1661
+ ASSERT_EQ (ECSqlStatus::Success, stmt.Prepare (m_ecdb, sql));
1662
+ assertDefault (stmt, 0 , " $->prop" , " __x0024____x002D____x003E__prop" );
1663
+ ASSERT_EQ (BE_SQLITE_ROW, stmt.Step ());
1664
+ assertDynamic (stmt, 0 , " prop" , " prop" , " " , " B" , PrimitiveType::PRIMITIVETYPE_Integer);
1665
+ ASSERT_EQ (BE_SQLITE_ROW, stmt.Step ());
1666
+ assertDynamic (stmt, 0 , " prop" , " prop" , " " , " C" , PrimitiveType::PRIMITIVETYPE_Double);
1667
+ stmt.Reset ();
1668
+ assertDefault (stmt, 0 , " $->prop" , " __x0024____x002D____x003E__prop" );
1669
+ }
1670
+
1596
1671
// ---------------------------------------------------------------------------------------
1597
1672
// @bsimethod
1598
1673
// +---------------+---------------+---------------+---------------+---------------+------
0 commit comments