Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Another IndexSeek BUG?
Message
De
28/11/2003 13:05:33
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
 
À
27/11/2003 14:08:29
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00854073
Message ID:
00854267
Vues:
20
>I run into really weird bug (or is it a feature?) with using IndexSeeek function in a stored procedure assigned as default value for a field. In short, IndexSeek seems to clear all fields, previously filled in with default values.
>
>To recreate the bug:
>
>1) Create Test_StoredProcedures.prg file with following text in it:
>function NewId
> lparameters tcIndex
> local lnId
> lnId = 1
> do while indexseek(lnId, .f., alias(), tcIndex)
> lnId = lnId + 1
> enddo
> return lnId
>endfunc
>
>2) Create Test database and Test table in it:
>create database test.dbc
>append procedures from Test_StoredProcedures.prg
>create table Test (Name C(20) default "Record # " + transform(recno()), ;
> Id I default NewId('Id') primary key)
>
>3) Try to add a new record to the table with APPEND BLANK or just by pressing {CTRL+Y} in Browse window. The Name field will be blank. Changing bufering mode or index type does not change the behavior. It is the same in VFP7 & VFP8. Weird, isn't it? Does anybody have an explanation?

Seems to be the indexseek() is less than perfect. Here's a cheaper way to do the same:
lcAlias=alias()
lcAlias2=sys(2015)
use dbf() again in 0 alias (lcAlias2) order tcIndex desc
select (lcAlias2)
locate
lnID=eval(key(tcIndex))+1
use
select (lcAlias)
return lnID
or, alternately
select max({your key here}) as lnID from alias();
   into array lnID
return lnID[1]
The latter needs a check for the case when the table is empty, Set Deleted etc, but generally that's what my newid() does when the key is first time used during a session - for the rest of the session it uses values stored in id.dbf.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform