summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-09-10 17:17:56 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-09-10 17:17:56 +0100
commit7ff46e8cf51e58a114e0bc1c43b4f0db587165e4 (patch)
tree6b85f919424f32bc57a88074bd261df16e50f99c
parentTemplate specialisations need to be marked DLL_PUBLIC for the case when a sli... (diff)
downloadslicer-7ff46e8cf51e58a114e0bc1c43b4f0db587165e4.tar.bz2
slicer-7ff46e8cf51e58a114e0bc1c43b4f0db587165e4.tar.xz
slicer-7ff46e8cf51e58a114e0bc1c43b4f0db587165e4.zip
Fix the case of reading a single column into a sequence of primitivesslicer-1.3.4
-rw-r--r--slicer/db/sqlSelectDeserializer.cpp59
-rw-r--r--slicer/db/testSelect.cpp15
-rw-r--r--slicer/test/initial/simpleArray1.json1
-rw-r--r--slicer/test/initial/simpleArray2.xml6
-rw-r--r--slicer/test/preprocessor.cpp2
-rw-r--r--slicer/test/serializers.cpp10
-rw-r--r--slicer/test/types.ice1
7 files changed, 73 insertions, 21 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"));
diff --git a/slicer/test/initial/simpleArray1.json b/slicer/test/initial/simpleArray1.json
new file mode 100644
index 0000000..f489673
--- /dev/null
+++ b/slicer/test/initial/simpleArray1.json
@@ -0,0 +1 @@
+["one","two","three"]
diff --git a/slicer/test/initial/simpleArray2.xml b/slicer/test/initial/simpleArray2.xml
new file mode 100644
index 0000000..12de178
--- /dev/null
+++ b/slicer/test/initial/simpleArray2.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SimpleSeq>
+ <element>1</element>
+ <element>2</element>
+ <element>3</element>
+</SimpleSeq>
diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp
index cc67d64..e34632b 100644
--- a/slicer/test/preprocessor.cpp
+++ b/slicer/test/preprocessor.cpp
@@ -13,7 +13,7 @@
namespace fs = boost::filesystem;
-const unsigned int COMPONENTS_IN_TEST_ICE = 39;
+const unsigned int COMPONENTS_IN_TEST_ICE = 40;
BOOST_FIXTURE_TEST_SUITE ( preprocessor, FileStructure );
diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp
index 95e8e87..7c5f252 100644
--- a/slicer/test/serializers.cpp
+++ b/slicer/test/serializers.cpp
@@ -448,6 +448,16 @@ BOOST_AUTO_TEST_CASE( json_objectmapMember )
verifyByFile<TestJson::HasProperitiesPtr, Slicer::JsonFileDeserializer>("objectmapMember.json", checkObjectMapMember);
}
+BOOST_AUTO_TEST_CASE( json_simpleArray )
+{
+ verifyByFile<TestModule::SimpleSeq, Slicer::JsonFileDeserializer>("simpleArray1.json");
+}
+
+BOOST_AUTO_TEST_CASE( xml_simpleArray )
+{
+ verifyByFile<TestModule::SimpleSeq, Slicer::XmlFileDeserializer>("simpleArray2.xml");
+}
+
BOOST_AUTO_TEST_CASE( json_streams )
{
const auto tmpf = tmp / "byStream";
diff --git a/slicer/test/types.ice b/slicer/test/types.ice
index c2ac8f3..311d210 100644
--- a/slicer/test/types.ice
+++ b/slicer/test/types.ice
@@ -50,6 +50,7 @@ module TestModule {
int a;
int b;
};
+ sequence<string> SimpleSeq;
sequence<BuiltIns> BuiltInSeq;
sequence<ClassType> Classes;
sequence<StructType> Structs;