SDAC optimization issue (ISNULL)

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
GC

SDAC optimization issue (ISNULL)

Post by GC » Mon 15 Nov 2004 09:10

Although this is not a bug it might cause some problems.

The following constuction won't work well in SDAC if you pass NULL to the parameter "param" (whicxh is varchar(xx)):

isnull(:Param,'Something') = 'Something'

if you pass NULL to param SDAC will optimize the SQL and pass it to SQL server as varchar(1) and ISNULL(Varchar(1),'Something') will return VARCHAR(1) which in this case will be 'S'. 'S' = 'Something' will then result to false.
The solution is to simply CAST :Param to VARCHAR(xx) where xx is your desired length and this will solve the problem.

This is not a bug report, just thought that it would be helpful.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Re: SDAC optimization issue (ISNULL)

Post by Ikar » Mon 15 Nov 2004 16:09

We need to consider properly all possible side effects from this optimization. Probably, we'll do it later.

Guest

Post by Guest » Tue 16 Nov 2004 12:46

You can also try to set null value to a parameter of type GUID (uniqueidentifier)... sometimes you can get the statement generated with varchar(1) parameter which doesn't work. :)

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 17 Nov 2004 09:12

We couldn't reproduce the problem.
Please send us complete small sample to demonstrate it and include script to create server objects.

Please supply us following information
  • Exact version of Delphi or C++ Builder
  • Exact version of SDAC. You can see it in About sheet of TMSConnection Editor
  • Exact version of Microsoft SQL Server and OLE DB provider that you use. You can see it in Info sheet of TMSConnection Editor
You can also try to set null value to a parameter of type GUID (uniqueidentifier)... sometimes you can get the statement generated with varchar(1) parameter which doesn't work.

zedmartins
Posts: 18
Joined: Wed 11 Jul 2007 20:59
Location: Brazil

ISNULL and parameters

Post by zedmartins » Thu 24 Apr 2008 14:14

About this problem with statements like:

ISNULL(:PARAM,'something')

Is there anything I can do besides rewriting my SQL to add a CONVERT function?

Thanks,

Z

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 29 Apr 2008 10:42

Another way is to change parameter type from ptInput to ptInputOutput, but this way may affect performance of your application. Therefore we recommend using the CONVERT function.

zedmartins
Posts: 18
Joined: Wed 11 Jul 2007 20:59
Location: Brazil

Post by zedmartins » Tue 29 Apr 2008 14:22

Thanks,

I found out that changing the Options,AutoPrepare to True makes the error go away,

Regards,

Zed

Post Reply