CODEPAGE ITWIN and DESCEND, strange ......

103 views
Skip to first unread message

Franz

unread,
Apr 8, 2014, 3:34:07 AM4/8/14
to harbou...@googlegroups.com
Hello,
I have a dbf index on "descend(dtos(DATAX))".
It works fine if I don't set codepage, if I set codepage to ITWIN order is not correct.
Why descend is affected by codepage in this case ? dtos return a 10 char string with only number.
See my little sample


function main

   set autopen on
   set date italian

   cls
   YES = "S"
   @ 00,00 Say "Set codepage to ITWIN ? " get YES pict "!" valid YES$("SN")
   read

   if YES = "S"
        
           request HB_CODEPAGE_ITWIN
           hb_setcodepage("ITWIN")

   endif

   request DBFCDX

   crea_db()
   fill_db()

   dbedit(5,5,20,70,{'DATAX','dtos(DATAX)'})

   return nil

function crea_db
  Local aDbf := {}
  AADD (aDbf,{"Datax"      , "D",  8,0})
  dbcreate( "Test", aDbf, 'DBFCDX' )
  aDbf := {}
  use TEST
  index on descend(dtos(TEST->DATAX)) to TEST
  return Nil

function fill_db
   local x
   for x := 1 to 100
      sele test
      append blank
      replace DATAX with date()+x
   next i
   return Nil

José Quintas

unread,
Apr 8, 2014, 9:23:59 AM4/8/14
to harbou...@googlegroups.com
I create a alternative Descend for codepage.

FUNCTION CPDescend( cText )
   LOCAL cResult, acAscii := {}, nCont
   STATIC cFrom, cTo
   IF cFrom == NIL .OR. cTo == NIL
      FOR nCont = 1 TO 255
         Aadd( acAscii, Chr( nCont ) )
      NEXT
      ASort( acAscii )
      cFrom := cTo := ""
      FOR nCont = 1 TO 255
         cFrom += acAscii[ nCont ]
         cTo   += acAscii[ 256 - nCont ]
      NEXT
   ENDIF
   cResult := hb_StrReplace( cText, cFrom, cTo )
   RETURN cResult

José M. C. Quintas
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Przemyslaw Czerpak

unread,
Apr 8, 2014, 9:45:24 AM4/8/14
to harbou...@googlegroups.com
On Tue, 08 Apr 2014, Franz wrote:

Hi,

> Hello,
> I have a dbf index on "descend(dtos(DATAX))".
> It works fine if I don't set codepage, if I set codepage to ITWIN order is
> not correct.

DESCEND() function is designed to operate on binary (BYTE) sorting
and gives reverted collation order only for codepages which use
such collation.

> Why descend is affected by codepage in this case ? dtos return a 10 char
> string with only number.

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.

best regards,
Przemek

Franz

unread,
Apr 8, 2014, 9:54:43 AM4/8/14
to harbou...@googlegroups.com
Thanks José and Przemek 
I have tryed José function and I found that it works in this condition. I will check other istances in my prg.
Ciao
Franz
Reply all
Reply to author
Forward
0 new messages