Sybase9: Problems with return value of stored procedure -
01-19-2004
, 10:20 AM
I have some problems with returning values from stored procedures.
The stored procedure is as follows:
Name: pn_ReservationLockChild
BEGIN
DECLARE @isLocked INT
SET @isLocked = 0
SELECT @isLocked =
pn_ReservationCheckObjectLock(@Id_,@objectType_,ob jectKey_)
IF @isLocked = 0
BEGIN
INSERT INTO Reservation
(Id,ObjectType,ObjectKey,TopObjectType,TopObjectKe y)
VALUES
(@Id_,@objectType_,@objectKey_,
@topObjectType_,@topObjectKey_)
COMMIT
END
RETURN @isLocked
END
As it is seen, it calls another sp, which either returns 0 or 1. If
this other sp returns 0, a row is inserted in a table and the value 0
is retured by the main sp. If the value is 1, the main sp should not
insert a row and return 1
The problem is that
IF @isLocked = 0
is always evaluated as true, causing the insertion of a row each time
the sp is executed. This causes a primary-key error. The contents of
the other sp (pn_ReservationcheckObjectLock) is
AS
BEGIN
DECLARE @isLocked INT
SELECT
@isLocked = count(Id)
FROM
Reservation
WHERE
Id = @Id_ AND ObjectType = @objectType_ AND ObjectKey =
@objectKey_
RETURN @isLocked
END
Can you help me figure out what is wrong?
If I via ISql runs the code,
SELECT pn_ReservationLockChild(1,2,80002,1,10001) /* insert non-locked
obj */
SELECT pn_ReservationCheckObjectLock(1,2,80002) /* check object is now
locked */
SELECT pn_ReservationLockChild(1,2,80002,1,10001) */ insert obj again
*/
It returns the values 0 (as expected, 0 = success), 1 (as expected, 1
= "is locked") og ERROR at the last line (which is not expected). I am
kind of in the blank with a solution here, so I would be grateful for
a bit of help.
Thanks,
--
Jesper Stocholm
http://stocholm.dk |