Hi Jan,
Could you try the latest SVN version of libpqxx? I remember that
something was fixed in this region recently, and I'm not sure if that
fix is in 2.6.9.
Cheers,
Bart
Jan Danielsson wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> Hello,
>
> The following program crashes when I run it (I have marked where):
>
> - -------------------------------------------
> #include <iostream>
> #include <string>
> #include <pqxx/pqxx>
>
>
> class ServerContext
> {
> private:
> pqxx::connection m_conn;
>
> public:
> ServerContext();
>
> bool createSession();
> bool touchSession(const std::string& id);
> };
>
> ServerContext::ServerContext() : m_conn("")
> {
> std::cout << "Foo 1" << std::endl;
> m_conn.prepare("addsess", "INSERT INTO sessions (id,addr) VALUES \
> ($1,$2)");
>
> std::cout << "Foo 2" << std::endl;
> m_conn.prepare("touchsess", "UPDATE sessions WHERE id=$1 SET \
> ts=CURRENT_TIMESTAMP");
>
> }
>
>
> bool ServerContext::createSession()
> {
> pqxx::work w(m_conn, "Insert session");
>
> pqxx::prepare::invocation inv(w.prepared("addsess"));
> inv("deadbeef");
> inv("127.0.0.1");
> pqxx::result r = inv.exec(); // <- crashes here
> /*
> if(r.affected_rows() == 1)
> {
> w.commit();
> return true;
> }
> */
> w.abort();
> return false;
> }
>
>
> bool ServerContext::touchSession(const std::string& id)
> {
> pqxx::work w(m_conn, "Touch session");
>
> pqxx::prepare::invocation inv = w.prepared("touchsess");
> inv("deadbeef");
> pqxx::result r = inv.exec();
>
> if(r.affected_rows() == 1)
> {
> w.commit();
> return true;
> }
> w.abort();
> return false;
> }
>
>
>
> int main()
> {
> ServerContext ctx;
>
> ctx.createSession();
>
> return 0;
> }
> - -------------------------------------------
>
> I traced the problem to pqxx:connection_base::find_prepared() in
> connection_base.cxx:826. It crashes when attempting to run:
>
> 826: throw invalid_argument("Unknown prepared statement '" + statement +
> "'");
>
> The fact that it crashes is obviously a question which needs to be
> answered, but I'm more interested in knowing why it's even (trying to)
> complain(ing) about the prepared statement not being found. Is there
> something wrong with the above code? According to my vast experience in
> these matters, I'm guessing I'm doing something wrong because I haven't
> read the manual properly. :-)
>
> I can post the sql-script to initialize the tables, if someone wants it.
>
> $ uname -m -p -r -s
> NetBSD 3.1 amd64 x86_64
> $ gcc --version
> gcc (GCC) 3.3.3 (NetBSD nb3 20040520)
>
> - --
> Kind regards,
> Jan Danielsson
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (NetBSD)
>
> iD8DBQFGcM58uPlHKFfKXTYRCl/QAJ4vl+oQMzw9uMfjfywZQm+5/b9MfACeNkT0
> NaKALWqtLWBnkfpW+YXH/Fg=
> =m/jF
> -----END PGP SIGNATURE-----
> _______________________________________________
> Libpqxx-general mailing list
> [email protected]
> http://gborg.postgresql.org/mailman/listinfo/libpqxx-general
_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general