Subject | Re: [ib-support] Stored Proc Question |
---|---|
Author | Carl van Tast |
Post date | 2001-10-04T08:02:48Z |
On Wed, 3 Oct 2001 21:55:17 +0000 (UTC), helebor@...
(Helen Borrie) wrote:
SQL> SHOW VERSION;
ISQL Version: WI-V6.0.0.627
InterBase/x86/Windows NT (access method), version "WI-V6.0.0.627"
InterBase/x86/Windows NT (remote server), version "WI-V6.0.0.627/tcp
(server)/P10"
InterBase/x86/Windows NT (remote interface), version
"WI-V6.0.0.627/tcp (client)/P10"
on disk structure version 10.0
SQL> CREATE TABLE t (i INTEGER);
SQL> INSERT INTO t VALUES (1);
SQL>
SQL> SET TERM | ;
SQL> CREATE PROCEDURE p (o INTEGER)
CON> AS
CON> DECLARE VARIABLE n INTEGER;
CON> DECLARE VARIABLE v INTEGER;
CON> BEGIN
CON> n = o + 1;
CON> n = :n + 1;
CON> FOR SELECT i FROM t INTO :v
CON> DO BEGIN
CON> IF (:v = :o) THEN BEGIN
CON> UPDATE t SET i = :n WHERE i = :v;
CON> END
CON> END
CON> END |
SQL> SET TERM ; |
SQL>
SQL> SELECT * FROM t;
I
============
1
SQL> EXECUTE PROCEDURE p (1);
SQL> SELECT * FROM t;
I
============
3
of an assignment, typically the variable name on the left side of an
assignment. If you write a variable name into an expression just to
use its value, it's an rvalue.
In a comparison we have rvalues both to the left and to the right of
the operator.
AFAICS isql behaves in this way:
If used as an lvalue, a variable name MUST NOT be preceded by a colon.
If used as an rvalue, a variable name MUST be preceded by a colon in
SELECT, INSERT, UPDATE, and DELETE statements, and CAN be preceded by
a colon otherwise.
Personally I'd like to see a colon ACCEPTED before each occurrence of
a variable name. (I'd even like to see it REQUIRED, but I have no
existing code to maintain :-)
something works with isql and does not work with another frontend, it
has to be considered as a frontend bug.
Carl van Tast
(Helen Borrie) wrote:
> [...]But it works for me. See below.
>When the variable on the left side of an assignment or comparison operation, omit the colon; otherwise include it.
>
>So, by rule, the predicate
> IF (vrate = :oldpay1) THEN...
>
>should work, and
>
> IF (:vrate = :oldpay1
>
>won't work.
>Yes, it does not work
>And this is correct:
>SELECT.....INTO :vrate
>
>This is not correct:
> :vrate = :vrate + 1
>works
>This won't work either:
>
> vrate = vrate + 1
>works
>It should be
> vrate = :vrate + 1
SQL> SHOW VERSION;
ISQL Version: WI-V6.0.0.627
InterBase/x86/Windows NT (access method), version "WI-V6.0.0.627"
InterBase/x86/Windows NT (remote server), version "WI-V6.0.0.627/tcp
(server)/P10"
InterBase/x86/Windows NT (remote interface), version
"WI-V6.0.0.627/tcp (client)/P10"
on disk structure version 10.0
SQL> CREATE TABLE t (i INTEGER);
SQL> INSERT INTO t VALUES (1);
SQL>
SQL> SET TERM | ;
SQL> CREATE PROCEDURE p (o INTEGER)
CON> AS
CON> DECLARE VARIABLE n INTEGER;
CON> DECLARE VARIABLE v INTEGER;
CON> BEGIN
CON> n = o + 1;
CON> n = :n + 1;
CON> FOR SELECT i FROM t INTO :v
CON> DO BEGIN
CON> IF (:v = :o) THEN BEGIN
CON> UPDATE t SET i = :n WHERE i = :v;
CON> END
CON> END
CON> END |
SQL> SET TERM ; |
SQL>
SQL> SELECT * FROM t;
I
============
1
SQL> EXECUTE PROCEDURE p (1);
SQL> SELECT * FROM t;
I
============
3
>In C books they talk about lvalues and rvalues. An lvalue is a target
>I don't know whether this less-than-helpful piece of documentation resulted from a failed attempt by the programmers to make things work in a more obvious way, or what, but if you follow what the current documentation says, you are going to get errors. The usual one from omitting the colon is "Column VRATE not found" (or something of that ilk).
of an assignment, typically the variable name on the left side of an
assignment. If you write a variable name into an expression just to
use its value, it's an rvalue.
In a comparison we have rvalues both to the left and to the right of
the operator.
AFAICS isql behaves in this way:
If used as an lvalue, a variable name MUST NOT be preceded by a colon.
If used as an rvalue, a variable name MUST be preceded by a colon in
SELECT, INSERT, UPDATE, and DELETE statements, and CAN be preceded by
a colon otherwise.
Personally I'd like to see a colon ACCEPTED before each occurrence of
a variable name. (I'd even like to see it REQUIRED, but I have no
existing code to maintain :-)
>The question is, should it be treated as a code bug or a documentation bug?I think it was Claudio who said isql is the ultimate reference. If
something works with isql and does not work with another frontend, it
has to be considered as a frontend bug.
>Kind regards
>Helen
Carl van Tast