FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Harbour OLE/ADO Backward Compatibility Issue
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Harbour OLE/ADO Backward Compatibility Issue
Posted: Tue Jan 30, 2018 03:39 AM
I was using Harbour 3.2.0dev (r1703231115) till recently and just now upgraded to the latest build Harbour 3.2.0dev (r1801051438). I noticed a major change in the manner array data is retrieved from Ole sources by TOleAuto, which may have impact on all libraries and software relying on this feature. In particular, this change affects

ADO RecordSet GetRows() --> aData
OLE Excel Range:Value() --> aData


xHarbour is consistent in its behavior from the time TOleAuto class was created till today. The behavior of Harbour's TOleAuto was also identical till recently. In other words, present Harbour version differs from xHarbour and all previous versions of Harbour.

GetRows()

Syntax: oRecordSet:GetRows( [rows], [start], [fields] ) --> aData

This is the fastest and simplest way to read data from a recordset into an array. Many existing software might be using this method and FWH library also uses this method.

Let us see the change using this sample program:
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oCn, oRs, aRows

   oCn   := FW_OpenAdoConnection( "c:\fwh\samples\xbrtest.mdb" )
   oRs   := FW_OpenRecordSet( oCn, "SELECT ID,FIRST,CITY FROM CUSTOMER WHERE ID < 6" )
   XBROWSER oRs TITLE "RecordSet"

   oRs:MoveFirst()
   aRows := oRs:GetRows()
   oRs:MoveFirst()

   XBROWSER aRows TITLE "oRs:GetRows() " + Version()

   oRs:Close()
   oCn:Close()

return nil

RecordSet:


Array from GetRows() with all versions of xHarbour and all previous versions of Harbour:


Array from GetRows() with the latest version of Harbour. (Different from xHarbour and all previous versions of Harbour)


aData := oRange:Value // Excel

For testing this sample, first please open Excel. Please fill data in top 3 rows and 2 columns in this way:


Range("A1:C3") is the used range.
In Visual Basic, if we assign Range.Value to an array the values of array are exactly like the values in the sheet, i.e.,
{ { "A1", "B1" },
{ "A2", "B2" },
{ "A3", "B3" } }
However (x)Harbour behaved differently from the beginning of TOleAuto class and was returning an array with transposed rows and columns like this:
{ { "A1", "A2", "A3" },
{ "B1", "B2", "B3 } }
For this reason, in all our (x)Harbour programs we transform the array after assining oRange:Value like this:
Code (fw): Select all Collapse
aData := oRange:Value
aData := ArrTranspose( aData )


Now let us see the change. Do not close Excel and keep it open on the desktop. Now execute this program:
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oRange, aData, n

   oRange   := GetExcelRange()
   if oRange == nil
      ? "Empty"
   else
      aData := oRange:Value
      xbrowser aData TITLE "oRange:Value " + Version()
      aData := ArrTranspose( aData )
      xbrowser aData TITLE "Transposed"
   endif

return nil


After "aData := oRange:Value"

All versions of xHarbour and all previous versions of Harbour:


Recent version of Harbour:

Obviously, Harbour fixed the transposed array issue in all previous versions, ignoring other side-effects and backward compatibility issues.


After "aData := ArrTranspose( aData )"

All versions of xHarbour and all previous versions of Harbour:


Recent version of Harbour:


Implications:
Only those who use Harbour and use ADO/Excel Ole, directly or indirectly using these methods, need to be concerned about this issue. Upgrading Harbour will produce erroneous results unless the application code is carefully modified.

Obviously, FWH team is working on this issue of making the library compatible with xHarbour and Harbour both old and revised versions.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Harbour OLE/ADO Backward Compatibility Issue
Posted: Tue Jan 30, 2018 09:38 AM
Possibly related to what's discussed here
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Harbour OLE/ADO Backward Compatibility Issue
Posted: Tue Jan 30, 2018 10:07 AM
can It influense the xls creation? One reason we migrated on libxlsx is that on some pc the creation did not works...

Code (fw): Select all Collapse
Error BASE/1005  Message not found: ARRAY:_MERGECELLS

=> __ERRRT_SBASE(0)
../../../tobject.prg => ARRAY:ERROR(0)
../../../tobject.prg => (b)HBOBJECT(0)
../../../tobject.prg => ARRAY:MSGNOTFOUND(0)
../../../tobject.prg => ARRAY:_MERGECELLS(0)
report.prg => TOEXCEL(2202)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Harbour OLE/ADO Backward Compatibility Issue
Posted: Tue Jan 30, 2018 10:20 AM
Mr AntonioP

I am still studying the impact.
Can you please let me know the version of Harbour you are using?
If you do the tests I posted above you will know if your version has the new behaviour or old.

In any case, if you can give me a sample where you are getting errors while creating xls, that would help me a lot in fixing any issues with our library.

Code (fw): Select all Collapse
WITH OBJECT ( oRng := oSheet:Range( oRange:Cells( nRow, 1 ), oRange:Cells( nRow, nMergeCols ) ) )
   :MergeCells := .t.

This is the line you are referring.
I will check and get back.
Regards



G. N. Rao.

Hyderabad, India
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Harbour OLE/ADO Backward Compatibility Issue
Posted: Tue Jan 30, 2018 11:41 AM

Hello,
we are using Harbour 3.2.0dev (r1708131853)
This error happened on a Windows Server 2008 64bit Service Pack 2 TS
I thought it depended on wich version of office is installed, in some computer it does not happen...

Posts: 174
Joined: Sat Feb 23, 2013 10:04 AM
Re: Harbour OLE/ADO Backward Compatibility Issue
Posted: Tue Jan 30, 2018 12:38 PM
My doubt,

Is this a relationed issue ?
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Harbour OLE/ADO Backward Compatibility Issue
Posted: Mon Feb 12, 2018 11:25 PM
In FWH 1801, we added 2 new functions

xlRangeValue( oRange ) --> aValue
RsGetRows( oRs ) --> aRows


These functions check the version of Harbour and decide on use of array transpose depending on the version.

aValue := xlRangeValue( oRange )
instead of
aValue := oRange:Value
aValue := ArrTranspose( aValue )

and

aData := RsGetRows( oRs )
may be used instead of
aData := oRs:GetRows()
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion