XBrowse : Switching datasources at runtime

XBrowse : Switching datasources at runtime

Postby nageswaragunupudi » Tue Feb 12, 2019 8:52 am

It has always been possible to swap datasource of Xbrowse from dbf to dbf, recordset to another recordset, etc., while XBrowse is running, provided that they are of the same type and column settings are the same.

From version FWH 18.05, it is possible to switch datasource from any type and any type and also reconfigure the columns.

It is possible to switch datasources within DBF, TDatabase, ADO, MariaDB Rowset, Dolphin/TMySql Query and PostGre Query. It is not possible to switch with other datasources like arrays, objects, etc.

Syntax:
Code: Select all  Expand view

oBrw:ResetData( [newDataSource], [aCols] )
// Atlease one parameter should be specified
 


oBrw:ResetData( nil, aCols ) // Reconfigures columns for the existing datasource
oBrw:ResetData( newData ) // Switches to new datasource with all columns
oBrw:ResetData( newData, aCols ) // switches to new datasource with new column setup.

The following sample demonstrates switching of datasources between DBF, TDatabase, ADO RecordSet and MariaDB RowSet. We can also add TDolphin/TMySql/PostGre query.
Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oDlg, oBrw
   local oDbf, oAdo, oRecSet, oMaria, oRowSet

   SET DELETED ON

   // OPEN TABLES

   USE CLIENTES NEW ALIAS CLI SHARED VIA "DBFCDX"

   oDbf     := TDataBase():Open( , "STATES", "DBFCDX", .t. )

   oAdo     := FW_OpenAdoConnection( "xbrtest.mdb" )
   oRecSet  := FW_OpenRecordSet( oAdo, "select * from customer" )

   oMaria   := FW_DemoDB()
   oRowSet  := oMaria:RowSet( "select * from states" )

   // CREATE DIALOG AND BROWSE

   DEFINE DIALOG oDlg SIZE 800,500 PIXEL TRUEPIXEL

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "CLI" AUTOCOLS ;
      CELL LINES NOBORDER FOOTERS FASTEDIT

   oBrw:CreateFromCode()

   // BUTTONS TO SWAP TABLES

   @ 10, 20 BTNBMP PROMPT "DBF"        SIZE 90,40 PIXEL OF oDlg FLAT ;
            ACTION oBrw:ResetData( "CLI" )

   @ 10,120 BTNBMP PROMPT "TDATABASE"  SIZE 90,40 PIXEL OF oDlg FLAT ;
            ACTION oBrw:ResetData( oDbf, { "Code", "Name" } )

   @ 10,220 BTNBMP PROMPT "ADO"        SIZE 90,40 PIXEL OF oDlg FLAT ;
            ACTION oBrw:ResetData( oRecSet, { "FIRST", "CITY", "STATE", "SALARY" } )

   @ 10,320 BTNBMP PROMPT "MARIADB"    SIZE 90,40 PIXEL OF oDlg FLAT ;
            ACTION oBrw:ResetData( oRowSet )


   ACTIVATE DIALOG oDlg CENTERED

   // CLOSE TABLES

   oRecSet:Close()
   oAdo:Close()

   oRowSet:Close()
   oMaria:Close()

   oDbf:Close()

   CLOSE CLI

return nil
 


Image
Regards

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

Re: XBrowse : Switching datasources at runtime

Postby ukoenig » Tue Feb 12, 2019 9:51 am

Mr. Rao,

I wanted to add Your sample to my collection but getting
errors of all < mysql_ > like

Image

do I have to link something more :?:

regards
Uwe :?:
Last edited by ukoenig on Tue Feb 12, 2019 11:37 am, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: XBrowse : Switching datasources at runtime

Postby nageswaragunupudi » Tue Feb 12, 2019 10:09 am

Whenever you get such problems you refer to buildx.bat and buildh.bat
All my samples link well if you copy them to samples folder and build with any build*.bat.

First, build and test them and then port the code to your application.

Yes, you need to link with fwh\lib\libmysql.lib
and
you should copy \fwh\dll\libmysql.dll to your exe path.
Regards

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

Re: XBrowse : Switching datasources at runtime

Postby ukoenig » Tue Feb 12, 2019 11:38 am

Thank You very much

works perfect and is added to the collection.

Image

test 2 is included as well
viewtopic.php?f=3&t=36733

Image

regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 62 guests