Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Gotcha -- EXEC needed when calling paramerized stored proc
Message
De
14/08/2003 11:58:29
Tom Johnson
Plymouth Rock Technology, Inc.
Plymouth, Massachusetts, États-Unis
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Titre:
Gotcha -- EXEC needed when calling paramerized stored proc
Divers
Thread ID:
00820178
Message ID:
00820178
Vues:
70
This one drove me nuts. It turns out that for VFP8, ?parameters aren't evaluated when calling a stored procedure in the CursorAdapter (Datasourcetype=ODBC) unless you prefix the command with "EXEC".

See the difference between lines 1&2. It took me a day to find this subtlety.

cSelectCmd="EXEC CustOrdersDetail ?lnId" && THIS DOES WORK !!!!!!!!!
cSelectCmd="CustOrdersDetail ?lnId" && THIS DOES NOT WORK !!!!!!!!!
cSelectCmd="CustOrdersDetail 10248" && this will work but the parameter is hardcoded


Code to replicate againsts Northwind on SQLSERVER is given below...and no I don't use "secret" for my sa password :)

Best regards,

Tom Johnson






* Lets make darn sure the parameter is available
PUBLIC lnId
lnId=10248


x=CREATEOBJECT("nwDataEnv")
x.opentables()
SELECT crsOrderDetails
BROWSE && this will fail if using parameters without "EXEC " command.



DEFINE CLASS nwDataEnv AS dataenvironment

Tag = "dsn=NORTHWIND;uid=sa;pwd=secret;trusted_connection=no;"
Width = 520
Height = 200
DataSource = .NULL.
DataSourceType = "ODBC"
Name = "nwDataEnv"

PROCEDURE BeforeOpenTables
set multilocks on
This.DataSource = sqlstringconnect([dsn=Northwind;uid=sa;pwd=secret;trusted_connection=no])
ENDPROC


ADD OBJECT caOrderDetails AS cursoradapter WITH ;
UseDeDataSource = .T., ;
DataSourceType = "Native", ;
CursorSchema = "UNITPRICE N(10,2), QUANTITY N(10,2),DISCOUNT(N,5), EXTENDEDPRICE N(10,2)", ;
Alias = "crsOrderDetails", ;
Name = "caOrderDetails", ;
BufferModeOverride=5 ;

PROCEDURE caOrderDetails.BeforeCursorFill
LPARAMETERS luseCursorSchema, lNoDataOnLoad, cSelectCmd

* cSelectCmd="exec CustOrdersDetail ?lnId" && THIS DOES WORK !!!!!!!!!

cSelectCmd="CustOrdersDetail ?lnId" && THIS DOES NOT WORK !!!!!!!!!

* cSelectCmd="CustOrdersDetail 10248" && this will work but the parameter is hardcoded

this.CursorFill()
ENDPROC

ENDDEFINE
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform