2011/11/19 Mateusz Łoskot <[email protected]>:
>        for (int i = 0; i != 10; i++)
>        {
>            sql << "insert into soci_test(val) values(:val)", use(i);
>        }
>
>        statement st1 = (sql.prepare <<
>            "update soci_test set val = val + 1");
>        st1.execute(false);
>        std::cout << st1.get_affected_rows() << std::endl;
>
> It prints1 instead of 10.
>
> Do you get correct results?

No, but I do get correct result when I use execute(true). Since I was
never quite sure what the bool flag to execute really does, I don't
really know why the behavior is as it is. Maybe you can clarify what
the bool really does.

But also note that most probably your code does not actually change
the values in the database (at least it does not for me). So if maybe
the statement is not executed at all, the get_affected_rows might
still be returning the 1 from the last insert statement.

In any case I attached a full example that does work for me. (and has
similar behavior to your example when execute(false) is used for the
update statement).

Best,
 Mika
#include <soci.h>
#include <sqlite3/soci-sqlite3.h>
#include <iostream>

using namespace soci;

const std::string db_file = "test.db";

void init(session& sql)
{
    statement st = (sql.prepare << "CREATE TABLE soci_test(val INTEGER)");
    st.execute(true);
    std::cout << sql.get_last_query() << std::endl;
    std::cout << st.get_affected_rows() << std::endl;

    for (int i = 0; i != 10; i++)
    {
        statement st = (sql.prepare << "insert into soci_test(val) values(:val)", use(i));
        st.execute(true);
        std::cout << sql.get_last_query() << std::endl;
        std::cout << st.get_affected_rows() << std::endl;
    }
}

void update(session& sql)
{
    statement st1 = (sql.prepare << "update soci_test set val = val + 1");
    st1.execute(true);
    std::cout << sql.get_last_query() << std::endl;
    std::cout << st1.get_affected_rows() << std::endl;
}

int main()
{
    session sql(sqlite3, db_file);

    init(sql);
    update(sql);
}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to