Hi, I am not sure if this is the correct way to reuse a prepared statement.
 This example generates a memory leak.

struct Student
{
int Id;
boost::optional<std::string> FirstName;
boost::optional<std::string> Email;
boost::optional<long long> Age;
int GroupId;
double Weight;
};

{
transaction tr(sql);
 string firstname;
indicator indFirstName;
string email;
indicator indEmail;
long long age;
indicator indAge;
int groupId;
double weight;
 statement st = (
sql.prepare
<< "insert into Student (firstname, email, age, groupId, weight) "
<< "values (:firstname, :email, :age, :GroupId, :Weight) "
, use(firstname, indFirstName)
, use(email, indEmail)
, use(age, indAge)
, use(groupId)
, use(weight)
);
 auto it = students.cbegin();
for (size_t i = 0; i < size; ++i, ++it) {
 firstname = it->FirstName.is_initialized() ? it->FirstName.get() : "";
indFirstName = it->FirstName.is_initialized() ? i_ok : i_null;
email = it->Email.is_initialized() ? it->Email.get() : "";
indEmail = it->Email.is_initialized() ? i_ok : i_null;
age = it->Age.is_initialized() ? it->Age.get() : 0;
indAge = it->Age.is_initialized() ? i_ok : i_null;
groupId = it->GroupId;
weight = it->Weight;

st.execute(true);
}

tr.commit();
}

The problem is in
src\backends\odbc\standard-use-type.cpp odbc_standard_use_type_backend.
 During the first invokation of execute, a buf_ is allocated, but not
deleted anywhere.  Subsequent invokations allocate a new block of memory
and assign it to buf_.

How should a prepared statement be reused?

CC
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to