Subject | select in procedure returns wrong result |
---|---|
Author | Sergey Ganev |
Post date | 2003-09-18T19:26:17Z |
Hello, All!
Sorry for the long example/question, I just coudn't make it
shorter :)
Let's have a table T1 with one field, DATELP : DATE;
and fill it with two values, '1.5.2002' and '1.6.2002',
for example.
Let's make procedure P1, with
DATEINPUT : DATE as input parameter, and
DATEOUTPUT : DATE as output parameter, and body:
BEGIN
SELECT FIRST 1 DATELP FROM T1
WHERE (DATELP > :DATEINPUT)
ORDER BY DATELP
INTO :DATEOUTPUT;
SUSPEND;
END
If we execute procedure with DATEINPUT = '1.1.2004',
output result is NULL, as expected, because there isn't
a date bigger than '1.1.2004' in the table.
So, let's change the procedure, just add one statement
into body:
BEGIN
DATEOUTPUT = '1.1.2000'; /* <-- */
SELECT FIRST 1 DATELP FROM T1
WHERE (DATELP > :DATEINPUT)
ORDER BY DATELP
INTO :DATEOUTPUT;
SUSPEND;
END
Now, if we execute the procedure with the same input value,
it returns '1.1.2000' instead NULL.
It seems, that select (or INTO clause) do not force
value into parameter (dateoutput), if the value is null.
And, 3-rd example:
Procedure P3, with the same i/o parameters, as above,
and with body:
BEGIN
DATEOUTPUT = '1.1.2000';
SELECT DATEOUTPUT FROM P1 ( :DATEINPUT )
INTO :DATEOUTPUT;
SUSPEND;
END
If we "hide" select into procedure (P1), returned value
is again NULL, as it has to be.
Server is Win 32 Firebird 1.5 RC4, and the same result is in RC6.
OS- windows XP
Examples are made using IBExpert.
So, am I missing something or the problem is
with firebird?
--
Sergey Ganev
Sorry for the long example/question, I just coudn't make it
shorter :)
Let's have a table T1 with one field, DATELP : DATE;
and fill it with two values, '1.5.2002' and '1.6.2002',
for example.
Let's make procedure P1, with
DATEINPUT : DATE as input parameter, and
DATEOUTPUT : DATE as output parameter, and body:
BEGIN
SELECT FIRST 1 DATELP FROM T1
WHERE (DATELP > :DATEINPUT)
ORDER BY DATELP
INTO :DATEOUTPUT;
SUSPEND;
END
If we execute procedure with DATEINPUT = '1.1.2004',
output result is NULL, as expected, because there isn't
a date bigger than '1.1.2004' in the table.
So, let's change the procedure, just add one statement
into body:
BEGIN
DATEOUTPUT = '1.1.2000'; /* <-- */
SELECT FIRST 1 DATELP FROM T1
WHERE (DATELP > :DATEINPUT)
ORDER BY DATELP
INTO :DATEOUTPUT;
SUSPEND;
END
Now, if we execute the procedure with the same input value,
it returns '1.1.2000' instead NULL.
It seems, that select (or INTO clause) do not force
value into parameter (dateoutput), if the value is null.
And, 3-rd example:
Procedure P3, with the same i/o parameters, as above,
and with body:
BEGIN
DATEOUTPUT = '1.1.2000';
SELECT DATEOUTPUT FROM P1 ( :DATEINPUT )
INTO :DATEOUTPUT;
SUSPEND;
END
If we "hide" select into procedure (P1), returned value
is again NULL, as it has to be.
Server is Win 32 Firebird 1.5 RC4, and the same result is in RC6.
OS- windows XP
Examples are made using IBExpert.
So, am I missing something or the problem is
with firebird?
--
Sergey Ganev