|
From: Candy C. <can...@gm...> - 2012-08-30 21:17:34
|
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.
>
|