Dbxkexpr()

From Recital Documentation Wiki
Revision as of 13:48, 1 April 2009 by Yvonnemilne (Talk | contribs)

Jump to: navigation, search

PURPOSE

get the key expression for a specified tag


SYNOPSIS

#include "dbl.h"
 
	int	dbxkexpr(dbx, tagno, tagname, keytype, keyexpr, forexpr,
	keyexprlen, keylen, keyunique, keydescend);
 
	<input parameters>
	char	 	*dbx;		 	/* Tagged index file descriptor 	*/
 
	<input/output parameters>
	int	 	tagno;		 	/* If tagno > 0, then it is used as input as the tag number, otherwise
				 	 	 	the tag number corresponding to the specified tagname is returned.	*/
	char	 	*tagname;	 	/* If tagno <= 0, then it is used as input as the tagname, otherwise
				 	 	 	the tagname corresponding to the 	specific tagno is returned.		*/
 
	<output parameters>
	char 	keytype;	 	 	/* Tag key data type:
					 	 	 	'C' - Character
					 	 	 	'N' - Numeric
					 	 	 	'D' – Date		*/
	char 	 *keyexpr;	 	/* Tag key  expression	 	 	 	 	*/
	char 	 *forexpr;	 	/* Tag for expression	 	 	 	 	*/
	int	 	*keyexprlen;	 	/* Length of the tag key expression	 	 	 	*/
	int	 	*keylen;	 	 	/* Tag key length		 	 	 	 	*/
	int	 	*keyunique; 	 	/* 1 if tag is unique, 0 otherwise	 	 	 	*/
	int	 	*keydescend;	 	/* 1 if tag is in descending order, 0 otherwise 	*/


RETURN VALUE

The dbxkexpr() function returns 0 for success, or < 0 if an error occurs. See the section on return code values for a detailed list of return codes.


DESCRIPTION

The dbxkexpr() function obtains the index tag information from the specified tagged index file, .DBX for a tag number or name.


EXAMPLE

The following example opens the index for the shipwreck.dbf table, checks the number of tags, then returns detailed information about the tags


#include <stdio.h>
#include "dbl.h"		/* Recital/Library include file		*/
#include "dblproto.h"		/* Recital/Library prototype file	*/
 
	static	dBFIELD fields[6] = {
		"VESSEL",	'C',	18,	0,	0,
		"LAT",	'N',	4,	1,	0,
		"LONG",	'N',	4,	1,	0,
		"AMOUNT",	'N',	10,	0,	0,
		"DATE",	'D',	8,	0,	0,
		"FLAG",	'C',	9,	0,	0
	};
 
	static void errorproc(
		char	*func,
		char	*str,
		int	rc);
 
main()
{
	int	rc; 			/* Return Code for error handling	*/
	char	*dbf; 			/* File descriptor for table		*/
	char	*dbx; 			/* File descriptor for tagged index	*/
	char	keytype; 		/* Variable for varying keytype	*/
	char	tagname[21]; 		/* Storage location for tag name	*/
	char	keyexpr[512]; 		/* Storage location for key expr	*/
	char	forexpr[512]; 		/* Storage location for for expr	*/
	int	kexprlen; 		/* The key expression length		*/
	int	keylen; 		/* The key length			*/
	int	i; 			/* Loop control variable		*/
	int	keyunique;		/* Boolean for unqiue tag key		*/
	int	keydescend;		/* Boolean for descending tag key	*/
	int	notags;			/* Number of tags in a dbx file	*/
 
	rc = dbdcache(100);
	errorproc("dbdcache()","table cache specified.", rc);
	rc = dbicache(100);
	errorproc("dbicache()", "index cache specified.",rc);
	rc = dbfilemode(0,0);
	rc = dbopen("shipwreck.dbf", &dbf);
	errorproc("dbopen()","table opened in exclusive mode.", rc);
	rc = dbxopen(dbf, "shipwreck.dbx", &dbx);
	errorproc("dbxopen()","tagged index opened.", rc);	
	rc = dbxnotags(dbx, &notags);
	errorproc("dbxnotags()","tagged index count obtained.", rc);
	printf("t	  Key count: t%dn", notags );
 
	for (i = 1; i <= notags; i++) {
	rc = dbxkexpr(dbx, 
			  &i,
			  tagname,
			  &keytype, 
			  keyexpr, 
			  forexpr,
			  &kexprlen, 
			  &keylen,
			  &keyunique,
			  &keydescend);
	errorproc("dbxkexpr()", "key information retrieved.", rc);
	printf("t	  Key number: t%dn", i );
	printf("t	  Key name: t%sn", tagname );
	printf("t	  Key type: t%cn", keytype );
	printf("t	  Key expression: %sn", keyexpr);
	printf("t	  Key length: %d   Expression length: %dn", kexprlen, keylen);
	printf("t	  For expression: %sn", forexpr);
	printf("t	  Key unique: t%sn", keyunique ? "Yes" : "No" );
	printf("t	  Key descending: t%sn", keydescend?"Yes":"No" );
	}	
 
	rc = dbxclose(dbx);
	errorproc("dbxclose()", "tagged index closed.", rc);
	 rc = dbclose(dbf);
	errorproc("dbclose()", "table closed.", rc);
	exit(0);
}
 
	static void errorproc(func, str, rc)
	char	*func;
	char	*str;
	int	rc;
{
	if ( rc != SUCCESS ) {
	printf("n  Error performing function %s -> %dn", func, rc);
	exit(1);
	}
	printf("Function: t%s, t%s - Okn", func, str);
	return;
}


SEE ALSO

dbxclose(), dbxcreate(), dbxopen()