Page 1 of 1

XBrowse : Switching datasources at runtime

PostPosted: Tue Feb 12, 2019 8:52 am
by nageswaragunupudi
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

Re: XBrowse : Switching datasources at runtime

PostPosted: Tue Feb 12, 2019 9:51 am
by ukoenig
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 :?:

Re: XBrowse : Switching datasources at runtime

PostPosted: Tue Feb 12, 2019 10:09 am
by nageswaragunupudi
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.

Re: XBrowse : Switching datasources at runtime

PostPosted: Tue Feb 12, 2019 11:38 am
by ukoenig
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