Information générale
Titre:
Gotcha -- EXEC needed when calling paramerized stored proc
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
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement