Re: DECLARE doesn't set/reset sqlca after DECLARE cursor

Lists: pgsql-hackers
From: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
To: Michael Meskes <michael(at)fam-meskes(dot)de>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Hans-Juergen Schoenig <hs(at)cybertec(dot)at>
Subject: DECLARE doesn't set/reset sqlca after DECLARE cursor
Date: 2009-08-12 17:13:44
Message-ID: 4A82F848.3010901@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

a customer of us complained a behavioural difference
between ESQL/C and ECPG. They check sqlca.sqlcode
almost everywhere in their application currently under
porting to PostgreSQL. Somewhere in their code
however there was a place where a statement error
was ignored and the error was reported when the code
reached the next DECLARE statement.

It seems that this pseudo-statement is the only one that
doesn't set/reset sqlca, I was thinking about adding that
in a way that a call to ecpg_init() gets emitted.

The attached patch implements this. The only downside
is that now DECLARE CURSOR cannot appear outside
of a function, a change in test/preproc/variable.pgc reflects
this fact. The largest part of the patch is the change in the
expected C source outcome of the regression tests. The only
test where the ecpg_log output has changed is variable.pgc.

Best regards,
Zoltán Böszörményi

--
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics

----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/

Attachment Content-Type Size
pg85-declare-reset-sqlca-1-ctxdiff.patch text/x-patch 51.9 KB

From: Michael Meskes <meskes(at)postgresql(dot)org>
To: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Hans-Juergen Schoenig <hs(at)cybertec(dot)at>
Subject: Re: DECLARE doesn't set/reset sqlca after DECLARE cursor
Date: 2009-08-13 11:33:19
Message-ID: 20090813113319.GA5505@feivel.credativ.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 12, 2009 at 07:13:44PM +0200, Boszormenyi Zoltan wrote:
> a customer of us complained a behavioural difference
> ...
> The attached patch implements this. The only downside
> is that now DECLARE CURSOR cannot appear outside
> of a function, a change in test/preproc/variable.pgc reflects

DECLARE by definition is a declarative command and as such should be able to
live outside a function.

Michael

--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ: 179140304, AIM/Yahoo/Skype: michaelmeskes, Jabber: meskes(at)jabber(dot)org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!


From: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
To: Boszormenyi Zoltan <zb(at)cybertec(dot)at>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Hans-Juergen Schoenig <hs(at)cybertec(dot)at>
Subject: Re: DECLARE doesn't set/reset sqlca after DECLARE cursor
Date: 2009-08-13 15:55:53
Message-ID: 4A843789.2050202@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Meskes írta:
> On Wed, Aug 12, 2009 at 07:13:44PM +0200, Boszormenyi Zoltan wrote:
>
>> a customer of us complained a behavioural difference
>> ...
>> The attached patch implements this. The only downside
>> is that now DECLARE CURSOR cannot appear outside
>> of a function, a change in test/preproc/variable.pgc reflects
>>
>
> DECLARE by definition is a declarative command and as such should be able to
> live outside a function.
>

Okay, so it's a declarative command. But if we're in a function,
we should still emit a call to ecpg_init, to be able to follow
the Informix behaviour. We can limit it it compat mode, though.
The attached patch does this, and detects being inside of a function
by braces_open > 0. Short of rewriting ECPG into a flull-fledged
C/C++ preprocessor, we can't do better currently.

In compat mode, you cannot do
DECLARE mycur CURSOR FOR SELECT ... INTO :var, ...
or
DECLARE mycur CURSOR FOR SELECT ... WHERE field = ?
in the global scope because adjust_informix() emits function calls
outside of a function. Or is this declaration illegal?
At least it should be documented in PostgreSQL.

Best regards,
Zoltán Böszörményi

--
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics

----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/

Attachment Content-Type Size
pg85-declare-reset-sqlca-2-ctxdiff.patch text/x-patch 8.4 KB

From: Michael Meskes <meskes(at)postgresql(dot)org>
To: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Hans-Juergen Schoenig <hs(at)cybertec(dot)at>
Subject: Re: DECLARE doesn't set/reset sqlca after DECLARE cursor
Date: 2009-08-14 07:59:03
Message-ID: 20090814075903.GB21414@feivel.credativ.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Aug 13, 2009 at 05:55:53PM +0200, Boszormenyi Zoltan wrote:
> Okay, so it's a declarative command. But if we're in a function,
> we should still emit a call to ecpg_init, to be able to follow

No, either it is declarative or it is not, but I don't see a reason for
different behaviour depending on where the command is located.

> the Informix behaviour. We can limit it it compat mode, though.

So let's first figure out exactly how Informix handles things. Zoltan, do you
have access to esql the Informix precompiler? If so, please run two simple
tests, one with just a DECLARE statement and one with a DECLARE statement in a
function and post the results please.

Michael
--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ: 179140304, AIM/Yahoo/Skype: michaelmeskes, Jabber: meskes(at)jabber(dot)org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!


From: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
To: Michael Meskes <meskes(at)postgresql(dot)org>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Hans-Juergen Schoenig <hs(at)cybertec(dot)at>
Subject: Re: DECLARE doesn't set/reset sqlca after DECLARE cursor
Date: 2009-08-14 11:02:07
Message-ID: 4A85442F.9060306@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Meskes írta:
> On Thu, Aug 13, 2009 at 05:55:53PM +0200, Boszormenyi Zoltan wrote:
>
>> Okay, so it's a declarative command. But if we're in a function,
>> we should still emit a call to ecpg_init, to be able to follow
>>
>
> No, either it is declarative or it is not, but I don't see a reason for
> different behaviour depending on where the command is located.
>
>
>> the Informix behaviour. We can limit it it compat mode, though.
>>
>
> So let's first figure out exactly how Informix handles things. Zoltan, do you
> have access to esql the Informix precompiler? If so, please run two simple
> tests, one with just a DECLARE statement and one with a DECLARE statement in a
> function and post the results please.
>

Here are the two test files, with their preprocessed C output.
Indeed, Informix emits a function call for DECLARE CURSOR.
And it seems it's not legal to do this outside of a function.

Best regards,
Zoltán Böszörményi

--
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics

----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/

Attachment Content-Type Size
test1.c text/x-csrc 2.8 KB
test1.ec text/plain 420 bytes
test2.c text/x-csrc 2.8 KB
test2.ec text/plain 421 bytes

From: Michael Meskes <meskes(at)postgresql(dot)org>
To: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Hans-Juergen Schoenig <hs(at)cybertec(dot)at>
Subject: Re: DECLARE doesn't set/reset sqlca after DECLARE cursor
Date: 2009-08-14 13:34:45
Message-ID: 20090814133445.GA11667@feivel.credativ.lan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Aug 14, 2009 at 01:02:07PM +0200, Boszormenyi Zoltan wrote:
> Here are the two test files, with their preprocessed C output.
> Indeed, Informix emits a function call for DECLARE CURSOR.
> And it seems it's not legal to do this outside of a function.

Okay, thanks. I changed several things in your patch mainly due to chosing a
slightly different way to reset the sqlca array and committed that change.
Please test.

Michael
--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ: 179140304, AIM/Yahoo/Skype: michaelmeskes, Jabber: meskes(at)jabber(dot)org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!


From: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
To: Michael Meskes <meskes(at)postgresql(dot)org>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Hans-Juergen Schoenig <hs(at)cybertec(dot)at>
Subject: Re: DECLARE doesn't set/reset sqlca after DECLARE cursor
Date: 2009-08-14 19:09:19
Message-ID: 4A85B65F.7080805@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Meskes írta:
> On Fri, Aug 14, 2009 at 01:02:07PM +0200, Boszormenyi Zoltan wrote:
>
>> Here are the two test files, with their preprocessed C output.
>> Indeed, Informix emits a function call for DECLARE CURSOR.
>> And it seems it's not legal to do this outside of a function.
>>
>
> Okay, thanks. I changed several things in your patch mainly due to chosing a
> slightly different way to reset the sqlca array and committed that change.
> Please test.
>

I looked at the committed change, and it works
the same as my version, only the emitted call
is put into the compat library. According to the
regression tests, it works. Thanks. :-)

Best regards,
Zoltán Böszörményi

--
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics

----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/