FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FWH: MySql/MariaDB: RowSet object
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Sat Dec 17, 2016 06:41 PM

Very nice !

Thank you for the changes. Learning a lot with this. Have become a nice sample!

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Sun Dec 18, 2016 02:51 AM
Adolfo wrote:Mr Rao.

Is there something like oRowset:GetBlankRow() as in tDolphin, which I found quite easy to create a blank or default set of values for the current table to fiil with new values an insert it into the table.

Regards

From Chile
Adolfo


May we know what version of FWH are you using?
Regards



G. N. Rao.

Hyderabad, India
Posts: 302
Joined: Fri Apr 23, 2010 04:30 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Fri Dec 23, 2016 05:03 AM

Hello,

Is there a method similar to dolphin SetWere to change where condition in query result ? i don't how Rowset and requery works.

Example in Tdolphin

oQry:= oServer:Query("Select * from customers") // All customers

oQry:SetWhere("sate='NY'") //Only NY State

oQry:SetWhere("") // All customers again reset where

Regards,

Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Fri Dec 23, 2016 08:19 AM
To Read all customers
Code (fw): Select all Collapse
oRs := oCn:RowSet( "select * from customer" )
// or
oRs := oCn:RowSet( "customer" )
// or
oRs := oCn:Customer  // fwh16.12


Instead of oQry:SetWhere( "state='NY'" ):
Note: SetWhere() reads the data again from the server and this places burden on the server and network traffic.
You may use:
Code (fw): Select all Collapse
oRs:SetFilter( "state='NY'" )
// or
oRs:SetFilter( "state='WA' .and. age > 30" )
? oRs:cFilter  // to know present filter
oRs:SetFilter( "" ) // Clear filter


Filter condition is similar to the usual DBF filter condtion.
SetFilter() does not read data again from the server. Works even when server is disconnected.

Changing Sort order:
Code (fw): Select all Collapse
oRs:SetOrder( "age" )
// or
oRs:Sort := "age"
//
? oRs:Sort  // to know the present sort order

This sorts the data of the rowset in the client pc' memory. Data is not read again from the server.

Just like we can use parameters while reading rowset, we can also use paramters for setting filters.

Example:
Code (fw): Select all Collapse
oRs:SetFilter( "state = ?", { "NY" } )  // same as "state = 'NY'"
// later change the filter to another state
oRs:ReFilter( { "WA" } ) // same effect as "state = 'WA'"
Regards



G. N. Rao.

Hyderabad, India
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Mon Apr 24, 2017 02:28 PM

Nages.

I have a doubt, how can you do you the following in FWHMARIA.
I have a big xbrowse routine which captures key strokes, functions keys and a personalized popup menu that calls functions for appending, modifying, deleting, listing etc.
I have a large clients table, but in a xbrowse I just show 4 fields out of 20+, in tDolphin, I have an extra dialog, a big one with lot of validations items, after that I save modifications and do:

       oDbCli:LoadQuery(.F.)
       oBrw:DrawLine()

and only the current line in xBrowse is altered and updated.
When appending new records, I do the same, call another extra dialog, its different from the one used for modifying data, after saving I do:

       oDbCli:Refresh(.F.)
       oBrw:DrawLine()

and the new record is shown in the xbrowse in the place it is supposed to be (acording to key order)

You advice us to use oDbCli:bEdit, and oBrw:EditSource( .t. ), but I prefer a more (complex) controlled way because I have permissions on appending, modifying, which are different for every user.

How can I do the refreshing of the data shown in the xBrowsethe same way I do it with tDolphin.

Regards.
From Chile, Adolfo

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 36
Joined: Sat Sep 03, 2016 03:11 PM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Mon Apr 24, 2017 08:01 PM

Mr.Rao

oRs:SetOrder( "age" )
// or
oRs:Sort := "age"
//
? oRs:Sort // to know the present sort order

Is it possible to sort by more than one column?

example :

oRs:SetOrder( "age,date,id,..." )
// or
oRs:Sort := "age,date,id,..."
//
? oRs:Sort // to know the present sort order

Att

Joao Carlos
VinheSoft

João Carlos

VinheSoft Informatica

BCC 7.7 - FHW 24.07 - Harbour 3.2.0dev (r2404101339) for BCC 7.7
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Tue Apr 25, 2017 02:59 PM
oRs:SetOrder( "age,date,id,..." )
// or
oRs:Sort := "age,date,id,..."
//

Multiple column sorting is provided in FWH 17.04.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Wed Apr 26, 2017 07:21 AM
Mr Adolfo

I have a large clients table, but in a xbrowse I just show 4 fields out of 20+,

Can you please clarify whether (a) you read all 20+ fields in the query but display only 4 fields in the xbrowse or (b) you read only 4 fields in the query, display these 4 fields in the xbrowse, but you want to edit all of some of 20+ fields of the table in your edit dialogs?
Regards



G. N. Rao.

Hyderabad, India
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Wed Apr 26, 2017 11:58 AM

Hi Nages.

Yes, I only show 4 out of 20+ fields, the others are loaded in a personalized dialog when you want to see, edit, modify the record, mainly because there are a lot of validations in some fields and not every user has privileges to edit some of them.

I use this approach with almost all the tables in a big ERP, just the auxiliary tables like cities, Tipe of taxes, discount % etc have 2 or 3 fields which can be easily modified inside the xbrowse.

Regards, from Chile
Adolfo

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Wed Apr 26, 2017 12:01 PM
I only show 4 out of 20+ fields,

My question is in the "SELECT" query
do you SELECT * FROM table
or
do you SELECT fld1,fld2,fld3,fld4 FROM table?
Regards



G. N. Rao.

Hyderabad, India
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Wed Apr 26, 2017 12:37 PM

Select f1,f2,f3,f4 from clients

f1 anf f2 are Keys (unique both)

When I load the whole Record, I also load relations with other tables, history sales or payments records etc.

Thanks in advance.

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Wed Apr 26, 2017 04:57 PM
Mr Adolfo

Both LoadQuery() and Refresh() of TDolphin are equivalent to oRs:Requery() of RowSet. These methods read and load the entire table again from the server and we like to avoid it as far as possible.

RowSet:ReSync() reads only one record from the server and updates the rowset. This is fast.

After modifying the record
With Dolphin
Code (fw): Select all Collapse
oDbCli:LoadQuery(.F.)
oBrw:DrawLine()


Suggested with RowSet: Ensure that the modified record is the selected record in the browse and call
Code (fw): Select all Collapse
oRs:Resync()
oBrw:RefreshCurrent() // same as oBrw:DrawLine()


After inserting a new record.
With Dolphin
Code (fw): Select all Collapse
oDbCli:Refresh(.F.)
oBrw:DrawLine()


Till FWH17.03, we can not use Resync to read external appends. Only way is to use oRs:Requery() which is same functionally as oQry:Refresh().
Code (fw): Select all Collapse
oRs:ReQuery()
// position the record on the just appended record
oRs:Refresh()


From FWH17.04:

The new method oRs:ReSyncWhere( cWhere ) is ideal for refreshing external modifications/appends.

Call
oRs:ReSyncWhere( "<primary/Uniquekey> = <value>" )
or
oRs:ReSyncWhere( "<primary/uniquekey>", uValue )
and oBrw:RefreshCurrent()

If the primary/unique key with the value already exists in the rowset, the record pointer is moved to the record and values of the record are re-read from the server.

if the primary/unique key with the value is not found in the rowset, the values of that row are read from the server and appended to the rowset in memory and record pointer is moved to the newly appended record.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Thu Apr 27, 2017 01:35 PM

Mr Adolfo

Please also see the new sample posted about oBrw:EditBaseRecord()
You may consider if it can be useful to you.

Regards



G. N. Rao.

Hyderabad, India
Posts: 43
Joined: Fri Jun 01, 2007 12:41 PM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Fri May 12, 2017 02:54 PM

HOW TO MAKE ?

IN TDOLPHIN
oQry := TDolphinQry():New("select * from country ", oServer )
oQry:setWhere("name like '%REPLUBLICA%'",.T.) // QUERY RESULT -> select * from country where name like '%REPLUBLICA%

to clean
oQry:setWhere("",.T.) // QUERY RESULT -> select * from country

IN TMARIADB ????

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH: MySql/MariaDB: RowSet object
Posted: Fri May 12, 2017 03:24 PM

Method 1

oRs := oCn:RowSet( "SELECT * FROM country WHERE NAME LIKE ?", { "%REPLUBLICA%" } )
Later
oRs:Requery( { "%OTHERNAME%" } )

Method 2

oRs := oCn:RowSet( "SELECT * FROM country ?", { "" } )
Later
oRs:ReQuery( { "WHERE name like '%REPLUBICA%' } )
Later
oRs:ReQuery( { "" } )
Later
oRs:ReQuery( { "WHERE age > 40" } )

Regards



G. N. Rao.

Hyderabad, India