473,545 Members | 2,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BUG DB2 V8 FP12 Stored Proc Parameters - NULL value is case sensitive

I think I have discovered a bug in the handling of null values (vs NULL
values) passed as parameters to a stored proc.

I have always believed that the database handled NULL and null the
same. The following statement returns the expected results:

select case when NULL is null then 'SAME' else 'DIFFERENT' end from
sysibm.sysdummy 1;

returns SAME.

BUT, If you call a proc with lower case null as a parameter, it will
not be treated as a NULL.

Here's an example proc:

CREATE PROCEDURE RG.NULLTEST(IN PARM1 VARCHAR(26))
SPECIFIC NULLTEST
MODIFIES SQL DATA
NOT DETERMINISTIC
NULL CALL
LANGUAGE SQL

P1: BEGIN

DECLARE c1 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

DECLARE c2 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NOT NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

if PARM1 IS null THEN

OPEN c1;

ELSE

OPEN c2;

END IF;

END P1
;
CALL RG.NULLTEST(nul l);

returns PARM1 IS NOT NULL

BUT

CALL RG.NULLTEST(NUL L);

PARM1 IS NULL

It's easy enough to code around, but frustrating when the database
violates a basic assumption.

Has anyone else encountered this issue?

Bob

Aug 21 '06 #1
10 4253
sy*****@gmail.c om wrote:
I think I have discovered a bug in the handling of null values (vs NULL
values) passed as parameters to a stored proc.

I have always believed that the database handled NULL and null the
same. The following statement returns the expected results:

select case when NULL is null then 'SAME' else 'DIFFERENT' end from
sysibm.sysdummy 1;

returns SAME.

BUT, If you call a proc with lower case null as a parameter, it will
not be treated as a NULL.

Here's an example proc:

CREATE PROCEDURE RG.NULLTEST(IN PARM1 VARCHAR(26))
SPECIFIC NULLTEST
MODIFIES SQL DATA
NOT DETERMINISTIC
NULL CALL
LANGUAGE SQL

P1: BEGIN

DECLARE c1 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

DECLARE c2 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NOT NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

if PARM1 IS null THEN

OPEN c1;

ELSE

OPEN c2;

END IF;

END P1
;
CALL RG.NULLTEST(nul l);

returns PARM1 IS NOT NULL

BUT

CALL RG.NULLTEST(NUL L);

PARM1 IS NULL

It's easy enough to code around, but frustrating when the database
violates a basic assumption.

Has anyone else encountered this issue?
I cannot reproduce this on DB2 9 GA.
Nonetheleless if your observation turns out to be confirmed it would be
a bug in the CLP, not the engine.
CLP does some amount of shallow parsing of the CALL statement to replace
literals with ? for IN/OUT arguments. Also in the very early days of
DB2 V7(!) CLP accepted strings without quotes. Here the NULL vs null
('null') would make sense.
Could it be you are on an old DB2 V7 client?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 21 '06 #2
I tested through both ODBC and CLP and here's what I found:

When I tested through RapidSQL using the IBM DB2 ODBC Driver
8.01.12.99, the proc returned incorrectly.

R1
PARM1 IS NOT NULL

I tried through the Command Line Processor and the proc returned
correctly.

(c) Copyright IBM Corporation 1993,2002
Command Line Processor for DB2 SDK 8.2.5

db2 =call rg.NULLTEST(nul l)
Result set 1
--------------

R1
-------------
PARM1 IS NULL

1 record(s) selected.

Return Status = 0

so it appears the problem may be with the ODBC driver.

-Bob

Serge Rielau wrote:
sy*****@gmail.c om wrote:
I think I have discovered a bug in the handling of null values (vs NULL
values) passed as parameters to a stored proc.

I have always believed that the database handled NULL and null the
same. The following statement returns the expected results:

select case when NULL is null then 'SAME' else 'DIFFERENT' end from
sysibm.sysdummy 1;

returns SAME.

BUT, If you call a proc with lower case null as a parameter, it will
not be treated as a NULL.

Here's an example proc:

CREATE PROCEDURE RG.NULLTEST(IN PARM1 VARCHAR(26))
SPECIFIC NULLTEST
MODIFIES SQL DATA
NOT DETERMINISTIC
NULL CALL
LANGUAGE SQL

P1: BEGIN

DECLARE c1 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

DECLARE c2 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NOT NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

if PARM1 IS null THEN

OPEN c1;

ELSE

OPEN c2;

END IF;

END P1
;
CALL RG.NULLTEST(nul l);

returns PARM1 IS NOT NULL

BUT

CALL RG.NULLTEST(NUL L);

PARM1 IS NULL

It's easy enough to code around, but frustrating when the database
violates a basic assumption.

Has anyone else encountered this issue?
I cannot reproduce this on DB2 9 GA.
Nonetheleless if your observation turns out to be confirmed it would be
a bug in the CLP, not the engine.
CLP does some amount of shallow parsing of the CALL statement to replace
literals with ? for IN/OUT arguments. Also in the very early days of
DB2 V7(!) CLP accepted strings without quotes. Here the NULL vs null
('null') would make sense.
Could it be you are on an old DB2 V7 client?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 22 '06 #3
OK, that starts to make sense. Can you open a PMR?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 22 '06 #4
Will do. Thanks.

Serge Rielau wrote:
OK, that starts to make sense. Can you open a PMR?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 22 '06 #5
sy*****@gmail.c om wrote:
Will do. Thanks.
Thanks, I asked backstage and they tried to repro. Without success.
So we are looking forward to your PMR to get to the bottom of this.

Cheers
Serge

Result:
sqlprepare 1 "call RG.NULLTEST(nul l)" -3
SQLPrepare: rc = 0 (SQL_SUCCESS)
sqlexecute 1
SQLExecute: rc = 0 (SQL_SUCCESS)
fetchall 1
FetchAll: Columns: 1
R1
PARM1 IS NULL
FetchAll: 1 rows fetched.
sqlfreestmt 1 SQL_CLOSE
SQLFreeStmt: rc = 0 (SQL_SUCCESS)
>
sqlprepare 1 "call RG.NULLTEST(NUL L)" -3
SQLPrepare: rc = 0 (SQL_SUCCESS)
sqlexecute 1
SQLExecute: rc = 0 (SQL_SUCCESS)
fetchall 1
FetchAll: Columns: 1
R1
PARM1 IS NULL
FetchAll: 1 rows fetched.
sqlfreestmt 1 SQL_CLOSE
SQLFreeStmt: rc = 0 (SQL_SUCCESS)
>
sqlprepare 1 "call RG.NULLTEST('nu ll')" -3
SQLPrepare: rc = 0 (SQL_SUCCESS)
sqlexecute 1
SQLExecute: rc = 0 (SQL_SUCCESS)
fetchall 1
FetchAll: Columns: 1
R1
PARM1 IS not NULL
FetchAll: 1 rows fetched.
sqlfreestmt 1 SQL_CLOSE
SQLFreeStmt: rc = 0 (SQL_SUCCESS)
>
sqlprepare 1 "call RG.NULLTEST('NU LL')" -3
SQLPrepare: rc = 0 (SQL_SUCCESS)
sqlexecute 1
SQLExecute: rc = 0 (SQL_SUCCESS)
fetchall 1
FetchAll: Columns: 1
R1
PARM1 IS not NULL
FetchAll: 1 rows fetched.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 22 '06 #6
sy*****@gmail.c om wrote:
Will do. Thanks.
Let me know when you open PMR (PMR number will be handy ...)

Jan M. Nelken
Aug 22 '06 #7
sy*****@gmail.c om wrote:
I think I have discovered a bug in the handling of null values (vs NULL
values) passed as parameters to a stored proc.

I have always believed that the database handled NULL and null the
same. The following statement returns the expected results:

select case when NULL is null then 'SAME' else 'DIFFERENT' end from
sysibm.sysdummy 1;

returns SAME.

BUT, If you call a proc with lower case null as a parameter, it will
not be treated as a NULL.

Here's an example proc:

CREATE PROCEDURE RG.NULLTEST(IN PARM1 VARCHAR(26))
SPECIFIC NULLTEST
MODIFIES SQL DATA
NOT DETERMINISTIC
NULL CALL
LANGUAGE SQL

P1: BEGIN

DECLARE c1 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

DECLARE c2 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NOT NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

if PARM1 IS null THEN

OPEN c1;

ELSE

OPEN c2;

END IF;

END P1
;
CALL RG.NULLTEST(nul l);

returns PARM1 IS NOT NULL

BUT

CALL RG.NULLTEST(NUL L);

PARM1 IS NULL

It's easy enough to code around, but frustrating when the database
violates a basic assumption.

Has anyone else encountered this issue?

Bob
Works properly for me, on Solaris (UDB 8.1.6).

Two points.

1) Is the version of the client and the server the same? (We had issues
here with the server crashing, when they were not.)

2) Have you tried casting the NULL as a VARCHAR to match the IN
parameter?

B.

Aug 23 '06 #8
Brian,

The server and the client are both at V8 FP 12. I'm running the Admin
Client on my workstation.

Here's the results of casting the null to a varchar(26) using RapidSQL
7.4 over ODBC:

call rg.nulltest(cas t(null as varchar(26)))
R1
PARM1 IS NOT NULL

call rg.nulltest(cas t(NULL as varchar(26)))

R1
PARM1 IS NOT NULL

The error seems to be ODBC related. Whenever we have used the DB2
Command Line Processor, the results return correctly.

FYI - I've submitted the case to our DBA team who will be creating the
PMR and will update the thread with the number when it gets created.

Thanks,

Bob

Brian Tkatch wrote:
sy*****@gmail.c om wrote:
I think I have discovered a bug in the handling of null values (vs NULL
values) passed as parameters to a stored proc.

I have always believed that the database handled NULL and null the
same. The following statement returns the expected results:

select case when NULL is null then 'SAME' else 'DIFFERENT' end from
sysibm.sysdummy 1;

returns SAME.

BUT, If you call a proc with lower case null as a parameter, it will
not be treated as a NULL.

Here's an example proc:

CREATE PROCEDURE RG.NULLTEST(IN PARM1 VARCHAR(26))
SPECIFIC NULLTEST
MODIFIES SQL DATA
NOT DETERMINISTIC
NULL CALL
LANGUAGE SQL

P1: BEGIN

DECLARE c1 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

DECLARE c2 CURSOR WITH RETURN TO CALLER FOR
SELECT 'PARM1 IS NOT NULL' AS R1 FROM SYSIBM.SYSDUMMY 1;

if PARM1 IS null THEN

OPEN c1;

ELSE

OPEN c2;

END IF;

END P1
;
CALL RG.NULLTEST(nul l);

returns PARM1 IS NOT NULL

BUT

CALL RG.NULLTEST(NUL L);

PARM1 IS NULL

It's easy enough to code around, but frustrating when the database
violates a basic assumption.

Has anyone else encountered this issue?

Bob

Works properly for me, on Solaris (UDB 8.1.6).

Two points.

1) Is the version of the client and the server the same? (We had issues
here with the server crashing, when they were not.)

2) Have you tried casting the NULL as a VARCHAR to match the IN
parameter?

B.
Aug 28 '06 #9
Here's the PMR:

PMR27545

Thanks All.

Jan M. Nelken wrote:
sy*****@gmail.c om wrote:
Will do. Thanks.

Let me know when you open PMR (PMR number will be handy ...)

Jan M. Nelken
Aug 28 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2155
by: Sean | last post by:
Hi all, In VB.NET you can use default parameters to stored procedures using the Nothing keyword, as described in: http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q321902 I used to use the default keyword in old ASP. How do I do this in C#?
2
1012
by: Benoist LUGNIER | last post by:
Hello VB .NET - ADO .NET - SQL Server (MSDE) I want to retrieve the parameters of a stored procedure before execute it. I've already try the fillschema but it return the "return object (table)" and not the stored proc. Thanks Benoist
4
5990
by: Andrew Baker | last post by:
I have the following code that calles a stored proc in SQLServer. When the output parameter @custref is null (System.DBNull) I cant seem to find a test for this and I get an exception. I know I could coalesce the stored proc, but I would like to know if the value is null. How do you test for null in the returned parameter of a stored...
1
1744
by: lnd | last post by:
Is there any bad side effect in recompiling PG with increased stored procedures maximum parameters count, for example, to 128? Thank you in advance, Laimis ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives?
4
9149
by: xAvailx | last post by:
Hello: I didn't find any documentation that notes save point names are case sensitive, but I guess they are... Stored Proc to reproduce: /* START CODE SNIPPET */ If Exists (Select * From sysobjects Where Type = 'P' and Name =
6
2152
by: Paul M | last post by:
Hi All, I'm currently writing a z/OS DB2 Stored Proc in C, using an example from the IBM Stored Procedure guide (SG24-7083-00). The database calls to read and update the database work fine...however, I can't seem to figure out how to pass parms to the C Program. The compile, bind, and run using DB2BATCH all work fine, however, when I...
3
1513
by: Byron | last post by:
I'm trying to iterate stored parameters and populate any public properties of an object with the parameter value. I've suceeded in doing it the other way around, but when I try it to the object I keep getting the error "Object does not match target type". I've tried field.SetValue(p, p.Value, BindingFlags.SetField, null, null, null) and a...
10
1349
by: dlesandrini | last post by:
Ok, I know I've done this, but it doesn't seem to work for me anymore. I have a form based on a stored proc, usp_PubsAuthors and it has a single parameter, @FilterState varchar(2) which defaults to CA. I put a combo box on the form with a list of states, and named it to the param, FilterState. Isn't this supposed to ... auto-negotiate,...
3
4989
by: bogdan | last post by:
Hi, I have a stored procedure that returns a single value. Example: SELECT @RowCount = COUNT(*) FROM t WHERE RETURN @RowCount I created a data set, table adapter, and adapter's method configured for the stored proc and as returning a single value. The wizard created an adapter method that calls SqlCommand.ExecuteScalar(). The...
0
7428
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7941
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6014
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5354
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3485
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.