Subject | Re: Cannot prepare IB_Query with this SQL... |
---|---|
Author | tibotaka |
Post date | 2002-02-20T00:10:43Z |
--- In IBObjects@y..., "Helen Borrie (TeamIBO)" <helebor@d...> wrote:
ACITY_STREET_ID defined as an input. As such, it could be treated as
a variable within your procedure. IMO, its illegal use in the WHERE
clause ought to have prevented the procedure from compiling. If it
DID compile, then I think we are seeing a parser error in the
database.
has NO bearing on the result of the EXISTS() predicate and it has no
business being there.
think comparision NULL = NULL is evaluated to FALSE (or UNKNOWN ? -
in Firebird and Interbase manuals this part is not very clear and in
one chapter the result of this comparision is stated as FALSE, in
other chapter as UNKNOWN...but it doesn't matter, because result of
EXISTS() is the same) so matter of whether the procedure's input
argument has a null value in that sub-clause HAS bearing on the
result of the EXISTS().
"Work fine" in sense that stored procedure returns valid result:
without part "(:ACITY_STREET_ID IS NULL) ..." of WHERE clause I have
to split above statement into two parts with IF...THEN to get the
same result:
CREATE PROCEDURE SPS_CUSTOMER$ADDRESS_EXISTS
(ACITY_CODE VARCHAR(5),
ACITY_STREET_ID INTEGER,
ASTREET_NUMBER VARCHAR(10),
ABUILDING_REG VARCHAR(10))
RETURNS
(ARESULT SMALLINT)
AS
BEGIN
...
IF (ACITY_STREET_ID IS NULL) THEN
BEGIN
IF (EXISTS(SELECT * FROM CUSTOMER
WHERE (CUSTOMER.CITY_CODE = :ACITY_CODE)
AND (CUSTOMER.CITY_STREET_ID IS NULL)
AND (CUSTOMER.STREET_NUMBER_UPPER = :ASTREET_NUMBER)
AND (CUSTOMER.BUILDING_REG_UPPER = :ABUILDING_REG)))
THEN
ARESULT = 1;
ELSE
ARESULT = 0;
END
ELSE
BEGIN
IF (EXISTS(SELECT * FROM CUSTOMER
WHERE (CUSTOMER.CITY_CODE = :ACITY_CODE)
AND (CUSTOMER.CITY_STREET_ID = :ACITY_STREET_ID)
AND (CUSTOMER.STREET_NUMBER_UPPER = :ASTREET_NUMBER)
AND (CUSTOMER.BUILDING_REG_UPPER = :ABUILDING_REG)))
THEN
ARESULT = 1;
ELSE
ARESULT = 0;
END
...
END
This construction is pretty complex compared to original...
Helen Borrie - you and others from TEAM IBO are my "GURUS" of
Interbase and Firebird and IBObjects and I think nobody believes HOW
MUCH I LEARNED ONLY FROM READING OF YOURS POSTINGS IN THIS GROUP - SO
I HAVE TO SAY: THANKS...
Tibor
> >the parser probably allowed it somehow because you had
> >CREATE PROCEDURE SPS_CUSTOMER$ADDRESS_EXISTS
> > (ACITY_CODE VARCHAR(5),
> > ACITY_STREET_ID INTEGER,
> > ASTREET_NUMBER VARCHAR(10),
> > ABUILDING_REG VARCHAR(10))
> >RETURNS
> > (ARESULT SMALLINT)
> >AS
> >BEGIN
> >...
> >IF (EXISTS(SELECT * FROM CUSTOMER
> >WHERE (CUSTOMER.CITY_CODE = :ACITY_CODE)
> > AND (((:ACITY_STREET_ID IS NULL) AND (CUSTOMER.CITY_STREET_ID IS
> >NULL)) OR (CUSTOMER.CITY_STREET_ID = :ACITY_STREET_ID))
> > AND (CUSTOMER.STREET_NUMBER_UPPER = :ASTREET_NUMBER) AND
> >(CUSTOMER.BUILDING_REG_UPPER = :ABUILDING_REG)))
> >THEN
> > ARESULT = 1;
> >ELSE
> > ARESULT = 0;
> >...
> >END
> >
>
> "works fine" in the sense that it doesn't throw an error? In PSQL
ACITY_STREET_ID defined as an input. As such, it could be treated as
a variable within your procedure. IMO, its illegal use in the WHERE
clause ought to have prevented the procedure from compiling. If it
DID compile, then I think we are seeing a parser error in the
database.
>the procedure's input argument has a null value in that sub-clause
> Regardless of what the PSQL parser allowed, the matter of whether
has NO bearing on the result of the EXISTS() predicate and it has no
business being there.
>Either I really don't understand or above claim is not correct - I
think comparision NULL = NULL is evaluated to FALSE (or UNKNOWN ? -
in Firebird and Interbase manuals this part is not very clear and in
one chapter the result of this comparision is stated as FALSE, in
other chapter as UNKNOWN...but it doesn't matter, because result of
EXISTS() is the same) so matter of whether the procedure's input
argument has a null value in that sub-clause HAS bearing on the
result of the EXISTS().
"Work fine" in sense that stored procedure returns valid result:
without part "(:ACITY_STREET_ID IS NULL) ..." of WHERE clause I have
to split above statement into two parts with IF...THEN to get the
same result:
CREATE PROCEDURE SPS_CUSTOMER$ADDRESS_EXISTS
(ACITY_CODE VARCHAR(5),
ACITY_STREET_ID INTEGER,
ASTREET_NUMBER VARCHAR(10),
ABUILDING_REG VARCHAR(10))
RETURNS
(ARESULT SMALLINT)
AS
BEGIN
...
IF (ACITY_STREET_ID IS NULL) THEN
BEGIN
IF (EXISTS(SELECT * FROM CUSTOMER
WHERE (CUSTOMER.CITY_CODE = :ACITY_CODE)
AND (CUSTOMER.CITY_STREET_ID IS NULL)
AND (CUSTOMER.STREET_NUMBER_UPPER = :ASTREET_NUMBER)
AND (CUSTOMER.BUILDING_REG_UPPER = :ABUILDING_REG)))
THEN
ARESULT = 1;
ELSE
ARESULT = 0;
END
ELSE
BEGIN
IF (EXISTS(SELECT * FROM CUSTOMER
WHERE (CUSTOMER.CITY_CODE = :ACITY_CODE)
AND (CUSTOMER.CITY_STREET_ID = :ACITY_STREET_ID)
AND (CUSTOMER.STREET_NUMBER_UPPER = :ASTREET_NUMBER)
AND (CUSTOMER.BUILDING_REG_UPPER = :ABUILDING_REG)))
THEN
ARESULT = 1;
ELSE
ARESULT = 0;
END
...
END
This construction is pretty complex compared to original...
Helen Borrie - you and others from TEAM IBO are my "GURUS" of
Interbase and Firebird and IBObjects and I think nobody believes HOW
MUCH I LEARNED ONLY FROM READING OF YOURS POSTINGS IN THIS GROUP - SO
I HAVE TO SAY: THANKS...
Tibor