My bad.  I was retyping code into the email that I was looking at via VNC on
the linux box which is why it got a bit mangled.  I was finally able to
transfer it over (had to restart Eclipse).  I yanked extra stuff that
doesn't matter (logging, etc).  As far as I can tell I have brought
everything up to the absolute latest version either via Fedora 6's Update
mechanism or by building from source.  My database has 1 table named items
which has (itemname varchar, quantity int, productid int).  I originally had
the code without the semicolon but added it while trying to track this down.
I just tried it with "select" lowercase but that didn't help.

Thanks for the pointer about exceptions to references, I hadn't thought
about it that way.

  try {
    if ( conn == NULL ) {
      conn = new connection("dbname=testdb user=postgres");

      work Xaction(*conn, "DemoTransaction");
      result R = Xaction.exec("select * from items");

      // Load the dispensers from the database
      for (result::size_type i = 0; i != R.size(); ++i) {
        std::string itemname = String::F("%s", R[i]["itemname"].c_str());
        int quantity, productId;
        R[i]["quantity"].to(quantity);
        R[i]["productid"].to(productId);
        
        mProductList.Load(productId, itemname, quantity);
      }
     }
    } catch(pqxx::sql_error sqlE) {

      return false; 
    } catch (pqxx::broken_connection bcE) {

      return false;
    } catch (...) {

      return false;
    }

-----Original Message-----
From: Jeroen T. Vermeulen [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 16, 2006 11:53 PM
To: Kevin Lambert
Cc: [email protected]
Subject: Re: [libpqxx-general] pqxx::sql_error on "SELECT * FROM ITEMS"


On Fri, November 17, 2006 01:38, Kevin Lambert wrote:
> I have a Fedora Linux box that I just upgraded from FC3 to FC6.  This 
> code worked fine under FC3 (it would show me all of the times in the 
> "items" database.  The code is at the end of the email.  Under FC6 I 
> am receiving a pqxx::sql_error message which has my select statement 
> in it.  If I do that select statement from psql it works fine.  Any 
> ideas?

Well, lots of variables there (postgres version, libpq version, libpqxx
version, possible changes in setup, and so on) so we may have to cull those
down a bit.  Let's look at the code first, though:


> Try {

Ahem.  :)


> conn = new connection("dbname=testdb user=postgres");
>
> work Xaction(*conn, "DemoTransaction");

It's at least possible that you're running into a bug with handling of
upper-case characters in names.  It shouldn't be a problem with
transactions, but you could try using an all-lower-case name just to be sure
that this isn't related to the problem.


> result R = Xaction.exec("SELECT * from items;");

This is where it hurts, right?

The semicolon isn't really right there.  It *shouldn't* cause any problems,
but who knows, it may.  The semicolon is used as a separator between
queries, so it's almost like you're issuing two queries at once
here: first a SELECT and then an empty one.


> for (result::size_type i=0; i != R.size(); ++I ) {
>       String itemname = R[i]["itemname"]'

It would help if you could post code that really does reproduce the problem.
This line wouldn't even compile because of the extra quote.


>       Int quantity, productId;
>       R[i]["quantity"].to(quantity);
>       R[i]["productid"].to(productId);

There are no "String" and "Int" types in C++, so are these typedefs for
std::string and int?


> }
> } catch(pqxx::sql_error sqlE) {
> }

This really doesn't have anything to do with the problem, but always try to
catch *references* to exception objects:

} catch (pqxx::sql_error &sqlE) {

If you leave out the reference, an exception object of a type derived from
the one you're catching may get "sliced."  In this case, that means that if
the exception is an object of some child class of sql_error, what you will
get is a new object of type sql_error.  Some information can be lost, which
is bad, but things get even worse when virtual functions are involved.


Jeroen

_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to