dbTalk Databases Forums  

Sybase9: Problems with return value of stored procedure

comp.databases.sybase comp.databases.sybase


Discuss Sybase9: Problems with return value of stored procedure in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jesper Stocholm
 
Posts: n/a

Default 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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.