summaryrefslogtreecommitdiff
path: root/slicer/db
diff options
context:
space:
mode:
Diffstat (limited to 'slicer/db')
-rw-r--r--slicer/db/sqlSelectDeserializer.cpp59
-rw-r--r--slicer/db/testSelect.cpp15
2 files changed, 54 insertions, 20 deletions
diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp
index 3abb03b..7836c63 100644
--- a/slicer/db/sqlSelectDeserializer.cpp
+++ b/slicer/db/sqlSelectDeserializer.cpp
@@ -88,28 +88,47 @@ namespace Slicer {
{
auto rmp = mp->GetAnonChild();
if (rmp) {
- if (typeIdColIdx) {
- std::string subclass;
- cmd[*typeIdColIdx] >> subclass;
- rmp = rmp->GetSubclassModelPart(subclass);
- }
- rmp->Create();
- for (auto col = 0u; col < columnCount; col += 1) {
- const DB::Column & c = cmd[col];
- if (!c.isNull()) {
- auto fmpr = rmp->GetAnonChildRef([&c](Slicer::HookCommonPtr h) {
- return boost::iequals(c.name, h->PartName());
- });
- if (fmpr) {
- SqlSourcePtr h = new SqlSource(c);
- auto fmp = fmpr->Child();
- fmp->Create();
- fmp->SetValue(h);
- fmp->Complete();
+ switch (rmp->GetType()) {
+ case Slicer::mpt_Complex:
+ {
+ if (typeIdColIdx) {
+ std::string subclass;
+ cmd[*typeIdColIdx] >> subclass;
+ rmp = rmp->GetSubclassModelPart(subclass);
+ }
+ rmp->Create();
+ for (auto col = 0u; col < columnCount; col += 1) {
+ const DB::Column & c = cmd[col];
+ if (!c.isNull()) {
+ auto fmpr = rmp->GetAnonChildRef([&c](Slicer::HookCommonPtr h) {
+ return boost::iequals(c.name, h->PartName());
+ });
+ if (fmpr) {
+ SqlSourcePtr h = new SqlSource(c);
+ auto fmp = fmpr->Child();
+ fmp->Create();
+ fmp->SetValue(h);
+ fmp->Complete();
+ }
+ }
+ }
+ rmp->Complete();
+ }
+ break;
+ case Slicer::mpt_Simple:
+ {
+ rmp->Create();
+ const DB::Column & c = cmd[0];
+ if (!c.isNull()) {
+ SqlSourcePtr h = new SqlSource(c);
+ rmp->SetValue(h);
+ }
+ rmp->Complete();
}
- }
+ break;
+ default:
+ throw UnsupportedModelType();
}
- rmp->Complete();
}
}
}
diff --git a/slicer/db/testSelect.cpp b/slicer/db/testSelect.cpp
index b5664a1..6cade1d 100644
--- a/slicer/db/testSelect.cpp
+++ b/slicer/db/testSelect.cpp
@@ -99,6 +99,21 @@ BOOST_AUTO_TEST_CASE( select_inherit_single )
BOOST_REQUIRE_EQUAL(300, d2->c);
}
+BOOST_AUTO_TEST_CASE( select_simple_sequence )
+{
+ auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto sel = SelectPtr(db->newSelectCommand(
+ "SELECT string \
+ FROM test \
+ ORDER BY id DESC"));
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::SimpleSeq>(*sel);
+ BOOST_REQUIRE_EQUAL(4, bi.size());
+ BOOST_REQUIRE_EQUAL("text four", bi[0]);
+ BOOST_REQUIRE_EQUAL("text three", bi[1]);
+ BOOST_REQUIRE_EQUAL("text two", bi[2]);
+ BOOST_REQUIRE_EQUAL("text one", bi[3]);
+}
+
BOOST_AUTO_TEST_CASE( select_inherit_sequence )
{
auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));