Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return data from =SQLExec()
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00065405
Message ID:
00065932
Vues:
60
>>>>>>>>Check out the Developer's Guide (I know, I know: read the book?) starting at the bottom of page 549. It gives an example of using input and output parameters with SQLEXEC.
>>>>>>>Believe it or not I usually start out by reading the book :) Must have missed something this time. I will go check it out and see if it helps. Thanks for the info.
>>>>>>>
>>>>>>>George
>>>>>>Ok, checked the docs. I was able to get the example to work but not mine (of course). I am including the stored procedure as well as the call I make to execute the sp in hopes that someone has an idea as to what I am doing wrong.
>>>>>>
>>>>>>Here is the stored procedure:
>>>>>>
>>>>>>CREATE PROCEDURE spgetmin
>>>>>>	@min_ret varchar(10) OUTPUT
>>>>>>AS
>>>>>>
>>>>>>DECLARE @m_min varchar(10)
>>>>>>DECLARE @m_assigned varchar(1)
>>>>>>DECLARE @m_recvd_date datetime
>>>>>>
>>>>>>DECLARE gmin SCROLL CURSOR
>>>>>>	FOR select * from mins where m_assigned='N' ORDER BY m_min
>>>>>>	FOR UPDATE OF m_assigned
>>>>>>OPEN gmin
>>>>>>FETCH FIRST FROM gmin INTO @m_min, @m_assigned, @m_recvd_date
>>>>>>SELECT @min_ret=@m_min
>>>>>>BEGIN TRANSACTION
>>>>>>	UPDATE mins SET m_assigned='Y' WHERE CURRENT OF gmin
>>>>>>IF @@ERROR <> 0
>>>>>>
>>>>>>	BEGIN
>>>>>>	ROLLBACK TRANSACTION
>>>>>>
>>>>>>	END
>>>>>>ELSE
>>>>>>	BEGIN
>>>>>>	COMMIT TRANSACTION
>>>>>>	END
>>>>>>
>>>>>>DEALLOCATE gmin
>>>>>>
>>>>>>
>>>>>>And here is the VFP code I use to execute the stored procedure. What I really want is the output parameter in VFP:
>>>>>>
>>>>>>
>>>>>>consql=SQLCONN('upsize')
>>>>>>=sqlsetprop(consql,'Asynchronous',.T.)
>>>>>>sputest=0
>>>>>>DO WHILE sputest=0
>>>>>>	sputest=SQLEXEC(consql,"use att_test;{call spgetmin (?@moutput)}")
>>>>>>ENDDO
>>>>>>IF sputest=-1
>>>>>>	lnCount=AERROR(laError)
>>>>>>	IF lnCount > 0
>>>>>>		lcErrorMsg=laError[2]
>>>>>>		nErrorNo=laError[1]
>>>>>>		nODBCErrorno=laError[5]
>>>>>>		cErrorMsg=lcErrorMsg+"["+LTRIM(STR(nErrorNo))+":"+LTRIM(STR(nODBCErrorno))+"]"
>>>>>>		=MESSAGEBOX(cErrorMsg+CHR(13)+'Update Error: Changes Rolled Back')
>>>>>>	ENDIF
>>>>>>ENDIF
>>>>>>=sqldisc(consql)
>>>>>>
>>>>>>
>>>>>>Any help would be GREATLY appreciated!
>>>>>>Thanks,
>>>>>>George
>>>>>
>>>>>Did you declare the variable moutput somewhere in your Fox code before you run the SQLEXEC? The variable has to exist before you use it in the SQLEXEC call.
>>>>
>>>>Yes, the variable is declared just above the VFP code listed here, just forgot to include that. I have tried initializing it as an empty string and with a single char such as 'x'. I cannot get the darn thing to return a value. I have also tried convert the return variable on the SQL Server side to an integer (the return should actually be a 10 digit phone number) and initialize moutput value as 0. This is driving me insane!
>>>
>>>Does it return anything, or cause an error? And forgive me for asking the obvious but are you sure the SP works (by testing it in I/SQLw or something)?
>>
>>I don't get any errors at all, just no return value. If I initialize moutput as '' then it looks like I get a formfeed returned. Go figure. If I initialize the variable with anything else I don't seem to get a return at all.
>>
>>Ask away, I'm never offended considering I've done (or not done) some pretty silly things in the past. Use the Enterprise Manager query window I can run the stored procedure and tell it to PRINT @min_ret. It prints the correct value every time.
>
>I just thought of another straw to grasp: Have you tried it with Asynchronous set to .F.? Assuming that you need to know the value minout before execution can continue, the connection doesn't really need to be asynchronous. Maybe that interferes with getting a value out.

Gary,
Thanks for all your help with this. I ended up compromising on this since it was imperative that I finish this part by Fri evening. I have listed the stored procedure below (just in case you are interested). I gave up on receiving a return value although if anyone has any ideas I sure would like to hear them. Anyway, here is what I ended up with:
CREATE PROCEDURE p_gmin
 AS
DECLARE @umin varchar(10)
SET ROWCOUNT 1
SELECT @umin=m_min FROM mins WHERE m_assigned='N' ORDER BY m_min
SELECT m_min FROM mins WHERE m_assigned='N' ORDER BY m_min
SET ROWCOUNT 0
UPDATE mins SET m_assigned='Y' WHERE m_min=@umin
Everything we see or seems
Is but a dream within a dream
- Edgar Allen Poe
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform