Page 2 of 3

Re: Bug in Harbour Descend()

PostPosted: Mon Oct 17, 2022 2:19 pm
by karinha
Master Enrico, look this:

http://www.pctoledo.com.br/forum/viewtopic.php?f=4&t=19895

Regards, saludos.

Re: Bug in Harbour Descend()

PostPosted: Mon Oct 17, 2022 2:50 pm
by Enrico Maria Giordano
Ok, thank you. I already use that workaround. I was hope that there is a better way.

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 3:23 pm
by Enrico Maria Giordano
Please note that this is not working too:

Code: Select all  Expand view
DESCEND( DTOS( dDate ) )


I can't believe that this bug has not been corrected yet... :-(

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 5:05 pm
by karinha
Master Enrico, I'm not sure, but I think you have to save the DATES, in a Database first. Just an idea.

Maestro Enrico, no estoy seguro, pero creo que primero debe guardar las FECHAS en una base de datos. Solo una idea.

Example / ejemplo:

Code: Select all  Expand view

    USE Sales NEW
    INDEX ON Str(Descend(SaleDate)) + Salesman TO LastSale
OR

   USE Sales NEW
   INDEX ON Descend(OrdDate) TO SalesDate
 


Regards, saludos.

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 5:16 pm
by Enrico Maria Giordano
It doesn't work either. This works:

Code: Select all  Expand view
DESCEND( dDate )


But this not:

Code: Select all  Expand view
DESCEND( DTOS( dDate ) )


Please note that there is no problem at all with xHarbour.

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 5:36 pm
by karinha
? DESCEND( dDate ) // Esto me retorna un numero, está correcto?

Regards, saludos.

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 5:42 pm
by Enrico Maria Giordano
Yes, that's right. The problem is there when you want to combine dates and other data types. In this case you have to convert the dates to strings and here the codepage breaks the sort order of the descending string.

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 5:45 pm
by karinha

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 6:04 pm
by Enrico Maria Giordano
Thank you. It is not a real solution but better than nothing:

Code: Select all  Expand view
DESCEND( STR( nVal ) ) => STR( 999999999999999 - nVal )
DESCEND( DTOS( dVal ) ) => STR( DESCEND( dVal ) )


Let's hope that Harbour developers will fix the bug, one day or another...

My concern is that Descend() could be called millions of times during a sort. So it should be as faster as possible.

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 6:23 pm
by cnavarro
From Harbour-users group
DESCEND() function is designed to operate on binary (BYTE) sorting
and gives reverted collation order only for codepages which use
such collation.

Because DESCEND() converts numbers to characters which have
special order in CP you are using. Look at this list archive
for some easy to create custom DESCEND() replacements which
can be used with non accented Latin based languages like
Lithuanian or Polish ones.


Dear Enrico
Please try with this. I hope you find this codepage useful
Code: Select all  Expand view

REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN, HB_CODEPAGE_IT850

HB_CDPSELECT( "IT850" )
hb_langSelect( 'IT' )
// hb_SetTermCP( 'ITWIN', 'ITWIN', .T. )   // Also with it run ok
 

Re: Bug in Harbour Descend()

PostPosted: Tue Oct 18, 2022 9:24 pm
by Enrico Maria Giordano
It doesn't work, it creates a file with the wrong name. Please try this:

Code: Select all  Expand view
#include "Fivewin.ch"


REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN, HB_CODEPAGE_IT850


FUNCTION MAIN()

    HB_CDPSELECT( "IT850" )
    HB_LANGSELECT( "IT" )

    HB_SETTERMCP( "ITWIN", "ITWIN", .T. )

    MEMOWRIT( "àèéìòù.txt", "àèéìòù" )

    RETURN NIL

Re: Bug in Harbour Descend()

PostPosted: Wed Oct 19, 2022 12:52 am
by cnavarro
Enrico Maria Giordano wrote:It doesn't work, it creates a file with the wrong name. Please try this:

Code: Select all  Expand view
#include "Fivewin.ch"


REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN, HB_CODEPAGE_IT850


FUNCTION MAIN()

    HB_CDPSELECT( "IT850" )
    HB_LANGSELECT( "IT" )

    HB_SETTERMCP( "ITWIN", "ITWIN", .T. )

    MEMOWRIT( "àèéìòù.txt", "àèéìòù" )

    RETURN NIL


Sorry Enrico, but the example you put now has nothing to do with the Descend() function
Has the example I posted worked?
I will look at the new example you propose and I will answer you

Re: Bug in Harbour Descend()

PostPosted: Wed Oct 19, 2022 7:52 am
by Enrico Maria Giordano
The problem is: without any codepage settings (ie. EN codepage) Descend() is fine but accented chars from filesystem are wrong. With ITWIN (or other codepages I tried) the accented chars from filesystem are right but Descend() is not working.

Any solutions will make me happy. :-)

Re: Bug in Harbour Descend()

PostPosted: Wed Oct 19, 2022 8:06 am
by cnavarro
Enrico Maria Giordano wrote:The problem is: without any codepage settings (ie. EN codepage) Descend() is fine but accented chars from filesystem are wrong. With ITWIN (or other codepages I tried) the accented chars from filesystem are right but Descend() is not working.

Any solutions will make me happy. :-)


This is more simple

Code: Select all  Expand view


#include "Fivewin.ch"

FUNCTION MAIN()

    LOCAL aData[ 7 ]

    LOCAL i


    HB_SETCODEPAGE( "UTF8" )

    aData[ 1 ] = { "TEST1", 3107.77 }
    aData[ 2 ] = { "TEST2", 852.07 }
    aData[ 3 ] = { "TEST3", 191.00 }
    aData[ 4 ] = { "TEST4", 148.68 }
    aData[ 5 ] = { "TEST5", 44.73 }
    aData[ 6 ] = { "TEST6", 15.24 }
    aData[ 7 ] = { "TEST7", 255.65 }

    ASORT( aData, , , { | aItem1, aItem2 | Descend( Str( aItem1[ 2 ], 10, 2 ) ) + aItem1[ 1 ] < Descend( Str( aItem2[ 2 ], 10, 2 ) ) + aItem2[ 1 ] } )

    xBrowse( aData )

    hb_MemoWrit( "àèéìòù.txt", "àèéìòù" )


    RETURN NIL

 

Re: Bug in Harbour Descend()

PostPosted: Wed Oct 19, 2022 8:26 am
by Enrico Maria Giordano
Sorry, it doesn't work:

Code: Select all  Expand view
? hb_MemoWrit( "àèéìòù.txt", "àèéìòù" )


Result:

Code: Select all  Expand view
.F.


:-(