On Monday 18 January 2010 04:32:41 Maciej Sobczak wrote:
> Hello,
> 
> Shridhar Daithankar wrote:
> > What is the expected way of handling vector ORM mapped objects?
> 
> Bulk operations with ORM mapped types are not supported.
> If you need to read many rows of ORM data, you should use prepared
> statements.


I am using prepaerd statements. PFA a demo program and compilation errors. The 
compile fails at prepare only.

-- 
 Shridhar
#include <soci.h>
#include <soci-postgresql.h>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#undef NDEBUG
#include <cassert>

struct person
{
	std::string name,address;
};

namespace soci {

template<> struct type_conversion<person>
{
	typedef values base_type;
	static void from_base(values const & v, indicator , person & p)
	{
		p.name = v.get<std::string>("name");
		p.address = v.get<std::string>("adderss");
	}

	static void to_base(const person & p, values & v, indicator & ind)
	{
		v.set("name",p.name);
		v.set("adress",p.address);

		ind = soci::i_ok;
	}
};
}

void prepare(std::vector<person> & v, std::size_t n=5)
{
	v.clear();
	for(std::size_t i=0;i<n;i++)
	{
		person p;
		std::stringstream s;
		s << "shridhar" << i;
		p.name = s.str();

		s.clear();s.str("");
		s << "pune" << i << std::endl;
		p.address = s.str();

		v.push_back(p);
	}
}

int main()
{
	using namespace soci;

	try
	{
		session sql(postgresql,"dbname=test");

		std::vector<person> v;
		{
			transaction tr(sql);
			sql.once << "delete from person";
			prepare(v);
			statement st = (sql.prepare << "insert into person(name,address) values(:name,:address)",use(v));

			st.execute(true);

			prepare(v);
			st.execute(true);

			//the vector size is deliberately changed here
			prepare(v,4);
			st.execute(true);

			tr.commit();
		}

		int i = 0;
		{
			v.clear();
			v.resize(8);
			statement st = (sql.prepare << "select name,address from person",into(v));
			st.execute();
			//when fetch returns false, the vector is sized down to zero
			for(;st.fetch();i++);
		}
		assert(i==2);
	}
	catch(std::exception & e)
	{
		std::cout << e.what() << std::endl;
	}
}
...found 56 targets...
...updating 2 targets...
gcc.compile.c++ bin/gcc-4.4.2/release/bulk-orm.o
In file included from /usr/local/include/soci/into.h:13,
                 from /usr/local/include/soci/soci.h:21,
                 from bulk-orm.cpp:1:
/usr/local/include/soci/type-conversion.h: In function 
‘soci::details::use_type_ptr soci::details::do_use(T&, const std::string&, 
soci::details::user_type_tag) [with T = std::vector<person, 
std::allocator<person> >]’:
/usr/local/include/soci/use.h:26:   instantiated from 
‘soci::details::use_type_ptr soci::use(T&, const std::string&) [with T = 
std::vector<person, std::allocator<person> >]’
bulk-orm.cpp:69:   instantiated from here
/usr/local/include/soci/type-conversion.h:268: error: no matching function for 
call to 
‘soci::details::type_ptr<soci::details::use_type_base>::type_ptr(soci::details::conversion_use_type<std::vector<person,
 std::allocator<person> > >*)’
/usr/local/include/soci/type-ptr.h:21: note: candidates are: 
soci::details::type_ptr<T>::type_ptr(T*) [with T = soci::details::use_type_base]
/usr/local/include/soci/type-ptr.h:19: note:                 
soci::details::type_ptr<soci::details::use_type_base>::type_ptr(const 
soci::details::type_ptr<soci::details::use_type_base>&)
/usr/local/include/soci/type-conversion.h: In function 
‘soci::details::into_type_ptr soci::details::do_into(T&, 
soci::details::user_type_tag) [with T = std::vector<person, 
std::allocator<person> >]’:
/usr/local/include/soci/into.h:26:   instantiated from 
‘soci::details::into_type_ptr soci::into(T&) [with T = std::vector<person, 
std::allocator<person> >]’
bulk-orm.cpp:87:   instantiated from here
/usr/local/include/soci/type-conversion.h:256: error: no matching function for 
call to 
‘soci::details::type_ptr<soci::details::into_type_base>::type_ptr(soci::details::conversion_into_type<std::vector<person,
 std::allocator<person> > >*)’
/usr/local/include/soci/type-ptr.h:21: note: candidates are: 
soci::details::type_ptr<T>::type_ptr(T*) [with T = 
soci::details::into_type_base]
/usr/local/include/soci/type-ptr.h:19: note:                 
soci::details::type_ptr<soci::details::into_type_base>::type_ptr(const 
soci::details::type_ptr<soci::details::into_type_base>&)
/usr/local/include/soci/type-conversion.h: In constructor 
‘soci::details::conversion_use_type<std::vector<T, std::allocator<_CharT> > 
>::conversion_use_type(std::vector<T, std::allocator<_CharT> >&, const 
std::string&) [with T = person]’:
/usr/local/include/soci/type-conversion.h:268:   instantiated from 
‘soci::details::use_type_ptr soci::details::do_use(T&, const std::string&, 
soci::details::user_type_tag) [with T = std::vector<person, 
std::allocator<person> >]’
/usr/local/include/soci/use.h:26:   instantiated from 
‘soci::details::use_type_ptr soci::use(T&, const std::string&) [with T = 
std::vector<person, std::allocator<person> >]’
bulk-orm.cpp:69:   instantiated from here
/usr/local/include/soci/type-conversion.h:208: error: no matching function for 
call to ‘soci::details::use_type<std::vector<soci::values, 
std::allocator<soci::values> > >::use_type(std::vector<soci::values, 
std::allocator<soci::values> >&, std::vector<soci::indicator, 
std::allocator<soci::indicator> >&, const std::basic_string<char, 
std::char_traits<char>, std::allocator<char> >&)’
/usr/local/include/soci/values-exchange.h:76: note: candidates are: 
soci::details::use_type<std::vector<soci::values, std::allocator<soci::values> 
> >::use_type()
/usr/local/include/soci/values-exchange.h:74: note:                 
soci::details::use_type<std::vector<soci::values, std::allocator<soci::values> 
> >::use_type(const soci::details::use_type<std::vector<soci::values, 
std::allocator<soci::values> > >&)
/usr/local/include/soci/type-conversion.h: In constructor 
‘soci::details::conversion_into_type<std::vector<T, std::allocator<_CharT> > 
>::conversion_into_type(std::vector<T, std::allocator<_CharT> >&) [with T = 
person]’:
/usr/local/include/soci/type-conversion.h:256:   instantiated from 
‘soci::details::into_type_ptr soci::details::do_into(T&, 
soci::details::user_type_tag) [with T = std::vector<person, 
std::allocator<person> >]’
/usr/local/include/soci/into.h:26:   instantiated from 
‘soci::details::into_type_ptr soci::into(T&) [with T = std::vector<person, 
std::allocator<person> >]’
bulk-orm.cpp:87:   instantiated from here
/usr/local/include/soci/type-conversion.h:145: error: no matching function for 
call to ‘soci::details::into_type<std::vector<soci::values, 
std::allocator<soci::values> > >::into_type(std::vector<soci::values, 
std::allocator<soci::values> >&, std::vector<soci::indicator, 
std::allocator<soci::indicator> >&)’
/usr/local/include/soci/values-exchange.h:101: note: candidates are: 
soci::details::into_type<std::vector<soci::values, std::allocator<soci::values> 
> >::into_type()
/usr/local/include/soci/values-exchange.h:99: note:                 
soci::details::into_type<std::vector<soci::values, std::allocator<soci::values> 
> >::into_type(const soci::details::into_type<std::vector<soci::values, 
std::allocator<soci::values> > >&)

    "g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -fPIC 
-I/usr/local/include/soci -I. -DNDEBUG   -c -o 
"bin/gcc-4.4.2/release/bulk-orm.o" "bulk-orm.cpp"

...failed gcc.compile.c++ bin/gcc-4.4.2/release/bulk-orm.o...
...failed updating 1 target...
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to