Subject | Re: Null in Stored Procedure parameter. |
---|---|
Author | Juha.Metsakallas@Tietotoimi.fi |
Post date | 2001-01-11T16:20:08Z |
Hello
Dale wrote:
parambyname('Object_ID').AsInteger := object_id;
parambyname('Keyword_id').clear;
parambyname('Keyword_Name').AsString := 'Some Name';
parambyname('Keyword_Value').AsString := 'Some Value';
ExecProc;
...
<<
The error is caused by the fact that you are passing three parameters
to
the stored procedure which is expecting to recieve four. If you want
to
set "keyword_ID" to null, you must do that in the stored procedure,
not
within Delphi. Define a parameter value, and use that in the stored
procedure to signal when to write a null:
in Delphi:
const
undefinedID = -1;
...
paramByName('keyword_ID').asInteger:= undefinedID;
in the stored procedure:
ALTER PROCEDURE MyProc(keyword_ID INTEGER)
AS
BEGIN
IF (keyword_ID = -1) THEN keyword_ID = NULL;
...
END
But using null to signal something is conceptually against the
principles of database design. You should use some other value, like
-1, to mean non-existing and like. Also remember that you can't
compare null to anything else than to null. E.g. you create a field
"state" that can take several values: null, 1, 2 and 3. You will run
into trouble if you make a query with "WHERE state <> 1".
Juha
Dale wrote:
>>...
parambyname('Object_ID').AsInteger := object_id;
parambyname('Keyword_id').clear;
parambyname('Keyword_Name').AsString := 'Some Name';
parambyname('Keyword_Value').AsString := 'Some Value';
ExecProc;
...
<<
The error is caused by the fact that you are passing three parameters
to
the stored procedure which is expecting to recieve four. If you want
to
set "keyword_ID" to null, you must do that in the stored procedure,
not
within Delphi. Define a parameter value, and use that in the stored
procedure to signal when to write a null:
in Delphi:
const
undefinedID = -1;
...
paramByName('keyword_ID').asInteger:= undefinedID;
in the stored procedure:
ALTER PROCEDURE MyProc(keyword_ID INTEGER)
AS
BEGIN
IF (keyword_ID = -1) THEN keyword_ID = NULL;
...
END
But using null to signal something is conceptually against the
principles of database design. You should use some other value, like
-1, to mean non-existing and like. Also remember that you can't
compare null to anything else than to null. E.g. you create a field
"state" that can take several values: null, 1, 2 and 3. You will run
into trouble if you make a query with "WHERE state <> 1".
Juha