Refreshing xbrowse when dataset is closed and re-opened

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Carles » Fri Jul 16, 2010 7:37 pm

James,

Can you tried to use OLE DB for ODBC Drivers ?

Image

In the conection folder u need select dBase files and especify the path. In this example i've got the exe in c:\test and customer.dbf in c:\temp\data

Image

Now, you can see the correct conection string if u need to use...

Image

And finally i execute this sentence "Select * from customer where age > 80 order by first"

Image
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1129
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby James Bott » Fri Jul 16, 2010 8:03 pm

Carles,

Yes, I did everything as you showed and I get the unknownName "open" error both with and without the WHERE clause.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Carles » Fri Jul 16, 2010 8:37 pm

James,

It's very strange, i don't know, i'm sorry :( .
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1129
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Armando » Sat Jul 17, 2010 2:09 am

nageswaragunupudi wrote:Yes, curiously oRs:Refresh() does not give any error, but this is no where officially documented and I am not sure what it does or does not do. I can be sure of what is documented by Microsoft and many other books on the subject.


Friends, pls review this link

http://msdn.microsoft.com/en-us/library ... 16(v=VS.85).aspx

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3201
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby nageswaragunupudi » Sat Jul 17, 2010 4:45 am

Armando wrote:
nageswaragunupudi wrote:Yes, curiously oRs:Refresh() does not give any error, but this is no where officially documented and I am not sure what it does or does not do. I can be sure of what is documented by Microsoft and many other books on the subject.


Friends, pls review this link

http://msdn.microsoft.com/en-us/library ... 16(v=VS.85).aspx

Regards

Clicking on the above link does not work. Those who want to see this page may please copy this link "http://msdn.microsoft.com/en-us/library/ms677516(v=VS.85).aspx" and paste in the address bar.

What this page lists are ADO methods, but not only those methods applicable to Recordset object. We all know for a long time that there is one Refresh method in ADO, but that applies to Collection Objects.

Sure there is a mention of Refresh method in this page. Please click on the "Refresh method" to go to the page where Refresh method is explained. To what this method applies to and what it does.

Clicking on Refresh method takes us to this page:
"http://msdn.microsoft.com/en-us/library/ms675046(v=VS.85).aspx".
In this page it is clearly explained that Refresh method applies to collections.

At the end of this page under "Applies To" section, it is clearly mentioned to what all collection objects the Refresh method applies and we all know this information all along.

This is the link to properties, methods and events of Recordset object:
"http://msdn.microsoft.com/en-us/library/ms675841(v=VS.85).aspx"

You will see that Refresh method is NOT documented here.
So, even if it does not error out, please do not use oRs:Refresh() and keep expecting that it does something what we in our minds like it to do.


So we come back to the original point. There is no documented method Refresh() for RecordSet object.
Regards

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

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby nageswaragunupudi » Sat Jul 17, 2010 5:43 pm

We have seen in the earlier post that Refresh method for Recordset is not documented.

Though oRs:Refresh() does not error out, this does not read data again from the table and refresh the recordset. I humbly advise my friends not to depend on oRs:Refresh() for this purpose.

Use oRs:Requery() instead. This reads all the data based on oRs:Source again from the database and refreshes data in the recordset.

Here is a sample program to show that oRs:Refresh() does not really read the data again.
Code: Select all  Expand view
#include 'fivewin.ch'
#include 'xbrowse.ch'

#define BS Chr(92)    // BackSlash
#define FWPATH "c:" + BS + "fwh" + BS + "samples" + BS

static oCn

function Main()

   local cStr   := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ;
                    FWPATH + "xbrtest.mdb;User Id=admin;Password=;"

   local cSql, oRs

   // Open Connection
   oCn   := TOleAuto():New( "ADODB.Connection" )
   oCn:Open( cStr )
   oCn:CursorLocation   := 3 // adUseClient

   // Open Recordset. Single record
   cSql  := 'SELECT SALARY FROM CUSTOMER WHERE FIRST = "Ali"'
   oRs   := TOleAuto():New( "ADODB.RecordSet" )
   oRs:Open( cSql, oCn )
   MsgInfo( oRs:Fields( 0 ):Value, 'SALARY' )  // 30800.00 in my case

   // Double the salary directly in the table ( Recordset does not know )
   cSql  := 'UPDATE CUSTOMER SET SALARY = 2 * SALARY WHERE FIRST = "Ali"'
   oCn:Execute( cSql )
   // Now the value in the table is 61600

   MsgInfo( oRs:Fields( 0 ):Value, 'AFTER UPDATE' ) // 30800, because recordset does not know the change

   oRs:Refresh()
   MsgInfo( oRs:Fields( 0 ):Value, 'AFTER REFRESH' ) // Still shows 30800.00 Refresh() did not read again
   oRs:ReQuery()
   MsgInfo( oRs:Fields( 0 ):Value, 'AFTER REQUERY' ) // Now shows 61800. Correct

   // Restore original value before exit
   cSql  := 'UPDATE CUSTOMER SET SALARY = SALARY / 2 WHERE FIRST = "Ali"'
   oCn:Execute( cSql )

   oRs:Close()
   oCn:Close()

return nil


There is also another method ReSync(). This method is much faster and has many options. But please use this with extreme caution. Not all providers support this method and even where supported it does not work as expected with all parameters on all kinds of recordsets in the same way.
Please thorougly test this method on the target databae before using. Not advised for cross RDMS programming.
Regards

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

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby James Bott » Sat Jul 17, 2010 8:44 pm

Rao,

In the original example showing oRS:Refresh(), even oRS:Requery() wasn't needed. It was right after the recordset was created.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby nageswaragunupudi » Thu Mar 22, 2018 3:06 am

This is better
Code: Select all  Expand view
WITH OBJECT oBrw
      :lScreenUpdating := .f.
      :oRs:Close()
      :oRs:Source := <revised SQL statement>
      :oRs:Open()
      :GoTop()
      :lScreenUpdating := .t.
      :Refresh()
   END
Regards

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

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 52 guests