Обсуждение: Using variables from c to be passed into PQexec

Поиск
Список
Период
Сортировка

Using variables from c to be passed into PQexec

От
vikashb@mweb.co.za (Vikash Badal)
Дата:
Greetings,

I am a novice programmer and I am now totally lost,
I've been through the web trying to find a solution,
If I've posted on the wrong place please advise.


If I have this line in the code, I get there desired result.
res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from currpass
where sitename = 'tvl'");
I get :
------------------------------------------------------------------
sitename       password       date           time

tvl            Zb0sj1sds       2002-02-13     12:21:00
------------------------------------------------------------------

If I do this:
strcat(querystr,"\"DECLARE mycursor CURSOR FOR select * from currpass
where sitename = \'tvl\'\");
fprintf(stdout,"%s\n", querystr);
res = PQexec(conn, querystr);

I get
---------------------------------------------------------------------------
Output of fprintf:
"DECLARE mycursor CURSOR FOR select * from currpass where sitename =
'tvl'"

Error Message:
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

-----------------------------------------------------------------------------

What am I missing ?

Please assist

Vikash

Re: Using variables from c to be passed into PQexec

От
"Tim Barnard"
Дата:
Don't pass in the double-quotes in your call. In other words:

strcat(querystr,"DECLARE mycursor CURSOR FOR select * from currpass
where sitename = \'tvl\'");

should work.

Tim

----- Original Message -----
From: "Vikash Badal" <vikashb@mweb.co.za>
To: <pgsql-general@postgresql.org>
Sent: Thursday, February 14, 2002 9:55 PM
Subject: [GENERAL] Using variables from c to be passed into PQexec


> Greetings,
>
> I am a novice programmer and I am now totally lost,
> I've been through the web trying to find a solution,
> If I've posted on the wrong place please advise.
>
>
> If I have this line in the code, I get there desired result.
> res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from currpass
> where sitename = 'tvl'");
> I get :
> ------------------------------------------------------------------
> sitename       password       date           time
>
> tvl            Zb0sj1sds       2002-02-13     12:21:00
> ------------------------------------------------------------------
>
> If I do this:
> strcat(querystr,"\"DECLARE mycursor CURSOR FOR select * from currpass
> where sitename = \'tvl\'\");
> fprintf(stdout,"%s\n", querystr);
> res = PQexec(conn, querystr);
>
> I get
> --------------------------------------------------------------------------
-
> Output of fprintf:
> "DECLARE mycursor CURSOR FOR select * from currpass where sitename =
> 'tvl'"
>
> Error Message:
> 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
>
> --------------------------------------------------------------------------
---
>
> What am I missing ?
>
> Please assist
>
> Vikash
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: Using variables from c to be passed into PQexec

От
Oliver Elphick
Дата:
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