I got the bulk fetch working with

Student s;
statement st = (sql.prepare << "select * from Student", into(s));

st.execute();
while (st.fetch()) {
students.push_back(s);
}

with the caveat that s needs to be "reset" in the type_conversion struct
before it's populated every time.  Unfortunately, the same approach doesn't
work for bulk insert.

Student s;
statement st = (sql.prepare
<< "insert into Student (StudentID, firstname, email, age) "
<< "values (:StudentID, :firstname, :email, :age)", use(s));
 if (size == 0 || size > students.size()) size = students.size();
auto it = students.cbegin();
for (size_t i = 0; i < size; ++i, ++it) {
s = *it;
st.execute(true);
}

Seems to me the value of s is read before the statement is prepared.  Any
idea is appreciated.


On Thursday, August 30, 2012, Candy Chiu wrote:

> Hi,
>
> I defined a type_conversion struct for an entity called Student.  Is it
> possible to select into a vector<Student> using this mapper?
>
> template<>
> struct soci::type_conversion<Student>
> { .... }
>
> std::vector<Student> students;
> sql << "select * from Student", into(students);
>
> Thanks.
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to