Rick - the Delete()
method should call oSql.ExecuteNonQuery()
rather than justExecute()
.
The reason I make this request is that Execute()
will change the current work alias, as it creates a new cursor even though we are sending the DELETE
command to Sql Server. I was not expecting a cursor to be created, or for my current work alias to be changed, so it caused problems that I had to work around in my local code.
If you corrected it to use ExecuteNonQuery()
, the current work alias will not change, which I would find much better.
************************************************************************
FUNCTION Delete(lnPk)
LOCAL lcPKField, lnResult
THIS.SetError()
IF !THIS.OPEN()
RETURN .F.
ENDIF
lcPKField = THIS.cpkfield
*** Try to load the record if a PK was passed
IF EMPTY(lnpk)
lnpk = THIS.odata.&lcPKField
ENDIF
DO CASE
CASE THIS.ndatamode = 0
*** Delete the record
DELETE FOR &lcPKField = lnpk
CASE THIS.ndatamode = 2
THIS.csql = "DELETE FROM " + THIS.cfilename + " WHERE " +THIS.cpkfield + " =" + TRANSFORM(lnpk)
lnResult = THIS.osql.execute(THIS.csql)
IF lnResult # 1
THIS.SetError(THIS.osql.cerrormsg)
RETURN .F.
ENDIF
CASE THIS.ndatamode = 4
lnResult = THIS.ohttpsql.execute("DELETE FROM " + THIS.cfilename + " WHERE " +THIS.cpkfield + " =" + TRANSFORM(lnpk) )
IF lnResult < 0
THIS.SetError(THIS.osql.cerrormsg)
RETURN .F.
ENDIF
ENDCASE
*** And clear the data area
THIS.getblankrecord()
RETURN .T.
ENDFUNC
ExecuteNonQuery()
calls .Execute()
so in theory this shouldn't be any different.
FUNCTION ExecuteNonQuery(lcSQL, llStoredProcedure)
THIS.naffectedrecords = 0
lnResult = THIS.Execute(lcSQL,,llStoredProcedure)
While wwBusinessObject.Delete()
does:
this.oSql.Execute(lcSql)
Which in effect is the same thing? How are you seeing different results? At the end of the day it all runs through SQLEXEC()
which either creates a cursor or not depending on the query type and which is determined by the FoxPro engine.
+++ Rick ---