[Libpqxx-general] adopting stateless cursor

Jeroen T. Vermeulen jtv at xs4all.nl
Wed Jul 22 20:05:07 UTC 2009


On Wed, July 22, 2009 00:19, Madden, Don (DCOR) wrote:

> I am a new user of libpqxx and I am using version 3.0.3 of  libpqxx. I
> am creating a  "stateless cursor" below and then use then in later
> transactions, i will be adopting this stateless cursor.  See an example
> snippet of code below involving T1, cur1 and T2, cur2. I cannot create
> "cur2" as the complier will not create the underlying SQL cursor as
> there is no "sql_cursor" that takes 4 arguments of transaction, adopted
> cursor name, update policy and ownership policy. Instead the SQL cursor
> expects 3 arguments - transaction, cursor name and ownership policy.
> Please see the details below via an example , the flagged compiler error
> and the constructor definitions for this problem.
>
> As i am new to libpqxx, is there something stupid that I'm doing?

Adopting a cursor is a bit of a nasty process.  Instead, I'd rely on the
"hold" feature to keep one single cursor object alive across transactions.
 You're already enabling "hold" in the constructor invocation, so things
get easier without much in the way of other changes.  No need for "loose"
ownership either.


>     work T1(cnx, "stateless cursor");
>     string query = "select relname from pg_class;";

Don't include the semicolon in the query.  A cursor query gets inserted
into other query text, and you don't want to break that.


>     const string cursorRefName = "loose cursor";
>     stateless_cursor<cursor_base::read_only, cursor_base::loose>
> cur1(T1, query, cursorRefName, true);
>
>     work T2(cnx, "stateless adaptor cursor");

You can't start a new transaction on the connection without finishing the
previous one.  Either commit it or abort it.



> ************************************************
> The information contained in, or attached to, this e-mail, may contain
> confidential information and is intended solely for the use of the
> individual or entity to whom they are addressed and may be subject to
> legal privilege.  If you have received this e-mail in error you should
> notify the sender immediately by reply e-mail, delete the message from
> your system and notify your system manager.  Please do not copy it for any
> purpose, or disclose its contents to any other person.  The views or
> opinions presented in this e-mail are solely those of the author and do
> not necessarily represent those of the company.  The recipient should
> check this e-mail and any attachments for the presence of viruses.  The
> company accepts no liability for any damage caused, directly or
> indirectly, by any virus transmitted in this email.

You've posted this on a publicly archived mailing list.  Just saying.  :-)


Jeroen



More information about the Libpqxx-general mailing list