Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a Filter expression from a .CDX file 1

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB

How can one return the Filter expression from a .CDX file

For instance:-

? SYS(14,17,[CONTACTS])

will return

UPPER(COMPANY)

which is the index Expression.

What function returns the Filter, assuming one exists?

TIA

Chris [sig][/sig]
 
SYS(2021, nIndexNumber [, nWorkArea | cTableAlias]) [sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 

Almost the same question - function to return the index type, such as UNIQUE, REGULAR, and function to return order, such as ASCENDING or DESCENDING?

TIA

Chris [sig][/sig]
 
Chris, for complete ways to take information you need from database, open GenDBC.PRG and use keyword search for what you want. I found SYS(2021) function by such way. [sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
Vlad

Once again many thanks.

I wish I had looked properly at that program before.

Chris [sig][/sig]
 
I have a function that opens a dbf and creates a program file with all the index info. With that program file you can delete the cdx and then run the program recreate all the indexs on the database. It also stores the info in a memo field for future use. If anyone wants it email me. [sig]<p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br>[/sig]
 
David

I wish I had known about your program yesterday.

The reason for finding those functions was to be able to emulate your program.

Here follows first attempt:-

CREA TABLE cdx_tags ;
[tab](Work_area N (5) ,;
[tab]Table_name M ,;
[tab]Tag_name C (10) ,;
[tab]Expression M ,;
[tab]Filter M ,;
[tab]Descending C (10) ,;
[tab]Tag_type C (10) ,;
[tab]Index_on M)

FOR lnTableNo = 1 TO 32767
[tab]IF !EMPTY(SELECT(lnTableNo)) && Checks for open tables
[tab][tab]SELE (lnTableNo)
[tab][tab]FOR lnCount = 1 TO TAGCOUNT()
[tab][tab][tab]IF !EMPTY(TAG(lnCount)) && Checks for index tags
[tab][tab][tab][tab]APPE BLAN IN CDX_TAGS
[tab][tab][tab][tab]REPLACE CDX_TAGS.work_area WITH SELECT(),;
[tab][tab][tab][tab][tab]CDX_TAGS.table_name WITH ALIAS[(lnTableNo),;
[tab][tab][tab][tab][tab]CDX_TAGS.tag_name WITH TAG(lnCount),;
[tab][tab][tab][tab][tab]CDX_TAGS.expression WITH SYS(14,lnCount),;
[tab][tab][tab][tab][tab]CDX_TAGS.filter WITH SYS(2021,lnCount)

[tab][tab][tab][tab]IF DESCENDING(lnCount)
[tab][tab][tab][tab][tab]REPLACE CDX_TAGS.Descending WITH [DESCENDING]
[tab][tab][tab][tab]ENDIF

[tab][tab][tab][tab]DO CASE
[tab][tab][tab][tab]CASE UNIQUE(lnCount)
[tab][tab][tab][tab][tab][tab]REPLACE CDX_TAGS.Tag_type WITH [UNIQUE]
[tab][tab][tab][tab]CASE CANDIDATE(lnCount)
[tab][tab][tab][tab][tab]REPLACE CDX_TAGS.Tag_type WITH [CANDIDATE]
[tab][tab][tab][tab]ENDCASE

[tab][tab][tab][tab]REPLACE CDX_TAGS.index_on WITH [INDEX ON ];
[tab][tab][tab][tab][tab]+ALLTRIM(CDX_TAGS.expression);
[tab][tab][tab][tab][tab]+[ TAG ];
[tab][tab][tab][tab][tab]+ALLTRIM(CDX_TAGS.tag_name);
[tab][tab][tab][tab][tab]+[ ];
[tab][tab][tab][tab][tab]+ALLTRIM(CDX_TAGS.Filter);
[tab][tab][tab][tab][tab]+[ ];
[tab][tab][tab][tab][tab]+ALLTRIM(CDX_TAGS.Descending);
[tab][tab][tab][tab][tab]+[ ];
[tab][tab][tab][tab][tab]+ALLTRIM(CDX_TAGS.Tag_type)
[tab][tab][tab]ELSE
[tab][tab][tab][tab]EXIT
[tab][tab][tab][tab]&& Exit the loop when no more tags are found
[tab][tab][tab]ENDIF
[tab][tab]ENDFOR
[tab]ELSE
[tab][tab]EXIT
[tab][tab]&& Exit the loop when no more tables are found
[tab]ENDIF
ENDFOR

SELE CDX_TAGS
BROW

The expressions for each tag may be found in the memo field CDX_TAGS.Index_on.

Someone may find the code of use.

Chris
[sig][/sig]
 
Just playing Devils Advocate for you.
What do you do about Primary Index Keys??
case primary()
&quot;ALTER TABLE &quot; + alias() + &quot; DROP PRIMARY KEY ADD PRIMARY &quot; + ........
[sig]<p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br>ICQ VFP ActiveList #46145644[/sig]
 
You also have an error in your code
replace cdx_tags.Work_area with select(),;
cdx_tags.Table_name with alias[(lnTableNo)[red]][/red],;
CDX_TAGS.tag_name WITH TAG(lnCount),;
CDX_TAGS.expression WITH SYS(14,lnCount),;
CDX_TAGS.filter WITH SYS(2021,lnCount)
[sig]<p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br>ICQ VFP ActiveList #46145644[/sig]
 
David

The missing square bracket is from formatting the code for the post.

The reason there is no reference to PRIMARY() is that the code was developed for free tables only hence the omission.

Thanks your comments, clearly code for PRIMARY() needs to be included for .dbc.

How does it compare to your version?

Chris [sig][/sig]
 
I totaly cheated: (since I wrote it about 10 years ago in 2.0)
Your method uses command that were not available in ver 2.0

close data
use sysindex
scan all
select 0
use (alltrim(SYSINDEX.DBF))
List Status to file c:\stat.txt
use
select SYSINDEX
lnHandle=fopen(&quot;c:\stat.txt&quot;)
replace SYSINDEX.CDXINFO with &quot; &quot;
do while not feof(lnHandle)
lcString=upper(alltrim(fgets(lnHandle)))
if lcString = &quot;INDEX&quot;
stripout the index info
replace SYSINDEX.CDXINFO with lcString additive
endif
enddo
=fclose(lnHandle)
endscan [sig]<p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br>ICQ VFP ActiveList #46145644[/sig]
 
David

Thanks

It's a good example low-level file functions which you don't see much of these days.

Chris [sig][/sig]
 
Oops

It's a good example of low-level file functions which you don't see much of these days.

Chris

[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top