FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TRecSet class : FWH 14.07
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
TRecSet class : FWH 14.07
Posted: Tue Jul 29, 2014 02:52 PM
FWH 14.07 introduces a new class TRecSet, which is basically a wrapper class for Ado Recordset object. This class works in a similar way as TDatabase class works with DBF.
All datas and methods of ADO RecordSet class can be used and is compatible with the existing code written using OleAuto RecordSet object.
This class also provides datas and methods similar to TDatabase, making it convenient to migrate from DBF to ADO by using TRecSet class in place of TDatabase class.

Purpose of this class are:
(1) To simplify coding with ADO recordsets to improve productivity.
(2) Provide familar methods like GoTop(), GoTo() etc for DBF users
(3) Ease migration from DBF to ADO for programmers who are already using TDatabase like classes.

Instantiation:
Code (fw): Select all Collapse
oRs := TRecSet():New()
oRs := TRecSet():New( oRs )
oRs := TRecSet():New( nil, source, actconn, cursortype, locktype, opt )


Normal Usage, similar to the standard way:
Code (fw): Select all Collapse
oRs := TRecSet():New()
// Instead of oRs := TOleAuto():New( "ADODB.RecordSet" )
// Optionally set some data
WITH OBJECT oRs
   :Source = <...>
   <... etc ...>
END

oRs:Open( source,actconn,cursortyp,locktyp,opt ) // Exactly like ADO recordset

// All the code used with ADO Recordset works equally with the TRecSet object

We can also open recordset in a single statement
Code (fw): Select all Collapse
oRs := TRecSet():New():Open( <params >


For programs already written using standard RecordSet object opened with TOleAuto(), we can either
(a) Replace TOleAuto():New( "ADODB.RecordSet" ) with oRs := TRecSet():New()
OR
(b) oRs := TOleAuto():New( "ADODB.RecordSet )
oRs := TRecSet():New( oRs )

Using with already created RecordSet
Code (fw): Select all Collapse
oRs := oCn:OpenSchema( <id> )
oRs := TRecSet():New( oRs )
//[OR]
oRs := TRecSet():New( oCn:OpenSchema( <id> ) )


In programs where FW_OpenRecordSet(...) is used for opening recordsets, please replace FW_OpenRecordSet(...) with FW_OpenTRecSet(...), retaining the same parameters.

Using compatible with TDataBase
Code (fw): Select all Collapse
oRs := TRecSet():New( nil, cTable, oConnection/cStr, cusortype, locktype, options )
if oRs:Used()
   // succcess
else
   // failure
endif

We can continue to use GoTop() etc methods same way as in TDatabase.

How does this class simplify some programming work:

We can refer to fields as datas same way as we do in TDatabase.
Eg:
? oRs:Age
oRs:Age += 5
oRs:Save()

We can also use familiar fieldget, etc.
oRs:FieldGet( "Salary" )
oRs:FieldPut( "Salary", 40000 )

While using field names containing blanks, we can replace blanks with underscore. Example:
Where a field name is "Sale Price",
? oRs:Sale_Price
? oRs:FieldGet( "Sale_Price" )
? oRs:FieldGet( "Sale Price" )
all the above can be used.

oRs:Fields( "Age" ):Value also works but the above code is a lot simpler.

In addition we can even use Expressions in FieldGet()
Example:
? oRs:FieldGet( "Quantity * Price" )
Using standard syntax we had to write
? oRs:Fields( "Quantity" ):Value * oRs:Fields( "Price" ):Value.

We are aware that we can not use some methods like oRs:MoveFirst(), etc on an empty recordset. This class simplifies this by doing the error checking and we can now use oRs:MoveFirst(), etc. without worrying about whether the recordset is empty or not.

We can also query the values of fields of an empty recordset. Now we can and the result is a blank value compatible to the field type.

We welcome users to try the class and offer suggestions for improvments and most importantly bug-reports are the most welcome. We endeavour to attend to any bug reports as immediately as possible.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: TRecSet class : FWH 14.07
Posted: Tue Jul 29, 2014 03:19 PM

thanks rao, I can not wait :-)

salu2
carlos vargas

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 195
Joined: Sun Jul 22, 2012 07:01 PM
Re: TRecSet class : FWH 14.07
Posted: Tue Jul 29, 2014 06:04 PM

Rao,

All of the data for my apps is from a remote database connection. I always get an array back, where the first row of that array contains the field names, the rest of the rows with the result set (think sqlite). I use the first row to lookup and set xbrowse display particulars, then delete that record and just do a :SetArray() with the remainder. Is there a way to use this data with ADO and/or this new TRecSet() class?

Robb

Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: TRecSet class : FWH 14.07
Posted: Tue Jul 29, 2014 06:20 PM

Rao,

I"m looking forward to working with this. It would be very helpful if there were a complete sample .prg included in the distribution.

I have converted over 100 dbf files into an SQL database. All of my code is written using tData. I have a version created with Visual Studio 2013, Harbour, FWH. This is the one I will be modifying to use with SQL. It is a large project but hopefully this new capability would make it easier to do the shift.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: TRecSet class : FWH 14.07
Posted: Tue Jul 29, 2014 07:09 PM

Mr. G.N. Rao:

Thanks a lot.

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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TRecSet class : FWH 14.07
Posted: Wed Jul 30, 2014 12:54 AM
rhlawek wrote:Rao,

All of the data for my apps is from a remote database connection. I always get an array back, where the first row of that array contains the field names, the rest of the rows with the result set (think sqlite). I use the first row to lookup and set xbrowse display particulars, then delete that record and just do a :SetArray() with the remainder. Is there a way to use this data with ADO and/or this new TRecSet() class?

Robb

Using SQLite, we can open RecordSets also.

oCn := FW_OpenAdoConnection( cConnString )

oRs := TRecSet():New():Open( "SELECT * FROM CUSTOMER", oCn )
XBROWSER oRs

If you intend to continue retrieving data as array, you can do so.
aHead := aData[ 1 ]
ADel( aData, 1, .t. )

@ 0,0 XBROWSE oBrw DATASOURCE aData AUTOCOLS HEADERS aHead ...
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: TRecSet class : FWH 14.07
Posted: Wed Jul 30, 2014 01:08 AM

Mr Tim

I remember you are using Microsoft Sql Server.
We have a new function for importing data from DBF in FWH14.07.

MSSQL_BulkImportDBF(...)

This function should import atleast 10 times faster than the generic FW_AdoImportFromDBF(). We shall be glad if you can test and provide your feedback.

Please also try TRecSet() and offer your suggestions how to make it more compatible with TData/TDatabase.

There are many differences between working with DBF and working with SQL databases. Despite all the tools available and what we provide, migration does involve a lot of work. We would be glad to support through these forums.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion