FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ADO: Listing tables from a database
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
ADO: Listing tables from a database
Posted: Thu May 02, 2013 10:15 PM
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xbrowse.ch"
#include "xhb.ch"

function Main()

   local oCon := TOleAuto():New( "ADODB.Connection" )
   local oCat := TOleAuto():New( "ADOX.Catalog" )
   local oRs  := TOleAuto():New( "ADODB.Recordset" )
   local aTables := {}, cTable, oError

   try
      oCon:Open( "Provider='Microsoft.Jet.OLEDB.4.0'; Data Source='xbrtest.mdb';" )
   catch oError
      MsgInfo( oError:Description )
   end   

   oCat:ActiveConnection = oCon
   oRs = oCon:OpenSchema( 20 ) // adSchemaTables
   
   while ! oRs:Eof()
      AAdd( aTables, oRs:Fields:Item( "Table_Name" ):Value )
      oRs:MoveNext()
   end   
   
   XBROWSER aTables SELECT cTable := aTables[ oBrw:nArrayAt ]

   oRs:Close()
   oRs:CursorType     = 1        // opendkeyset
   oRs:CursorLocation = 3        // local cache
   oRs:LockType       = 3        // lockoportunistic

   if ! Empty( cTable )
      try
         oRs:Open( "SELECT * FROM " + cTable, oCon ) // Password="abc" )
      catch oError
         MsgInfo( oError:Description )
      end   

      XBrowser( oRS )
   endif
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ADO: Listing tables from a database
Posted: Fri May 03, 2013 09:13 AM
This is an alternative way of doing it using the most recent FWH functions:

Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()

   local oCn, oRs, cTable

   oCn   := FW_OpenAdoConnection( "Provider='Microsoft.Jet.OLEDB.4.0'; Data Source='xbrtest.mdb';" )

   if oCn != nil
      oRs   := oCn:OpenSchema( 20 )

      #ifdef __XHARBOUR__
         oRs:cClassName := "RECORDSET"  // due to a bug in xbrowse.prg. Fixed in FWH13.05
      #endif

      XBROWSER oRs TITLE "Select a table" ;
         COLUMNS { "TABLE_NAME" } SELECT ( cTable := oBrw:aCols[ 1 ]:Value )
         
      oRs:Close()
      
      if ! Empty( cTable )
         if ' ' $ cTable
            cTable   := '[' + cTable + ']'
         endif
         if ( oRs := FW_OpenRecordSet( oCn, cTable ) ) != nil
            XBROWSER oRs AUTOSORT
            oRs:Close()
         else
            ? "Failed to open " + cTable
         endif
      endif
      oCn:Close()
   else
      ? "Connection Fail"
   endif

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: ADO: Listing tables from a database
Posted: Fri May 03, 2013 12:46 PM

Antonio

I like where you are going with ADO here ..

One thing that needs to be done is add the ability for a password to the connection string. Let me dig deeper and see if I can help.

Rick Lipkin

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: ADO: Listing tables from a database
Posted: Fri May 03, 2013 02:05 PM
Antonio

I am using fwh1303 and xHarbour .. Trying to compile and getting an error on EXECUTE .. I rem'd it out temporarily to get get a good build.

Rick Lipkin

Code (fw): Select all Collapse
DEFINE BUTTON OF oBar PROMPT "Run" RESOURCE "run" ACTION nil GROUP //Execute( ( cAlias )->Code )
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ADO: Listing tables from a database
Posted: Fri May 03, 2013 03:04 PM
Rick,

What compiling error do you get ? syntax error only ? There is no DEFINE BUTTON in my code

I really would appreciate your cooperation in adding ADO support to FWH FiveDBU.prg:
https://code.google.com/p/fivewin-contributions/downloads/detail?name=fivedbu_20130503_2.zip

We already open databases and tables, Add a record, and we get an error deleting one (the browse painting after it). Rao is also helping on this.

If we are able to provide all the required ADO functionality from FiveDBU I think that we will be providing a great help for users wanting to easily use ADO :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: ADO: Listing tables from a database
Posted: Fri May 03, 2013 03:17 PM
Antonio

Let me see what I can do with your code .. here is the line where my compile fails on Execute()

Rick Lipkin

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ADO: Listing tables from a database
Posted: Fri May 03, 2013 03:30 PM

Rick,

I am afraid that Execute() portion of FiveDBU will not work with xHarbour and we use the great Harbour capability to compile and execute from memory in runtime. I am going to review the syntax of that line.

We have just published an enhanced FiveDBU with Add and Delete from an ADO browse :-)

viewtopic.php?f=3t=26229p=144053#p144053

&&

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ADO: Listing tables from a database
Posted: Fri May 03, 2013 04:54 PM

Rick,

An enhanced version already published that supports editing:

viewtopic.php?p=144063#p144063

It compiles fine here with xHarbour, except that function Execute() has to be declared dummy. Maybe we will supply it by default.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: ADO: Listing tables from a database
Posted: Sun May 05, 2013 09:25 AM

Antonio,

As soon as you implement the option to define a connection-string, I will test it on MySQL/MariaDB & SQLite-databases.

I can't modify the program myself, since I still use an older version of FW (7.10) that is not able to compile the source.
With my old version I can use and browse MySQL & SQLite-database via ADO without any problem. That's the reason wy I didn't upgrade yet to a newer version. :)

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ADO: Listing tables from a database
Posted: Sun May 05, 2013 09:44 AM

Marc,

Could you email me the connection string ? I will build it for you and email it to you.

There were lots of OLE errors that have been fixed in the recent years, thats why I suggest you to upgrade and don't block yourself on an old version :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion