Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Find record position in an indexed table
Message
De
24/08/2006 19:38:49
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
24/08/2006 18:26:34
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01148310
Message ID:
01148420
Vues:
22
>>>>>>Hello,
>>>>>>
>>>>>> How to find the position of a record in an indexed table.
>>>>>>RECNO() will give the position of the record in the table but how to find the position in an indexed table.
>>>>>>
>>>>>>TIA
>>>>>
>>>>>For Versions of VFP previous to 9, if the table is small (under 65,000 rows), you could do a SQL SELECT of the primary keys into an array in the order of the index key. Then do an ASCAN to find your primary key. The element of the array would be the indexed order.
>>>>
>>>>Fred! That's brilliant!
>>>>
>>>
>>>Sure ?
>>
>>It is a great concept.
>>
>
>no, it is useless.

You and Fred are doing the same concept in different ways. Different implementation. Your implementation may be better, but the concept is the same.

>
>>>ASCAN is equal to a ordered count
>>
>>Yes.
>
>
>>
>>>
>>>>You could expand that to a cursor! select pk order by indexkey. locate for pk = m.pk
>>>>
>>>
>>>If you want gain something:
>>>
>>>SELECT pk from table order by 1 ...
>>>INDEX ON pk tag tagpos && without this, the locate is equal to the ordered count, again
>>>SEEK m.pk
>>>? recno()
>>>
>>
>>Only if the index is used in several subsequent seeks.
>>
>
>without the index, this solution is useless
>
>>>
>>>>recno is then the relative position.

Con tropo rispetto, mio amico, non sono d'accordo
CREATE TABLE SPEED.DBF FREE ;
  (Spd_ID I, ;
  Spd_Char C(10), ;
  Spd_Date D, ;
  Spd_DT T)

LOCAL ;
  m.lnI, ;
  m.lnX, ;
  m.Spd_ID, ;
  m.Spd_Char, ;
  m.Spd_Date, ;
  m.Spd_DT

FOR m.lnI = 1 TO 500000
  m.SPD_ID = m.lnI
  m.SPD_CHAR = TRANSFORM(m.lnI,"##########")
  *This will give me groups of records
  *with the same date / date time.
  m.lnX = m.lnI / 100
  m.SPD_DATE = {^2000-01-01} + m.lnX
  m.SPD_DT = {^2000-01-01 00:00:00} + m.lnX
  INSERT INTO SPEED FROM MEMVAR
  IF MOD(m.lnI,1000) = 0
    WAIT WINDOW TRANSFORM(m.lnI) NOWAIT
  ENDIF
ENDFOR
INDEX ON SPD_ID TAG SPD_ID
INDEX ON SPD_DATE TAG SPD_DATE
INDEX ON SPD_DT TAG SPD_DT
INDEX ON VAL(SPD_CHAR) TAG VALCHAR
CLEAR ALL

a=SECONDS()
SELECT * from speed order by spd_date descending into cursor c_fabio
LOCATE FOR spd_id = 500000 NOOPTIMIZE
?"locate:",RECNO(),SECONDS()-m.a

a=SECONDS()
SELECT * from speed order by spd_date into cursor c_fabio
INDEX on spd_id TAG spd_id DESCENDING
SEEK 500000
?"seek:",RECNO(),SECONDS()-m.a
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform