Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do I know if CursorAdapter has updated SQL records
Message
From
19/02/2004 23:29:04
James Chan
Objectmastery Pty Ltd
Hawthorn, Australia
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Client/server
Title:
How do I know if CursorAdapter has updated SQL records
Miscellaneous
Thread ID:
00879065
Message ID:
00879065
Views:
59
Hi,

I am using CA to update an SQL table. CA will not update the records if they have been changed by another process. This is working OK. But how do I know if CA has updated the SQL table successfully?

FYI, I list my sample code below where TableUpdate() always return .t., even if I changed the SQL table records mannaully using QA.
----------------------
    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

*==============================================================================*
James Chan
ObjectMastery Pty Ltd
Next
Reply
Map
View

Click here to load this message in the networking platform