Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need Suggestions
Message
From
16/09/2003 09:13:04
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00829257
Message ID:
00829341
Views:
26
>Hi Cetin
>
>thanks for the swift reply
>
>i think the NODATA idea might work but,
>can you please explain by some example that how to load all the cursors with no data and how to unload data after using these cursors.
>
>Thanks
>Anwar

This time a lot of delay :) Sorry had many things to do.
While this works you should only use it as an idea (code is not complete and not optimized - couldn't find a better one in backyard for now) :
#Define SQLCONNECTION 	"Provider=SQLOLEDB.1;Integrated Security=SSPI;"+;
  "Persist Security Info=False;"+;
  "Initial Catalog=Northwind; Data Source=cetin\cetin"

oForm = Createobject('myForm',SQLCONNECTION)
oForm.Show
Read Events

Define Class myForm As Form
  DataSession = 2
  Height = 300
  Width = 800
  Add Object Grd1 As myGrid With Height = 300, Width = 400
  Add Object Grd2 As Grid With Height = 300, Width = 400, Left = 400

  Procedure Init
    Lparameters tcConn
    This.AddProperty('oConn', Newobject("ADODB.Connection"))
    With This.oConn
      .ConnectionString = tcConn
      .Mode = 16
      .Open()
    Endwith
    This.AddProperty('Dataenvironment',Createobject('myDataEnvironment', this.oConn))
    This.Grd1.RecordSource = 'ca_customers'
    This.Grd2.RecordSource = 'ca_orders'
  Endproc

  Procedure QueryUnload
    Clear Events
  Endproc
  Procedure Destroy
  Endproc

  Procedure DispError
    Local Array errors(1)
    Aerror(errors)
    ? 'Error--------------'
    For ix=1 To 7
      ? errors[ix]
    Endfor
    ? 'Error--------------'
  Endproc

Enddefine

DEFINE CLASS myDataEnvironment as DataEnvironment
	PROCEDURE init
	LPARAMETERS toConn
    With This
      .AddObject('caCustomers','myADOAdapter',toConn,'ca_customers')
      With .caCustomers
        .Tables = "Customers"
        .KeyFieldList = "CustomerID"
        .UpdatableFieldList = "CustomerID, CompanyName, ContactName, ContactTitle"
        .UpdateNameList = ;
          "CustomerID customers.CustomerID, "+;
          "CompanyName customers.CompanyName,"+;
          "ContactName customers.ContactName,"+;
          "ContactTitle customers.ContactTitle"
        .SelectCmd = "select * from customers"
        .CursorFill()
      Endwith
      .AddObject('caOrders','myADOAdapter',toConn,'ca_orders')
      With .caOrders
        .Tables = "Orders"
        .KeyFieldList = "ORDERID"
        .UpdateNameList = "CUSTOMERID Orders.CUSTOMERID, "+;
          "EMPLOYEEID Orders.EMPLOYEEID,"+;
          "FREIGHT Orders.FREIGHT,"+;
          "ORDERDATE Orders.ORDERDATE,"+;
          "ORDERID Orders.ORDERID"
        .UpdatableFieldList = "CUSTOMERID, EMPLOYEEID, FREIGHT, ORDERDATE, ORDERID"
        .CursorSchema = "CUSTOMERID C(5), EMPLOYEEID I, FREIGHT Y, ORDERDATE D, ORDERID I"

        .AddProperty('oCommand', Newobject('ADODB.Command') )
        With .oCommand
          .CommandText = "select Orders.CustomerID, Orders.EmployeeID, "+;
            "Orders.Freight, Orders.OrderDate, Orders.OrderID"+;
            " from Orders"+;
            " where customerID = ?"
          .Parameters.Append( .CreateParameter("CustomerID", 129,1,10,"") )
          .Parameters("CustomerID") = ca_customers.customerID
        Endwith
        .oCommand.ActiveConnection = .Datasource.ActiveConnection
        .AddProperty( 'oRS', .oCommand.Execute() )
        .CursorFill(.T., .F., 0, .oRS)
      Endwith
    ENDWITH
    endproc
ENDDEFINE

Define Class myGrid As Grid
  Procedure AfterRowColChange
    Lparameters nColIndex
    With Thisform.DataEnvironment.caOrders
      .oRS.ActiveCommand.Parameters("CustomerID") = ca_customers.customerID
      .CursorRefresh()
    Endwith
    Thisform.Refresh()
  Endproc
Enddefine

Define Class myADOAdapter As CursorAdapter
  AllowUpdate = .T.
  AllowInsert = .T.
  AllowDelete = .T.
  WhereType = 1
  UpdateType= 1
  SendUpdates = .T.
  DataSourceType = "ADO"

  Procedure Init
    Lparameters toConn, tcAlias
    With This
      .Alias = tcAlias
      .Datasource = Newobject("ADODB.Recordset")
      With .Datasource
        .ActiveConnection = toConn
        .LockType=4
        .CursorLocation = 3
        .CursorType = 2
      Endwith
    Endwith
  Endproc

  Procedure UpdateTable
    This.Datasource.Updatebatch()
  Endproc
Enddefine
PS: Dataenvironment object addition is intentional meaning you could do that using a DE (and maybe builders).
Also there are differences between ADO and ODBC,XML with cursoradapter. BVefore you drill down much read the related chapters.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform