pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedecpg cursors and scope
8+ messages / 4 participants
[nested] [flat]
* ecpg cursors and scope
@ 1999-04-21 01:46 Dave Broudy <shaggy@broudy.net>
0 siblings, 1 reply; 8+ messages in thread
From: Dave Broudy @ 1999-04-21 01:46 UTC (permalink / raw)
To: pgsql-interfaces
I have two senarios about scoping and ecpg's parsing of cursor
declarations:
A) In seperate functions:
func1() {
exec sql declare test_cur for ...
}
func2() {
exec sql declare test_cur for ... /* same or different sql */
}
B) In an if:
if(...) {
exec sql declare test_cur for ...
} else {
exec sql declare test_cur for ... /* same or different sql */
}
These both yield "cursor test_cur already defined"
Is this by design? I seem to remember it working under 6.3.2, and this is
under 6.4.2
If I knew lex/yacc, I'd make an effort at a patch, alas my compilers class
of a few years ago made us parse the old fashioned way :) Does anyone know
of a work-around?
Thanks,
Dave Broudy dave@broudy.net
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] ecpg cursors and scope
@ 1999-04-21 10:36 Pavel PaJaSoft Janousek <janousek@fonet.cz>
0 siblings, 1 reply; 8+ messages in thread
From: Pavel PaJaSoft Janousek @ 1999-04-21 10:36 UTC (permalink / raw)
To: Dave Broudy <shaggy@broudy.net>; +Cc: pgsql-interfaces
>A) In seperate functions:
>
>func1() {
> exec sql declare test_cur for ...
>}
>func2() {
> exec sql declare test_cur for ... /* same or different sql */
>}
>
>B) In an if:
>
>if(...) {
> exec sql declare test_cur for ...
>} else {
> exec sql declare test_cur for ... /* same or different sql */
>}
>
>These both yield "cursor test_cur already defined"
I try this too, but I got the same error... )ECPG distributed with
PostgreSQL 6.4.2)
I think, that principly is correct contructions like this:
if (condition)
{
exec sql declare cur cursor for select count (*) from tmp where
col1 - :num;
}
else
{
exec sql declare cur cursor for select count (*) from tmp;
}
exec sql whenever not found continue;
exec sql open cur;
exec sql whenever not found do break;
while (1)
{
exec sql fetch in cur into :num1;
}
But this isn't allow too, because second exec sql declare.... - in this
line I got the same message...:-(
One time I wrote this exec<space><space>sql - and ECPG say parse error
too, but I forgot, that bad was only this two spaces between 'exec' and
'sql'....
Next, some 'interesting' situations I got when I use exec sql
whenever... - scope for this is not as the program running, but as the
source is parsing... - this is ...'-)
----------------------------------------------------------------------------
--
Pavel Janousek (PaJaSoft) FoNet, spol. s r. o.
Vyvoj software, sprava siti, Unix, Web, Y2K Anenska 11, 602 00
Brno
E-mail: mailto:Janousek@FoNet.Cz Tel.: +420 5 4324
4749
SMS: mailto:P.Janousek@SMS.Paegas.Cz Fax.: +420 5 4324
4751
WWW: http://WWW.FoNet.Cz/ E-mail:
mailto:Info@FoNet.Cz
----------------------------------------------------------------------------
---
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] ecpg cursors and scope
@ 1999-04-21 11:49 Michael Meskes <meskes@postgresql.org>
parent: Dave Broudy <shaggy@broudy.net>
0 siblings, 0 replies; 8+ messages in thread
From: Michael Meskes @ 1999-04-21 11:49 UTC (permalink / raw)
To: Dave Broudy <shaggy@broudy.net>; +Cc: pgsql-interfaces
On Tue, Apr 20, 1999 at 09:46:14PM -0400, Dave Broudy wrote:
> I have two senarios about scoping and ecpg's parsing of cursor
> declarations:
> ...
AFAIK teh standrad the cursor is valid in the scope of its module, i.e. the
source file it's listed in.
> Is this by design? I seem to remember it working under 6.3.2, and this is
> under 6.4.2
The new version does comply much more to the standard.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net | Use PostgreSQL!
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] ecpg cursors and scope
@ 1999-04-22 15:50 Michael Meskes <meskes@postgresql.org>
parent: Pavel PaJaSoft Janousek <janousek@fonet.cz>
0 siblings, 1 reply; 8+ messages in thread
From: Michael Meskes @ 1999-04-22 15:50 UTC (permalink / raw)
To: Pavel PaJaSoft Janousek <janousek@fonet.cz>; +Cc: Dave Broudy <shaggy@broudy.net>; pgsql-interfaces
On Wed, Apr 21, 1999 at 12:36:59PM +0200, Pavel PaJaSoft Janousek wrote:
> I think, that principly is correct contructions like this:
No, to do this you need the PREPARE statement.
> ...
>
> One time I wrote this exec<space><space>sql - and ECPG say parse error
> too, but I forgot, that bad was only this two spaces between 'exec' and
> 'sql'....
Hmm, this is not good.
> Next, some 'interesting' situations I got when I use exec sql
> whenever... - scope for this is not as the program running, but as the
> source is parsing... - this is ...'-)
That's what the standard says. The whenever statement is a preprocessor
statement.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net | Use PostgreSQL!
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] ecpg cursors and scope
@ 1999-04-22 16:16 Margarita Barvinok <brita@math.lsa.umich.edu>
parent: Michael Meskes <meskes@postgresql.org>
0 siblings, 1 reply; 8+ messages in thread
From: Margarita Barvinok @ 1999-04-22 16:16 UTC (permalink / raw)
To: pgsql-interfaces
I just tried to compile my program and found that
exec sql .... statement must have one space between 'exec' and 'sql',
otherwise it is a mistake.
-Margarita
On Thu, 22 Apr 1999, Michael Meskes wrote:
> >
> > One time I wrote this exec<space><space>sql - and ECPG say parse error
> > too, but I forgot, that bad was only this two spaces between 'exec' and
> > 'sql'....
>
> Hmm, this is not good.
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] ecpg cursors and scope
@ 1999-04-23 04:16 Michael Meskes <meskes@postgresql.org>
parent: Margarita Barvinok <brita@math.lsa.umich.edu>
0 siblings, 0 replies; 8+ messages in thread
From: Michael Meskes @ 1999-04-23 04:16 UTC (permalink / raw)
To: Margarita Barvinok <brita@math.lsa.umich.edu>; +Cc: pgsql-interfaces
On Thu, Apr 22, 1999 at 12:16:42PM -0400, Margarita Barvinok wrote:
>
> I just tried to compile my program and found that
>
> exec sql .... statement must have one space between 'exec' and 'sql',
>
> otherwise it is a mistake.
Yes, I will take care of this.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net | Use PostgreSQL!
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] ecpg cursors and scope
@ 1999-04-23 08:17 Pavel PaJaSoft Janousek <janousek@fonet.cz>
0 siblings, 1 reply; 8+ messages in thread
From: Pavel PaJaSoft Janousek @ 1999-04-23 08:17 UTC (permalink / raw)
To: Michael Meskes <meskes@postgresql.org>; +Cc: pgsql-interfaces
>> I think, that principly is correct contructions like this:
>
>No, to do this you need the PREPARE statement.
Thanks, but in PostgreSQL or ECPG manual isn't this... and I forgot
syntax from Oracle...Could you put some example (the best is the contruction
below)?
if (cond)
exec sql declare cur cursor for select count (*) from tpm;
else
exec sql declare cur cursor for select count (*) from tpm where col1 =
:cislo1;
exec sql open cur;
exec sql whenever not found break;
while (1)
{
exec sql fetch in cur into :cislo2;
}
Thanks...
-------------------------------------------------------------------------
Pavel Janousek (PaJaSoft) FoNet, spol. s r. o.
Vyvoj software, sprava siti, Unix, Web, Y2K Anenska 11, 602 00 Brno
E-mail: mailto:Janousek@FoNet.Cz Tel.: +420 5 4324 4749
SMS: mailto:P.Janousek@SMS.Paegas.Cz Fax.: +420 5 4324 4751
WWW: http://WWW.FoNet.Cz/ E-mail: mailto:Info@FoNet.Cz
--------------------------------------------------------------------------
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [INTERFACES] ecpg cursors and scope
@ 1999-04-24 15:28 Michael Meskes <meskes@postgresql.org>
parent: Pavel PaJaSoft Janousek <janousek@fonet.cz>
0 siblings, 0 replies; 8+ messages in thread
From: Michael Meskes @ 1999-04-24 15:28 UTC (permalink / raw)
To: Pavel PaJaSoft Janousek <janousek@fonet.cz>; +Cc: pgsql-interfaces
On Fri, Apr 23, 1999 at 10:17:03AM +0200, Pavel PaJaSoft Janousek wrote:
> Thanks, but in PostgreSQL or ECPG manual isn't this... and I forgot
Shame on me. :-( Yes, the docs need much more work.
> syntax from Oracle...Could you put some example (the best is the contruction
> below)?
Please check the test source under .../ecpg/test.
How about this
if (cond)
strcpy(query, "select count (*) from tpm");
else
strcpy(query, "select count (*) from tpm where col1 = ?");
exec sql prepare MM from :query;
exec sql declare prep cursor for MM;
exec sql open prep using :cislo1;
exec sql whenever not found break;
while (1)
{
exec sql fetch in cur into :cislo2;
}
But speaking of this. It appears ecpg cannot do prepares without variables
at the moment. This is a bug. I just didn't see this so far.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net | Use PostgreSQL!
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~1999-04-24 15:28 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-04-21 01:46 ecpg cursors and scope Dave Broudy <shaggy@broudy.net>
1999-04-21 11:49 ` Michael Meskes <meskes@postgresql.org>
1999-04-21 10:36 Re: [INTERFACES] ecpg cursors and scope Pavel PaJaSoft Janousek <janousek@fonet.cz>
1999-04-22 15:50 ` Michael Meskes <meskes@postgresql.org>
1999-04-22 16:16 ` Margarita Barvinok <brita@math.lsa.umich.edu>
1999-04-23 04:16 ` Michael Meskes <meskes@postgresql.org>
1999-04-23 08:17 Re: [INTERFACES] ecpg cursors and scope Pavel PaJaSoft Janousek <janousek@fonet.cz>
1999-04-24 15:28 ` Michael Meskes <meskes@postgresql.org>
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