Difference between revisions of "Dbxopen()"

From Recital Documentation Wiki
Jump to: navigation, search
Line 12: Line 12:
  
 
<input parameters>
 
<input parameters>
char *dbf; /* .DBF file descriptor */
+
char *dbf; /* .DBF file descriptor */
char *filename; /* Address of a buffer containing the name of a .DBX file to be opened */
+
char *filename; /* Address of a buffer containing the name of a .DBX file to be opened */
  
 
<output parameters>
 
<output parameters>
char *dbx; /* The .DBX file descriptor */
+
char *dbx; /* The .DBX file descriptor */
 
</code>
 
</code>
  
Line 38: Line 38:
 
<code lang="c">
 
<code lang="c">
 
#include <stdio.h>
 
#include <stdio.h>
#include "dbl.h" /* Recital/Library include file */
+
#include "dbl.h" /* Recital/Library include file */
#include "dblproto.h" /* Recital/Library prototype file */
+
#include "dblproto.h" /* Recital/Library prototype file */
  
 
static dBFIELD fields[6] = {
 
static dBFIELD fields[6] = {
Line 55: Line 55:
 
int rc);
 
int rc);
  
main()
+
main()
{
+
{
int rc; /* Return Code for error handling */
+
int rc; /* Return Code for error handling */
char *dbf; /* File descriptor for table */
+
char *dbf; /* File descriptor for table */
char *dbx; /* File descriptor for tagged index */
+
char *dbx; /* File descriptor for tagged index */
char keytype; /* Variable for varying keytype */
+
char keytype; /* Variable for varying keytype */
char tagname[21]; /* Storage location for tag name */
+
char tagname[21]; /* Storage location for tag name */
char keyexpr[512]; /* Storage location for key expr */
+
char keyexpr[512]; /* Storage location for key expr */
char forexpr[512]; /* Storage location for for expr */
+
char forexpr[512]; /* Storage location for for expr */
int kexprlen; /* The key expression length */
+
int kexprlen; /* The key expression length */
int keylen; /* The key length */
+
int keylen; /* The key length */
int i; /* Loop control variable */
+
int i; /* Loop control variable */
int keyunique; /* Boolean for unqiue tag key */
+
int keyunique; /* Boolean for unqiue tag key */
int keydescend; /* Boolean for descending tag key */
+
int keydescend; /* Boolean for descending tag key */
int notags; /* Number of tags in a dbx file */
+
int notags; /* Number of tags in a dbx file */
  
rc = dbdcache(100);
+
rc = dbdcache(100);
errorproc("dbdcache()","table cache specified.", rc);
+
errorproc("dbdcache()","table cache specified.", rc);
rc = dbicache(100);
+
rc = dbicache(100);
errorproc("dbicache()", "index cache specified.",rc);
+
errorproc("dbicache()", "index cache specified.",rc);
rc = dbfilemode(0,0);
+
rc = dbfilemode(0,0);
rc = dbopen("shipwreck.dbf", &dbf);
+
rc = dbopen("shipwreck.dbf", &dbf);
errorproc("dbopen()","table opened in exclusive mode.", rc);
+
errorproc("dbopen()","table opened in exclusive mode.", rc);
rc = dbxopen(dbf, "shipwreck.dbx", &dbx);
+
rc = dbxopen(dbf, "shipwreck.dbx", &dbx);
errorproc("dbxopen()","tagged index opened.", rc);
+
errorproc("dbxopen()","tagged index opened.", rc);
rc = dbxnotags(dbx, &notags);
+
rc = dbxnotags(dbx, &notags);
errorproc("dbxnotags()","tagged index count obtained.", rc);
+
errorproc("dbxnotags()","tagged index count obtained.", rc);
printf("t   Key count: t%dn", notags );
+
printf("\t   Key count: \t%d\n", notags );
 
 
for (i = 1; i <= notags; i++) {
+
for (i = 1; i <= notags; i++) {
rc = dbxkexpr(dbx,  
+
rc = dbxkexpr(dbx,  
 
  &i,
 
  &i,
 
  tagname,
 
  tagname,
Line 95: Line 95:
 
  &keyunique,
 
  &keyunique,
 
  &keydescend);
 
  &keydescend);
errorproc("dbxkexpr()", "key information retrieved.", rc);
+
errorproc("dbxkexpr()", "key information retrieved.", rc);
printf("t   Key number: t%dn", i );
+
printf("\t   Key number: \t%d\n", i );
printf("t   Key name: t%sn", tagname );
+
printf("\t   Key name: \t%s\n", tagname );
printf("t   Key type: t%cn", keytype );
+
printf("\t   Key type: \t%c\n", keytype );
printf("t   Key expression: %sn", keyexpr);
+
printf("\t   Key expression: %s\n", keyexpr);
printf("t   Key length: %d  Expression length: %dn", kexprlen, keylen);
+
printf("\t   Key length: %d  Expression length: %d\n", kexprlen, keylen);
printf("t   For expression: %sn", forexpr);
+
printf("\t   For expression: %s\n", forexpr);
printf("t   Key unique: t%sn", keyunique ? "Yes" : "No" );
+
printf("\t   Key unique: \t%s\n", keyunique ? "Yes" : "No" );
printf("t   Key descending: t%sn", keydescend?"Yes":"No" );
+
printf("\t   Key descending: \t%s\n", keydescend?"Yes":"No" );
}
+
}
 
 
rc = dbxclose(dbx);
+
rc = dbxclose(dbx);
errorproc("dbxclose()", "tagged index closed.", rc);
+
errorproc("dbxclose()", "tagged index closed.", rc);
rc = dbclose(dbf);
+
rc = dbclose(dbf);
errorproc("dbclose()", "table closed.", rc);
+
errorproc("dbclose()", "table closed.", rc);
exit(0);
+
exit(0);
}
+
}
  
 
static void errorproc(func, str, rc)
 
static void errorproc(func, str, rc)
Line 117: Line 117:
 
char *str;
 
char *str;
 
int rc;
 
int rc;
{
+
{
 
if ( rc != SUCCESS ) {
 
if ( rc != SUCCESS ) {
printf("n  Error performing function %s -> %dn", func, rc);
+
printf("\n  Error performing function %s -> %d\n", func, rc);
exit(1);
+
exit(1);
 
}
 
}
printf("Function: t%s, t%s - Okn", func, str);
+
printf("Function: \t%s, \t%s - Ok\n", func, str);
 
return;
 
return;
 
}
 
}

Revision as of 16:21, 5 May 2009

PURPOSE

open a .dbx index file


SYNOPSIS

#include "dbl.h"
 
	int	dbxopen(dbf, filename, dbx);
 
	<input parameters>
	char	*dbf;			/* .DBF file descriptor */
	char	*filename;		/* Address of a buffer containing the name of a .DBX file to be opened */
 
	<output parameters>
	char	*dbx;		/* The .DBX file descriptor */


RETURN VALUE

The dbxopen() 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

This function opens a .DBX file and returns its file descriptor. A call to The dbxclose() function releases the file descriptor.


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%d\n", 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%d\n", i );
			printf("\t	  Key name: \t%s\n", tagname );
			printf("\t	  Key type: \t%c\n", keytype );
			printf("\t	  Key expression: %s\n", keyexpr);
			printf("\t	  Key length: %d   Expression length: %d\n", kexprlen, keylen);
			printf("\t	  For expression: %s\n", forexpr);
			printf("\t	  Key unique: \t%s\n", keyunique ? "Yes" : "No" );
			printf("\t	  Key descending: \t%s\n", 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 -> %d\n", func, rc);
		exit(1);
	}
	printf("Function: \t%s, \t%s - Ok\n", func, str);
	return;
}


SEE ALSO

dbxclose(), dbxcreate(), dbxkexpr()