class TDatabase and ADO

class TDatabase and ADO

Postby lucasdebeltran » Wed Jul 17, 2013 7:43 am

Hello,

Works this class with ADO?.

I have to convert an old program that uses TDatabase.

Thank you very much.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: class TDatabase and ADO

Postby Antonio Linares » Wed Jul 17, 2013 8:41 am

Lucas,

Class TDataBase does not provide ADO support currently, but it would be quite easy to create an inherited Class from TDataBase to support ADO.

As I commented you, I am working on a project using ADO only, so actually I am focused on testing everything to get it working fine, and once the ADO code is fine, we could use it to build a Class TAdoDb :-)

Also, we have been publishing new ADO functions recently that could be used from such new Class.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: class TDatabase and ADO

Postby lucasdebeltran » Wed Jul 17, 2013 8:47 am

Thank you Antonio.

The presence of the method Execute for SQL confused me.

Anyway, I will rewrite the code using TDataRow, which is beautiful and very powerful and easy to use.

It would be interesting to update the ADO topic in the wiki adding the post from Elvira and latest samples provided by Mr. Nages.


Thank you.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: class TDatabase and ADO

Postby Antonio Linares » Wed Jul 17, 2013 9:09 am

Lucas,

Would you like to update the wiki yourself ? thanks :-)

http://wiki.fivetechsoft.com/doku.php?id=ado-related_stuffs
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: class TDatabase and ADO

Postby Antonio Linares » Wed Jul 17, 2013 9:22 am

Lucas,

You are right, Rao enhanced the Class TDataBase to have some ADO support, but it is not fully ADO compatible yet.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: class TDatabase and ADO

Postby lucasdebeltran » Wed Jul 17, 2013 10:14 am

Antonio,

What is the problema with TDataRow class?.

It is finished and it Works perfect. It is not a replacement for TDatabase, but it helps very much introducing data to the Recordset and with the use of dialogs too:

The class is very powerfull and saves a lot of coding. For example:

Code: Select all  Expand view

   IF lAppend                         // Si hay que a¤adir
      oData := TDataRow():New( oRs, nil, .t. )

   ELSE
      oRs:AbsolutePosition := nRegistro  // Goto
      oData := TDataRow():New( oRs )

   ENDIF




  IF lAppend
      DEFINE DIALOG oDlg RESOURCE "USUARIOS" TITLE "Añadir un nuevo USUARIO"
   ELSE
      DEFINE DIALOG oDlg RESOURCE "USUARIOS" TITLE "Modificar un USUARIO"
   ENDIF



   REDEFINE GET oData:USUARIO      ID  101 OF oDlg
   REDEFINE GET oData:CLAVE         ID  102 OF oDlg


   REDEFINE BUTTON ID 701 OF oDlg  ACTION( lSave := .T., oDlg:End() )
   REDEFINE BUTTON ID 702 OF oDlg  ACTION( lSave := .F., oDlg:End() )



   ACTIVATE DIALOG oDlg CENTERED

   IF lSave

      oData:Save()

   ENDIF
   // ---------------------------------------------------------------------

 
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: class TDatabase and ADO

Postby Antonio Linares » Wed Jul 17, 2013 10:53 am

Lucas,

No hay ningún problema con ella :-)

Lo que ocurre es que Rao lleva más tiempo usando ADO y ya está encapsulando funcionalidad en las nuevas funciones de ADO y en esa clase, pero para mis pruebas con ADO de momento prefiero que no haya ninguna capa intermedia, para asi poder hacer cualquier prueba que me pueda interesar.

De todas formas, en mi código ya estoy usando algunas de las funciones nuevas.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: class TDatabase and ADO

Postby nageswaragunupudi » Wed Jul 17, 2013 12:18 pm

TDataRow class was not meant to be just for ADO.
It is also not meant to serve the purpose of TDatabase class for ADO.
TDataRow is completely generic for any datasource, be it DBF, Ado, etc.

It is basically a class to handle Gather/Scatter mechanism to edit existing or new records and can be used transparently without regard to the underlying datasource.

Lucas, actually while using TDataRow it is not necessary to save and restore the record pointer. TDataRow itself takes care of it.

Antother feature of TDataRow is that we can use even XBrowse itself as its datasource.

Also both XBrowse and TDataRow make certain complex things simple. Like its much easier to handle BLOB data like photos and images.

eg; oRec:Photo := MemoRead( "photo.jpg" ). This works with DBF memo fields as well as ADO blob fields without the need for specific coding.

With both XBrowse and TDataRow we can write "single code" to work with any datasource. Just change the datasource and the same code works.
I shall follow it up with a small sample.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: class TDatabase and ADO

Postby Antonio Linares » Wed Jul 17, 2013 1:19 pm

Rao,

I think that the Class TDataRow name is little confusing, as James commented about it (not sure if he was who did it)

Maybe TRecord would be easier to understand it ? I admit that I am not used to this great Class from Rao yet
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: class TDatabase and ADO

Postby nageswaragunupudi » Wed Jul 17, 2013 1:46 pm

Sample:
Code: Select all  Expand view
/*
* tstdrow.prg
* test TDataRow usage
*
*/


#include "fivewin.ch"
#include "xbrowse.ch"
#include "adodef.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local uDataSource

   SET DATE ITALIAN
   SET CENTURY ON
   SET DELETED ON
   FWNumFormat( "A", .t. )

   uDataSource := OpenData()
   BrowseData( uDataSource )
   CloseData(  uDataSource )

return nil

//----------------------------------------------------------------------------//
// TESTING XBROWSE WITH TDATAROW
// Both XBrowse and TDataRow Code is the same for all Data Sources
//----------------------------------------------------------------------------//

static function BrowseData( uData )

   local oDlg, oBrw, oFont, oRec

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE GetSysMetrics(0) * 0.9,400 PIXEL FONT oFont ;
      TITLE "TDataRow test : " + FWVERSION
   @ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      DATASOURCE uData AUTOCOLS AUTOSORT ;
      FOOTERS CELL LINES NOBORDER

   WITH OBJECT oBrw
      :nEditTypes    := EDIT_GET
      :Married:SetCheck()
      //
      :CreateFromCode()
   END

   @ 10, 10 BUTTON "Edit" SIZE 40,12 PIXEL OF oDlg ;
      ACTION ( oRec := TDataRow():New( uData ), oRec:Edit(), oBrw:Refresh(), oBrw:SetFocus() )
   @ 10, 60 BUTTON "Append" SIZE 40,12 PIXEL OF oDlg ;
      ACTION ( oRec := TDataRow():New( uData, nil, .t. ), oRec:Edit(), oBrw:Refresh(), oBrw:SetFocus() )
   @ 10,110 BUTTON "Delete" SIZE 40,12 PIXEL OF oDlg ACTION ( oBrw:Delete(), oBrw:SetFocus() )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

static function OpenData()

   local nChoice, uDataSource

   nChoice := Alert( "Choose DataSource", { "DBF", "TDATABASE", "ADO", "Quit" }, "DATASOURCE" )
   if nChoice  <= 2
      USE C:\FWH\SAMPLES\CUSTOMER NEW ALIAS CUST SHARED VIA "DBFCDX"
      if nChoice == 1
         uDataSource    := Alias()
      else
         DATABASE uDataSource
      endif
   elseif nChoice == 3
      uDataSource := FW_OpenRecordSet( "c:\fwh\samples\xbrtest.mdb", "CUSTOMER" )
   else
      QUIT
   endif

return uDataSource

//----------------------------------------------------------------------------//

static function CloseData( uDataSource )

   if ValType( uDataSource ) == 'C'
      ( uDataSource )->( DbCloseArea() )
   elseif ValType( uDataSource ) == 'O'
      uDataSource:Close()
      if uDataSource:ClassName() == "TOLEAUTO"
         uDataSource:ActiveConnection:Close()
      endif
   endif

return nil

//----------------------------------------------------------------------------//
 


Please use latest FWH release.

The entire code to browse, add, edit and delete() work independently of the datasource. The same code works for RDD, TDatabase and ADO

This sample also demonstrates the latest feature oBrw:Delete().
New Delete() method of XBrowse deletes the current row in a manner appropriate to the datasource, repositions the current row and refreshes the browse.

In the above sample, I used the default Edit() of the TDataRow. Obviously we use custom edit dialog to edit/add the records. We can do this in to ways.

oRec := TDataRow():New( Source )
oRec:bEdit := { |oRec| MyEditDlg( oRec ) }
oRec:Edit()

Or
oRec := TDataRow():New( Source )
MyEditDlg( oRec )

Whichever way we edit, please use only built in UnDo() and Save() methods of TDataRow.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: class TDatabase and ADO

Postby nageswaragunupudi » Wed Jul 17, 2013 2:02 pm

Antonio Linares wrote:Rao,

I think that the Class TDataRow name is little confusing, as James commented about it (not sure if he was who did it)

Maybe TRecord would be easier to understand it ? I admit that I am not used to this great Class from Rao yet


When I started drafting the class, I named it TRecord instinctively. Latter I changed it as TDataRow for two reasons:

1. I understand that the TData library provided by Mr James Bott contains a TRecord class also. I understood this from his postings. I did not want to use a name that would conflict with his library class, because some users are using his library.

2. The words "Record" and "Field" are used mostly by XBase users and ADO. In many other environments it is usual to refer to them as Rows and Columns. I chose TDataRow name.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: class TDatabase and ADO

Postby Antonio Linares » Wed Jul 17, 2013 3:58 pm

Rao,

many thanks for the explanation :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42094
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: class TDatabase and ADO

Postby nageswaragunupudi » Thu Jul 18, 2013 8:17 am

lucasdebeltran wrote:Hello,

Works this class with ADO?.

I have to convert an old program that uses TDatabase.

Thank you very much.

You can write a small wrapper class for recordset with methods similar to tdatabase.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: class TDatabase and ADO

Postby nageswaragunupudi » Thu Jul 18, 2013 8:19 am

The presence of the method Execute for SQL confused me.

Please express your confusion. We try to clarify to extent we know.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: class TDatabase and ADO

Postby lucasdebeltran » Thu Jul 18, 2013 8:26 am

Mr. Nages,

Thank you, all is clear by now.

The present code uses for example Database:save(), :recno(), or :eof() methods.

But I can rewrite the code and use TDataRow, no problem.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 80 guests