Board index » delphi » NULL values in stored procedure params

NULL values in stored procedure params

Is there any way to asign a NULL value to a stored procedure param such as :

myproc.parambyname('myparam').value := nullVariable;

(where nullVariable = NULL)

without having to know the parameter data type ahead of time?  Actually, the
asignment is fine since the param value is a variant it just crashes when
executed.

 

Re:NULL values in stored procedure params


Quote
"Phil Griffith" <pgri...@prodigy.net> wrote:
>Is there any way to asign a NULL value to a stored procedure param such as :

>myproc.parambyname('myparam').value := nullVariable;

>(where nullVariable = NULL)

>without having to know the parameter data type ahead of time?  Actually, the
>asignment is fine since the param value is a variant it just crashes when
>executed.

Phil,

Sure. Just say:

myproc.parambyname('myparam').value := null;

Unlike other data types, the variant can use the value null in your
Delphi code. This is also useful for testing for nulls on data
retrieved from the database (if ..... value = null then etc.).

Phil Cain
--

Re:NULL values in stored procedure params


Use myproc.parambyname('myparam').Clear

Quote
Phil Griffith wrote in message <7ve2bh$c...@forums.borland.com>...
>Is there any way to asign a NULL value to a stored procedure param such as
:

>myproc.parambyname('myparam').value := nullVariable;

>(where nullVariable = NULL)

>without having to know the parameter data type ahead of time?  Actually,
the
>asignment is fine since the param value is a variant it just crashes when
>executed.

Re:NULL values in stored procedure params


Thanks alot Phil (good name by the way) .
I realize that variants and, hence, params can have a null value but when
the stored procedure is called with a null in any parameter value I always
get a "parameter type unknown" error for that parameter.

Re:NULL values in stored procedure params


Quote
"Phil Griffith" <pgri...@prodigy.net> wrote:
>Thanks alot Phil (good name by the way) .
>I realize that variants and, hence, params can have a null value but when
>the stored procedure is called with a null in any parameter value I always
>get a "parameter type unknown" error for that parameter.

I've seen that happen in InterBase. The other day I tried to use Null
as a literal in a select clause (select, name, null.... from
tablename) and I got that error. I resolved it when I did a typecast:
        Select name, cast(null as integer)..... from tablename.

The problem apparently is that, like any type, the db engine has to
know the type as well as the value. I suspect that you're getting the
error when you try to run the proc and not when you are assigning the
null value. If that's the case then I think you're stuck with the
typecast, unless you can use some of the properties and methods of
TParam, (e.g. ParamByName.AsInteger := null).

I would think that you might have some other problems in the stored
procedure as well, depending on how it's written. A param used as a
constraint also has some syntax problems. I suppose you know that you
can't say Where columnname = null but must say Where columnname is
null. (if the db engine is SQL standard).

If none of this helps, why not tell us more about the problem and
let's see if we can figure out a solution.

Phil Cain

--

Re:NULL values in stored procedure params


use myproc.parambyname('myparam').clear to assign null values

Quote
Phil Griffith <pgri...@prodigy.net> wrote in message

news:7ve2bh$cit7@forums.borland.com...
Quote
> Is there any way to asign a NULL value to a stored procedure param such as
:

> myproc.parambyname('myparam').value := nullVariable;

> (where nullVariable = NULL)

> without having to know the parameter data type ahead of time?  Actually,
the
> asignment is fine since the param value is a variant it just crashes when
> executed.

Re:NULL values in stored procedure params


Thanks Philip, I believe you are correct.  The error is definitely occuring
when execution takes place not on assignment.  The type cast will probably
work but I am trying to write as generic code as possible without having
worry about each parameters type.  It could be that this just isn't
possible.  I have 10 or 15 parameters to pass and its a lot easier to write
in a loop than specefying each field.  Being generic also provides a much
greater degree of portability.

Thanks alot for your help.
Phil

Re:NULL values in stored procedure params


try

myproc.parambyname('myparam').DataType := ftString;
myproc.parambyname('myparam').Clear;

On Sat, 30 Oct 1999 02:18:06 -0400, "Phil Griffith"

Quote
<pgri...@prodigy.net> wrote:
>Is there any way to asign a NULL value to a stored procedure param such as :

>myproc.parambyname('myparam').value := nullVariable;

>(where nullVariable = NULL)

>without having to know the parameter data type ahead of time?  Actually, the
>asignment is fine since the param value is a variant it just crashes when
>executed.

Other Threads