Project

General

Profile

Bug #3511 ยป 0001-Fix-for-dbo-ptr_tuples-without-version-fields.patch

Bruce Toll, 08/03/2014 02:21 AM

View differences:

src/Wt/Dbo/Session_impl.h
* dbo_test4c.
*/
if (!statement->getResult(column++, &id)) {
column += (int)mapping->fields.size() + 1; // + version
column += (int)mapping->fields.size() + !!mapping->versionFieldName;
return ptr<C>();
}
......
if (!i->second->isLoaded())
implLoad<C>(*i->second, statement, column);
else
column += (int)mapping->fields.size() + 1; // + version
column += (int)mapping->fields.size() + !!mapping->versionFieldName;
return ptr<C>(i->second);
}
test/dbo/DboTest.C
class B;
class C;
class D;
class E;
bool fractionalSeconds = true;
......
session_->mapClass<B>(SCHEMA "table_b");
session_->mapClass<C>(SCHEMA "table_c");
session_->mapClass<D>(SCHEMA "table_d");
session_->mapClass<E>(SCHEMA "table_e");
try {
session_->dropTables();
......
static const char *versionField() { return 0; }
};
template<>
struct dbo_traits<E> : public dbo_default_traits
{
static const char *versionField() { return 0; }
};
}
}
......
}
};
class E {
public:
std::string name;
E() { }
E(const std::string& aName)
: name(aName)
{ }
bool operator== (const E& other) const {
return name == other.name;
}
template <class Action>
void persist(Action& a)
{
dbo::field(a, name, "name", 1000);
}
};
BOOST_AUTO_TEST_CASE( dbo_test1 )
{
DboFixture f;
......
}
#endif //POSTGRES
}
BOOST_AUTO_TEST_CASE( dbo_test23 )
{
DboFixture f;
dbo::Session *session_ = f.session_;
{
dbo::Transaction t(*session_);
dbo::ptr<E> e1(new E("e1"));
dbo::ptr<C> c1(new C("c1"));
session_->add(e1);
session_->add(c1);
/*
* Note: E has no versionField
*/
typedef dbo::ptr_tuple<E, C>::type EC;
EC ec = session_->query< EC >
("select E, C from \"table_e\" E, \"table_c\" C");
BOOST_REQUIRE(ec.get<0>()->name == "e1");
BOOST_REQUIRE(ec.get<1>()->name == "c1");
}
}
BOOST_AUTO_TEST_CASE( dbo_test24 )
{
DboFixture f;
dbo::Session *session_ = f.session_;
{
dbo::Transaction t(*session_);
#ifdef POSTGRES
dbo::ptr<E> e1(new E("e1"));
session_->add(e1);
/*
* Note: E has no versionField, right join will result in E1 as null
*/
typedef dbo::ptr_tuple<E, E>::type EE;
EE ee = session_->query< EE >
("select \"E1\", \"E2\" from \"table_e\" \"E1\" "
"right join \"table_e\" \"E2\" on \"E1\".id != \"E2\".id");
BOOST_REQUIRE(ee.get<1>()->name == "e1");
#endif //POSTGRES
}
}
BOOST_AUTO_TEST_CASE( dbo_test25 )
{
DboFixture f;
dbo::Session *session_ = f.session_;
{
dbo::Transaction t(*session_);
dbo::ptr<D> d1(new D(Coordinate(42, 43), "d1"));
dbo::ptr<C> c1(new C("c1"));
session_->add(d1);
session_->add(c1);
/*
* Note: D has no versionField
*/
typedef dbo::ptr_tuple<D, C>::type DC;
DC dc = session_->query< DC >
("select D, C from \"table_d\" D, \"table_c\" C");
BOOST_REQUIRE(dc.get<0>()->name == "d1");
BOOST_REQUIRE(dc.get<1>()->name == "c1");
}
}
    (1-1/1)