SQLExpress - Xb2.NET     ot4xb  
xfree.public
Postgree + Ado
Thread Starter: Jose Valle Started: 6/24/2008 4:59 PM UTC
Replies: 2
Postgree + Ado
Hola

Me han dejado un ejemplo de como se usa ADO para acceder datos.
Me parece que es muy sencillo de usar. A mi me viene muy bien porque Fastreports usa Ado para acceder a los datos.
Os pido vuestra opinion sobre ADO antes de dedicarle tiempo. ¿Es una solución fiable?

Hello

This is a sample of how to use ADO to access PostGree. It looks very easy.
Any experiences with Ado?



#include "ado.ch"
#include "common.ch"

#define CRLF chr(13)+chr(10)
#PRAGMA LIBRARY ("ASCOM10.LIB")


PROCEDURE MAIN
LOCAL oConexion, oRs, lConectado , nValue

      oConexion := CreateObject("ADODB.Connection")

      //ok-> oConexion:ConnectionString :=  "Provider= Microsoft.Jet.OLEDB.4.0;Data Source= BookSale.mdb"

      Los espacios en blanco a veces dan error
      //ok-> //oConexion:ConnectionString :=  "Provider=Microsoft OLE DB Provider for ODBC Drivers;Server=localhost;Port=5432;Data Source=PostgreSQL35W;User Id=postgres;Password=43434343;"
      //ok->//oConexion:ConnectionString :=  "Provider=Microsoft OLE DB Provider for ODBC Drivers;Server=localhost;Port=5432;Data Source=PostgreSQL35W;User Id=postgres;Password=43434343;"

      oConexion:ConnectionString :=  " Server=localhost; Data Source = PostgreSQL35W ; UserId = postgres ;"

/*
     sets the string used to connect to a PostgreSQL database.
       /// Valid values are:
       /// Server:                     Address/Name of Postgresql Server;
       /// Port:                       Port to connect to;
       /// Protocol:                   Protocol version to use, instead of automatic; Integer 2 or 3;
       /// Database:                   Database name. Defaults to user name if not specified;
       /// User Id:                    User name;
       /// Password:                   Password for clear text authentication;
       /// SSL:                        True or False. Controls whether to attempt a secure connection. Default = False;
       /// Pooling:                    True or False. Controls whether connection pooling is used. Default = True;
       /// MinPoolSize:                Min size of connection pool. Default: 1;
       /// MaxPoolSize:                Max size of connection pool. Default: 20;
       /// Encoding:                   Encoding to be used; Can be ASCII or UNICODE. Default is ASCII. Use UNICODE if you are having problems with accents.
       /// Timeout:                    Time to wait for connection open in seconds. Default is 15.
       /// CommandTimeout:             Time to wait for command to finish execution before throw an exception. In seconds. Default is 20.
       /// Sslmode:                    Mode for ssl connection control.
       /// ConnectionLifeTime:         Time to wait before closing unused connections in the pool in seconds. Default is 15.
       /// SyncNotification:           Specifies if Npgsql should use synchronous notifications

       Encoding can be ASCII or UNICODE. If your application uses characters with accents and with default settings it doesn't work, try changing that.
       Min pool size when specified will make NpgsqlConnection pre allocates this number of connections with the server.
       Sslmode can be one of the following values:
           Prefer - If it is possible to connect using ssl, it will be used.
           Require - If an ssl connection cannot be made, an exception is thrown.
           Allow - Not supported yet, just connects without ssl.
           Disable - No ssl connection is done.
           Default is Disable.
           Server=192.168.10.4;Port=5432;Userid=postgres;Password=stefan;Protocol=3;SSL=false;Pooling=true;MinPoolSize=1;MaxPoolSize=20;Encoding=UNICODE;Timeout=15;SslMode=Disable;Database=test

*/

      oConexion:open()

      ? ' donde me conecto', oConexion:ConnectionString

      inkey(0)

      oRs := CreateObject("ADODB.Recordset")

      public es el schema
      oRs:Open("SELECT * FROM public.apuntes ORDER BY fecha",oConexion,0,3)

       IF oRs:Bof .And. oRs:Eof
         ?  "NO HAY DATOS"
           oConexion:Close()
           return
       endif

       oRs:MoveFirst()

       do while .NOT. oRs:eof

          ? 'valor', oRS:fields("fecha"):Value

          oRs:MoveNext()
       enddo

      inkey(0)

     oRs:Close()

  return

/*
PROCEDURE MAIN   //ok

LOCAL oConexion, oRs, lConectado , nValue

      oConexion := CreateObject("ADODB.Connection")

      //oConexion:ConnectionString :=  "Provider= Microsoft.Jet.OLEDB.4.0;Data Source= BookSale.mdb"
      oConexion:ConnectionString :=  "Provider= Microsoft.Jet.OLEDB.4.0;Data Source= BookSale.mdb"

      oConexion:open()

      ? ' donde me conecto', oConexion:ConnectionString

      inkey(0)

      oRs := CreateObject("ADODB.Recordset")

      oRs:Open("SELECT * FROM Publishers ORDER BY NAME",oConexion,0,3)

       IF oRs:Bof .And. oRs:Eof
         ?  "NO HAY DATOS"
           oConexion:Close()
           return
       endif

       oRs:MoveFirst()

       do while .NOT. oRs:eof

          ? 'valor', oRS:fields("Name"):Value

          oRs:MoveNext()
       enddo

      inkey(0)

     oRs:Close()

  return
Re: Postgree + Ado
Estimado Jose

Bueno, definiendo

1.- ot4xb accesaa directamente al API de PostgreSQL el cual nos da
    rapidez, pero nos casamos con Postgresql.
    Xbase++ -> ot4xb -> api postgresql -> database

2.- SqlExpress++ accesa via ODBC a Postgresql y la verdad no se si
    el odbc de postgresql necesite el api de postgresql para correr
    asi que quedaria asi :
    Xbase++ -> sqlexpress++ -> odbc -> api postgresql -> database

3.- Usando ADO, segun entiendo quedaria asi
    Xbase++ -> COM/ActiveX -> OLE DB - > database


Pero bueno esto me encontre por ahi

ADO = API to OLE DB.
ADO Speed < OLE DB Speed
Programming the OLE DB API Directly may take a very long time to master.

Explanation from M$.
ActiveX Data Objects (ADO) is a high-level, easy-to-use interface to OLE DB.
OLE DB is a low-level, high-performance interface to a variety of data
stores.
ODBC is another low-level, high-performance (maybe not-so high-performance,
I think) interface that is designed specifically for relational data stores.

ADO provides a layer of abstraction between your client or middle-tier
application and the low-level OLE DB interfaces. ADO uses a small set of
Automation objects to provide a simple and efficient interface to OLE DB.
This interface makes ADO the perfect choice for developers in higher level
languages, such as Visual Basic and VBScript, who want to access data
without having to learn the intricacies of COM and OLE DB.

A Note on Providers from M$:
You are strongly encouraged to use one of the native OLE DB Providers
instead of the Microsoft Open Database Connectivity (ODBC) Provider. Native
OLE DB Providers provide better application stability and performance.

If you want more info, go to http://msdn.microsoft.com/data
Then drill down from "Data Access->Reference.

HTH, Matt
---
Outgoing mail is certified Virus Free.
Regards, Matt
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.548 / Virus Database: 341 - Release Date: 12/5/2003


-- MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe: http://lists.mysql.com/myodbc?unsub=gcdmo-myodbc [at] m.gmane.org
Re: Postgree + Ado
Hola,

Precisando <ggg>
Xbase++ -> ot4xb -> api postgresql -> database
ok. Bueno incluso si alguien quiere saltarse ot4xb pues se puede igual usando DllCall() solo que con ot4xb es más facil.

DllCall() es un pelin más lento que FpQCall() de ot4xb y DllExecuteCall() un pelín más rápido siempre que no tengas que convertir ni comprobar  ningún parámetro.  

   Xbase++ -> sqlexpress++ -> odbc -> api postgresql -> database
Xbase++ -> sqlexpress++ -> odbc -> driver odbc -> api postgresql -> database

   Xbase++ -> COM/ActiveX -> OLE DB - > database
Xbase++ -> COM/ActiveX -> OLE DB - > driver oledb -> api de postgres -> database

Mi consejo es que para no complicarse la vida lo mejor es usar SQLExpress, te maneja cursores,
reordena los en el lado del cliente y tiene opción de traerse records en background al mismo tiempo que se estan mostrando en un browse

A mi ADO me encanta para usarlo desde C++, funciona muy rápido es muy facil de usar y si encima
lo usas con los Smart Pointers de VC++ pues ni te preocupas de hacer Release o de incrmentar la referencia de los objetos, el compilador se ocupa automaticamente de todo.

Ahora usar ADO con Xbase++ en primer lugar el soporte ActiveX de Xbase++ no es precisamente demasiado rápido
en la V 2.0 de Xbase++ el GC llamará automaticamente a un metodo destructor de nuestros objetos, pero hoy por hoy
hay que llevar el control manualmente asi que tenemos 2 cosas en contra: velocidad y complejidad.

Ahora no hay ningún probema en que FRAX acceda a la base de datos usando ADO y la aplicación lo haga usando ODBC o incluso usando el API de postgres directamente.

Saludos,

Pablo Botella