Skip site navigation (1) Skip section navigation (2)

libpq++ and strings.

From: Carlos Moreno <moreno(at)mochima(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: libpq++ and strings.
Date: 2001-05-17 01:04:26
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
I wonder why all the string parameters and return values 
are expressed in the form of char * or const char * ? 

After some time sticking to C++ and learning to hate 
(even more :-)) C strings, I find myself annoyed by 
not being able to do this:

if (db.ExecTuplesOk ("select * from products"))
    for loop ......

        if (db.GetValue(row, "discontinued") == "t")
            cout << "Disconinued";

Or something like this:

// Get results from one query and use one field to 
// produce another query:

string query = "select * from table where ID='" + 
               db.GetValue (row, "prodID") + "'";

Don't you just hate it?  At least the second one is 
not that bad, because the compiler won't let you add 
two pointers.  But the first one slips through the 
compiler, who doesn't have a problem with comparing 
two pointers -- it can not even know that the comparison 
will be unconditionally false to warn you...  :-(

Why not just changing all the parameters and return 
values to `const string &' and/or `string' ?

Any thoughts? 


In response to

  • Re: libpq++ at 2001-05-14 13:17:02 from J. T. Vermeulen


pgsql-interfaces by date

Next:From: J. T. VermeulenDate: 2001-05-17 12:59:34
Subject: Re: libpq++ and strings.
Previous:From: Jan WieckDate: 2001-05-16 19:50:00
Subject: Re: JDBC and numeric datatype...

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group