ConsultaNativa() && Consulta datos nativos con CA * ConsultaADO() && Consulta datos via ADO con CA * TestXMLAdapter() && Genera XML de un cursor cualquiera * CreaDiffGram() && Prueba de creacion de un diffgram * AplicaDiffGram() && Prueba de aplicacion de las modificaciones en un diffgram Return *************************************************************************************** Function ConsultaNativa * Abro la DBC Open Database ( Home(2) + 'Northwind\Northwind.dbc' ) * Creo el CursorAdapter Local oCA As CursorAdapter oCA=Createobject("CursorAdapter") * Seteo las propiedades necesarias para obtener los datos With oCA .DataSourceType="NATIVE" .Alias="Clientes" .SelectCmd="select * from customers" If .CursorFill() Select Clientes Browse Else Messagebox( "Falló el CursorFill!!!", 16 ) Endif Endwith oCA = Null Release oCA * Cierro la DBC Close Database Return *************************************************************************************** Function ConsultaADO * Me conecto al BackEnd con un objeto ADO Connection oConn = Createobject("ADODB.Connection") oConn.ConnectionString = 'Provider=SQLOLEDB.1;Integrated Security=SSPI;' ; + 'Persist Security Info=False;Initial Catalog=Northwind;Data Source=(local)' oConn.Open() * Creo un objeto ADO Command oCmd = Createobject("ADODB.Command") oCmd.ActiveConnection = oConn * Creo un objeto ADO Recordset oRS = Createobject("ADODB.Recordset") With oRS .CursorLocation = 3 &&adUseClient .LockType = 3 &&adLockOptimistic .ActiveConnection = oConn Endwith * Creo un CursorAdapter Local oCA As CursorAdapter oCA=Createobject("CursorAdapter") * Seteo las propiedades necesarias para obtener los datos With oCA .DataSourceType="ADO" .Datasource = oRS .Alias="Clientes" .SelectCmd="select * from customers" .KeyFieldList="CustomerID" .UpdatableFieldList = "companyname,contactname" .UpdateNameList = [companyname Customers.CompanyName, ] ; + [contactname Customers.ContactName] If .CursorFill() Select Clientes CursorSetProp("Buffering",5) Browse If TableUpdate(.t.) MessageBox("Actualizó") EndIf Else Messagebox( "Falló el CursorFill!!!", 16 ) EndIf Endwith oCA = Null Release oCA oRS = Null Release oRS oCmd = Null Release oCmd oConn.Close() oConn = Null Release oConn Return *************************************************************************************** Function TestXMLAdapter * Abro la DBC *!* Open Database ( Home(2) + 'Northwind\Northwind.dbc' ) *!* USE Customers In 0 *!* USE orders In 0 Local oXA as XMLAdapter oXA=Createobject("XMLAdapter") oXA.LoadXML("CATest.XML",.t.) Suspend *!* oXA.AddTableSchema( "Customers" ) *!* oXA.AddTableSchema( "Orders" ) *!* oXA.ToXML("cXML") && Nombre de la variable entre comillas *!* oXA.ToXML("CATest.XML", "", .T.) && Nombre del archivo (sin schema) *!* Messagebox(cXML,64) oXA = Null Release oXA oCA = Null Release oCA * Cierro la DBC Close Databases Return *************************************************************************************** Function CreaDiffGram * Por las dudas, cierro todo Close Databases All Set Multilocks On Clear * Creo la tabla auxiliar *Create Table TestVFP8 (Id Int Autoinc, nombre C(20), apellido C(20)) * declaro objetos y variables, una buena costumbre Local oCA As CursorAdapter Local oXA As Xmladapter Local cXML As String * Creo el CursorAdapter oCA=Createobject("CursorAdapter") With oCA * Seteo algunas propiedades y traigo un cursor vacio para hacer los Inserts .Alias="CATest" .DataSourceType="NATIVE" .SelectCmd="select * from TestVFP8" && Aunque esta vacio. un Where 1 = 0 * me asegura que lo que agregue lo va a tomar como Inserted If .CursorFill() Select CATest * Buffering para el DiffGram * Agrego algunos datos CursorSetProp( "Buffering", 5 ) * Insert Into CATest (nombre, apellido) Values ("Martin", "Salias") replace in CATest nombre with "Carlos Martín" * Insert Into CATest (nombre, apellido) Values ("Ruben", "Rovira") * Creo el XMLAdapter para generar el DiffGram oXA=Createobject("XMLAdapter") With oXA .AddTableSchema( "CAtest" ) .PreserveWhiteSpace= .T. .IsDiffGram= .T. oXA.ToXML("cXML", "", .F., .T., .T. ) && Name, SchemaLocation, IsFile, ChangesOnly, IncludeBefore Endwith Messagebox( cXML, 64 ) * Guardo el DiffGram en el disco (Podria haber utilizado el 3º parametro en .T. * pero no tendriamos el MessageBox() anterior Strtofile( cXML, "diff.xml" ) Else Messagebox( "CursorFill failed!!!", 16 ) Endif Endwith oCA = Null Release oCA oXA = Null Release oXA cXML = Null Release cXML Close Databases All Return *************************************************************************************** Function AplicaDiffGram Close Databases All Clear * declaro objetos y variables Local oCA As CursorAdapter Local oXA As Xmladapter Local cXML As String * Creo el CursorAdapter oCA=Createobject("CursorAdapter") With oCA * Seteo algunas propiedades para recuperacion de datos .Alias="CATest" .DataSourceType="NATIVE" .SelectCmd="select * from TestVFP8" * Seteo algunas propiedades para actualizacion de datos .Tables=[TestVFP8] .KeyFieldList="id" .UpdatableFieldList = "nombre, apellido" * No va el ID porque es autoinc = readonly .UpdateNameList = [nombre TestVFP8.nombre, apellido TestVFP8.apellido] If oCA.CursorFill() Select CATest * Buffering para el DiffGram CursorSetProp( "Buffering", 5 ) * Recupero el DiffGram del disco cXML = Filetostr( "diff.xml" ) * Creo el XMLAdapter para cargar y aplicar el DiffGram oXA=Createobject("XMLAdapter") With oXA .AddTableSchema( "CAtest" ) .LoadXML( cXML ) oXA.Tables( 1 ).ApplyDiffgram() Endwith * Confirmo las actualizaciones en la tabla (Aca sería el lugar para usar transacciones) If Tableupdate(.T.) Messagebox( "Actualizado", 64 ) Else Messagebox( "Falló el TABLEUPDATE!!!", 16 ) =AError(laError) Suspend Endif Else Messagebox( "Falló el CursorFill!!!", 16 ) Endif Endwith oCA = Null Release oCA oXA = Null Release oXA Close Databases All ReturnAté mais,