Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Programmatically Setting Descending Primary Key
Message
 
To
13/12/2006 20:49:55
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01177451
Message ID:
01177500
Views:
11
Hi Carole,

What you need descending PK as default? You can before using set:
SET ORDER TO "primarykey" DESCENDING
Yes, VFP has not way how to create descending index with ALTER TABLE. But, you can use my a small utility FILE#28060.
#INCLUDE "dbc.h"
SET PROCEDURE TO dbc.prg ADDITIVE
LOCAL lcAlias,liIDT,loDBC,luValue,liIDI
loDBC=CREATEOBJECT("_DBC")
lcAlias=SYS(2015)

** REMOVE older info about primary key
=loDBC.OpenTable(HOME(2)+"\Tastrade\Data\tastrade.dbc",lcAlias,"EXCLUSIVE")
* Get table ID
liIDT=loDBC.GetIDObject(lcAlias,_DBC_Table,"products")
* Clear property value - primary key
=loDBC.ClearProperty(lcAlias,liIDT,_DBCID_PrimaryKey)
* delete object for PK
liIDI=loDBC.GetIDObject(lcAlias,_DBC_Table,"products.primarykey")
DELE NEXT 1
PACK
loDBC.CloseTable(lcAlias)

** ADD index AS descending and CANDIDATE
=loDBC.OpenTable(HOME(2)+"\Tastrade\Data\tastrade.dbc!products",lcAlias,"EXCLUSIVE")
INDEX ON blablalblabla TAG PRIMARYKEY DESCENDING CANDIDATE
loDBC.CloseTable(lcAlias)

** ADD new info about primary key
=loDBC.OpenTable(HOME(2)+"\Tastrade\Data\tastrade.dbc",lcAlias,"EXCLUSIVE")
* Get table ID
liIDT=loDBC.GetIDObject(lcAlias,_DBC_Table,"products")
* Set property value - primary key
=loDBC.SetProperty(lcAlias,liIDT,_DBCID_PrimaryKey,"primarykey")
* Set index as primary
liIDI=loDBC.GetIDObject(lcAlias,_DBC_Table,"products.primarykey")
=loDBC.SetProperty(lcAlias,liIDI,_DBCID_Prim_Cand,.T.)
loDBC.CloseTable(lcAlias)

RELEASE loDBC
RELEASE PROCEDURE dbc.prg
MartiJ

>Hi,
>
>I am writing a utility that uses ataginfo() to discover tags that are primary or candidate keys and then remove them from a table, storing the index info so that I can later restore them.
>
>In my restore utility I am able to do the following to restore the candidate indexes in either descending or ascending order in the cdx file:
>
>
lcTable = [Customer]
>lctagexpr = "icustomerid"
>lctagfilter = "icustomerid > 1000"
>lctagname = "customer"
>lctagproc = ["MACHINE"]
>lctagorder = "DESCENDING"
>
>index on &lctagexpr for &lctagfilter tag &lctagname ;
>  collate &lctagproc &lctagorder additive
>
>
>I can also to the following to restore a primary key in ascending order:
>
>
alter table (m.lcTable) add primary key &lctagexpr ;
>  for &lctagfilter tag &lctagname collate &lctagproc
>
>However in the VFP IDE it is possible to make a primary key that is in a descending order. I can not figure out how to do this programmatically. Functionally I can just use a candidate key, but then commands like primary()will not behave as they did pre-strip.
>
>Thanks!
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Reply
Map
View

Click here to load this message in the networking platform