Re: Using variables from c to be passed into PQexec - Mailing list pgsql-general

From Oliver Elphick
Subject Re: Using variables from c to be passed into PQexec
Date
Msg-id 1014321864.13240.734.camel@linda
Whole thread Raw
In response to Using variables from c to be passed into PQexec  (vikashb@mweb.co.za (Vikash Badal))
List pgsql-general
On Fri, 2002-02-15 at 05:55, Vikash Badal wrote:
> If I do this:
> strcat(querystr,"\"DECLARE mycursor CURSOR FOR select * from currpass
                   ^^
> where sitename = \'tvl\'\");
                          ^^
Why the double quotes?

They turn your command into a single identifier (whose length is limited
to 31 characters):

> NOTICE:  identifier "DECLARE mycursor CURSOR FOR select * from
> currpass where si
> tename = 'tvl'" will be truncated to "DECLARE mycursor CURSOR FOR sel"
> DECLARE CURSOR command failed

I don't think you need to escape the single quotes either:
strcat(querystr,"DECLARE mycursor CURSOR FOR select * from currpass
   where sitename = 'tvl'");

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C

     "My sheep hear my voice, and I know them, and they
      follow me; And I give unto them eternal life; and they
      shall never perish, neither shall any man pluck them
      out of my hand."          John 10:27,28


pgsql-general by date:

Previous
From: Dave Smith
Date:
Subject: Can somebody save my bacon?
Next
From: "Marek"
Date:
Subject: Re: parse error in timestamp function