FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FUNNY Indexing
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
FUNNY Indexing
Posted: Sun Jan 22, 2012 11:35 AM

Hi to all
This is example program:

include "FiveWin.ch"

//----------------------------------------------------------------------------//
function Main()
local i := 0
local aData := {"11","9","9999999999","99999999999","11111111111" }
DbCreate( "MyDbf.dbf", { { "Field1", "C", 13, 0 } } )
USE MyDbf
FOR i = 1 TO LEN( aData)
DbAppend()
REPLACE Field1 WITH aData[ i ]
NEXT
INDEX ON VAL(MyDbf->Field1) TO MyIndex
XBROWSE()
return nil

DATA ARE ORDERED LIKE THIS:
99999999999
11111111111
9
11
9999999999

Best Regards

:)

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: FUNNY Indexing
Posted: Sun Jan 22, 2012 02:13 PM
Code (fw): Select all Collapse
INDEX ON STR(VAL(MyDbf->Field1),LEN(MyDbf->Field1)) TO MyIndex


Please note:

1. This is standard Clipper behavior (I just tested with Clipper 5.3b).

2. This is not a problem with FWH.

EMG
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: FUNNY Indexing
Posted: Sun Jan 22, 2012 06:00 PM
Avista

Code (fw): Select all Collapse
INDEX ON VAL(MyDbf->Field1) TO MyIndex


Try eliminating the database name in the index ..

Code (fw): Select all Collapse
Select MyDbf
INDEX ON VAL(Field1) TO MyIndex


Rick Lipkin
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: FUNNY Indexing
Posted: Sun Jan 22, 2012 06:11 PM

The problem is the val() function does not return a fixed length and the index needs to be fixed length.
Like Enrico's example, you should convert it to a fixed length string.

Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 09:55 AM
Hi,

INDEX ON STR(VAL(MyDbf->Field1),LEN(MyDbf->Field1)) TO MyIndex

Yes this is going well ....

Enrico ...this is problem in FWH too if you use NTX index ...with CDX there is no problem.

Thanks to all,
Best regards,
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 01:10 PM

avista
> this is problem in FWH too if you use NTX index ...with CDX there is no problem.
enrico
>1. This is standard Clipper behavior (I just tested with Clipper 5.3b).
It's standard but it's wrong and very dangerous!

bye

marco

Marco Boschi
info@marcoboschi.it
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 02:35 PM

I repeat: it's not a problem with FWH. Please report it to comp.lang.xharbour.

EMG

Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 03:56 PM

Hi,

I never use numeric keys.
1st) In dates do not obtain good order; it's necessary dtos()
2st) Numerics do not permit add subkeys field1+ field2

I allways use character key expressions, are more controllables (length key) y expansives (subkeys)

Regards

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 04:03 PM

I used dates as index key sometimes and never find any problems.

EMG

Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 04:34 PM

emg,

dates aren't good keys

INDEX ON Date1 TO FileOrder // obtain wrong order:
...
23/01/2011
23/01/2012
23/01/2013
24/01/2011
24/01/2012
24/01/2013
...

INDEX on DToS(Date1) TO FileOrder // obtain right order:
...
2011/23/01
2011/24/01
2012/23/01
2012/24/01
2013/23/01
2013/24/01
...

Regards

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 04:51 PM

Please post a complete sample showing the problem.

EMG

Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 05:27 PM

I dont understand; there is no problem; i haven´t problem. I only say: date expression do not keep year+month+day natural order and consequently they are very bad order key.That's all.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 06:41 PM
But since I already used (as I said) dates as index key without any problems then I can't confirm the behavior you reported. So I need a sample showing that behavior. The following sample works fine for me:

Code (fw): Select all Collapse
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local i := 0
local aData
SET DATE BRITISH
aData = {CTOD( "23/01/2011" ), CTOD( "24/01/2011" ), CTOD( "23/01/2012" ), CTOD( "24/01/2012" ), CTOD( "23/01/2013" ), CTOD( "24/01/2013" ) }
DbCreate( "MyDbf.dbf", { { "Field1", "D", 8, 0 } } )
USE MyDbf
FOR i = 1 TO LEN( aData)
DbAppend()
REPLACE Field1 WITH aData[ i ]
NEXT
INDEX ON MyDbf->Field1 TO MyIndex
XBROWSE()
return nil


EMG
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 06:55 PM

Enrico,

You are right. I was thinking in

INDEX ON DToC(Date1) TO TmpFile

DToC() function return bad order expression key

INDEX ON Date1 TO TmpFile is ok; my fault; I´m sorry :(

Regards

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: FUNNY Indexing
Posted: Mon Jan 23, 2012 06:58 PM

No problem at all, my friend.

EMG

Continue the discussion