Bug in Harbour Descend()

User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by karinha »

Master Enrico, look this:

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

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by Enrico Maria Giordano »

Ok, thank you. I already use that workaround. I was hope that there is a better way.
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by Enrico Maria Giordano »

Please note that this is not working too:

Code: Select all | Expand

DESCEND( DTOS( dDate ) )


I can't believe that this bug has not been corrected yet... :-(
User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post 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


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

   USE Sales NEW
   INDEX ON Descend(OrdDate) TO SalesDate
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by Enrico Maria Giordano »

It doesn't work either. This works:

Code: Select all | Expand

DESCEND( dDate )


But this not:

Code: Select all | Expand

DESCEND( DTOS( dDate ) )


Please note that there is no problem at all with xHarbour.
User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by karinha »

? DESCEND( dDate ) // Esto me retorna un numero, está correcto?

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post 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.
User avatar
karinha
Posts: 7932
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by karinha »

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by Enrico Maria Giordano »

Thank you. It is not a real solution but better than nothing:

Code: Select all | Expand

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.
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: Bug in Harbour Descend()

Post 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


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
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by Enrico Maria Giordano »

It doesn't work, it creates a file with the wrong name. Please try this:

Code: Select all | Expand

#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
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: Bug in Harbour Descend()

Post 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

#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
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post 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. :-)
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: Bug in Harbour Descend()

Post 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



#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

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 3 times
Contact:

Re: Bug in Harbour Descend()

Post by Enrico Maria Giordano »

Sorry, it doesn't work:

Code: Select all | Expand

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


Result:

Code: Select all | Expand

.F.


:-(
Post Reply