> FUNCTION Cursor_Save_View(cCursor AS STRING, cTable AS STRING, cPKField AS STRING, tiDataSessionID AS INTEGER) > * This routine saves a whole cursor to the back end very quickly by tricking the cursor into behaving > * like a remote view. This routine does not perform pre-maintenance on the table: like converting > * blank dates into valid SQL Server values or initializing null values. > * Primary key values must be assigned before calling this routine. > LOCAL loRec, llRetVlu > cPKField=IIF(EMPTY(cPKField),'PK',cPKField) > tiDataSessionID = IIF(EMPTY(tiDataSessionID),this.DataSessionId,tiDataSessionID) > SET DATASESSION TO tiDataSessionID > TRY > SELECT (cCursor) > SCATTER MEMO NAME loRec > * Make the cursor updatable to the back end and wrap in a remote transaction > =SQLSetProp(THIS.iCH, "Transactions", 2) > =CURSORSETPROP("Tables", cTable) > =CURSORSETPROP("FetchMemo",.T.) > =CURSORSETPROP("KeyFieldList", cPKField) > =CURSORSETPROP("UpdatableFieldList", THIS.AllMembers(loRec)) > =CURSORSETPROP("SendUpdates", .T.) > =CURSORSETPROP("UpdateNameList", THIS.AllMembers(loRec,cTable)) > * Update Locally > IF TABLEUPDATE(1,.T.,cCursor) > * Commit the changes > =SQLCOMMIT(THIS.iCH) > llRetVlu = .T. > ELSE > * Something went wrong, log it and roll back the transaction > THIS.ERROR(0,'TableUpdate',0) > =SQLROLLBACK(THIS.iCH) > ENDIF > =SQLSetProp(THIS.iCH, "Transactions", 1) > CATCH TO oErr > llRetVlu = .F. > THIS.LOG("ERROR - "+oErr.MESSAGE) > FINALLY > IF SQLGETPROP(THIS.iCH,"Transactions")=2 > * If the Tansaction was not closed, then something went wrong with the update > llRetVlu = .F. > THIS.LOG("ERROR - Transaction left in flux, therefore performed a rollback") > =SQLROLLBACK(THIS.iCH) > =SQLSetProp(THIS.iCH, "Transactions", 1) > ENDIF > * Disconnect the cursor and cleanup > =CURSORSETPROP('SendUpdate', .F.) > =CURSORSETPROP("Tables") > =CURSORSETPROP("KeyFieldList") > =CURSORSETPROP("UpdatableFieldList") > =CURSORSETPROP("UpdateNameList") > ENDTRY > SET DATASESSION TO THIS.DATASESSIONID > RETURN llRetVlu > ENDFUNC >