pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Carlos Moreno <moreno@mochima.com>
To: pgsql-interfaces@postgresql.org
Subject: libpq++ and strings.
Date: Wed, 16 May 2001 21:04:26 -0400
Message-ID: <3B03239A.E4685125@mochima.com> (raw)
References: <20010514151702.F14645@cistron.nl>


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? 


Carlos
--



view thread (4+ messages)  latest in thread

Message-ID: <3B03239A.E4685125@mochima.com>
Permalink:  ../3B03239A.E4685125@mochima.com/
Also on:    postgresql.org/message-id/3B03239A.E4685125@mochima.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: moreno@mochima.com
  Subject: Re: libpq++ and strings.
  In-Reply-To: <3B03239A.E4685125@mochima.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox