> local oCursor > local AdapterAlias > local SourceTable > > set multilocks on > > oCursor = createobject('UnitPriceAdapter') > > with oCursor > > SourceTable = .Tables > > text to .SelectCmd textmerge noshow > select InvTranRef, Units, Price from <<SourceTable>> where Price <= 0 > endtext > > if .cursorfill() > > AdapterAlias = .Alias > CursorSetProp('buffering', 5, AdapterAlias) && optimistic table buffering > ? 'Buffering: ', CursorGetProp('buffering', AdapterAlias) > > browse && change the prices to -1 via SQL Server Query Analyzer before proceeding > > try > > > update (AdapterAlias) set Price = Price - 2 > browse && this will show prices <= -2 in the cursor > > if tableupdate(1, .f., AdapterAlias) > > ? 'update OK' > > * shouldn't need to call SQLCommit(), call it anyway to see if there > * are any exception > if SQLCommit(.DataSource) > 0 > ? 'SQLCommit OK' > else > ? 'SQLCommit failed' > endif > > ? SQLExec(.DataSource, .SelectCmd, "NewPriceTable") > > select NewPriceTable > browse && this will show prices = -1 > && implying tableupdate() did not update the SQLServer table > && but still returns .t., why?? > else > > = aerror(laErrors) > this.AddSQLError(-1, "UpdateRecords() " + this.SelectCmd, laErrors[2] + "; " + laErrors[3]) > > endif > > catch to oErr > ? "Catch:",oErr.ErrorNo > > finally > endtry > > else > > ? '.cursorfill() failed' > > endif > > endwith > > return > > endfunc > > *----------------------------------------------------------------------------* > >*==============================================================================* > >define class UnitPriceAdapter as CursorAdapter > > AllowUpdate = .T. > AllowDelete = .T. > AllowInsert = .T. > SendUpdates = .T. > > DataSourceType = "ODBC" > > Alias = "WrongPrice" > Tables = "MyTable" > KeyFieldList = "InvTranRef" > > CursorSchema = "InvTranRef C(10), Units N(17,4), Price N(9,4)" > UpdatableFieldList = "InvTranRef, Units, Price" > > FetchSize = -1 > MaxRecord = -1 > > *----------------------------------------------------------------------------* > > protected function init > > local ODBCConnString > > ODBCConnString = "Driver={SQL Server};Server=MyServer;DATABASE=MySqlDB;Trusted_Connection=yes;" > > * Add a property at run-time that holds a Connection Handle. > this.AddProperty('Connection', SQLStringConnect(ODBCConnString)) > > * The data source is our Connection Handle > this.DataSource = this.Connection > > = SQLSetProp(this.DataSource, 'asynchronous', .f.) > = SQLSetProp(this.DataSource, 'Transactions', 1) && auto > > text to this.UpdateNameList textmerge noshow > InvTranRef <<this.Tables>>.InvTranRef, Units <<this.Tables>>.Units, Price <<this.Tables>>.Price > endtext > > = dodefault() > > return > > endfunc > > *----------------------------------------------------------------------------* > > protected function destroy > > = SQLDisconnect(this.DataSource) > = dodefault() > > return > > endfunc > > *----------------------------------------------------------------------------* > >enddefine > >*==============================================================================* >