Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Different ways to connect to SQL server
Message
From
19/02/2004 13:34:48
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00877675
Message ID:
00878841
Views:
12
>I might be a bit slow here but if I use a cursoradapter (which sounds great) wont I still run into the problems of trying to execute a stored procedure with the parameters that I am passing? I understand that the CA is designed to take a source and convert it to a vfp cursor but if it other than a simple select statment will I still have the same problems? Will it handle the sqlexec() command rather than a select statement? Wont the same problems of getting the record set still be present?
>
>Thanks again
>Kelly

Kelly,
You'd decide that better after playing with it for sometime. CursorAdapter supports ODBC,OLEDB,XML,Native and has SelectCmd, UpdateCmd, InsertCmd, DeleteCmd which let you do those with stored procedures as well rather than straight select,insert,update,delete commands.
Check this sample. In that I didn't use a parameterized stored proc but might be. Should give idea how you could easily create parameterized cursors from SQL server :
#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 = ?"+;
            " order by employeeID, orderdate desc"
          .Parameters.Append( .CreateParameter("CustomerID", 129,1,10,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
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