Difference between revisions of "Dbxakey()"

From Recital Documentation Wiki
Jump to: navigation, search
 
Line 12: Line 12:
  
 
<input parameters>
 
<input parameters>
char *dbx; /* Tagged index file descriptor */
+
char *dbx; /* Tagged index file descriptor */
long recno; /* Record number */
+
long recno; /* Record number */
  
 
<output parameters>
 
<output parameters>
Line 40: Line 40:
 
<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 58: Line 58:
  
 
static char *text_table[] =  {
 
static char *text_table[] =  {
"Santa Margarita   80.027.5  700000095/01/01Spanish ",
+
"Santa Margarita 80.027.5  7000000 95/01/01 Spanish ",
"Santa Rosa   81.824.8  3000000032/01/01Spanish ",
+
"Santa Rosa 81.824.8  30000000 32/01/01 Spanish ",
"Unknown galleon   83.123.0   015/01/01Spanish ",
+
"Unknown galleon 83.123.0   0 15/01/01 Spanish ",
"Jessie 97.127.4    10000075/01/01U.S.    ",
+
"Jessie 97.127.4    100000 75/01/01 U.S.    ",
"Lea   96.227.8  100000080/01/01U.S.    ",
+
"Lea 96.227.8  1000000 80/01/01 U.S.    ",
"S.J. Lee     96.926.9    20000075/01/01U.S.    ",
+
"S.J. Lee 96.926.9    200000 75/01/01 U.S.    ",
"Genovase     78.418.4  185000030/01/01Spanish ",
+
"Genovase 78.418.4  1850000 30/01/01 Spanish ",
"Unknown Vessel   77.517.9   075/01/01U.S.    "
+
"Unknown Vessel 77.517.9   075 /01/01 U.S.    "
 
};
 
};
  
 
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 */
int i; /* Loop control variable */
+
int i; /* Loop control variable */
long recno; /* Table record variable */
+
long recno; /* Table record variable */
  
 
rc = dbdcache(100);
 
rc = dbdcache(100);
Line 117: Line 117:
 
{
 
{
 
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:16, 1 May 2009

PURPOSE

add keys to all tags in the tagged index file


SYNOPSIS

#include "dbl.h"
 
	int	dbxakey(dbx, recno);
 
	<input parameters>
	char	*dbx;		/* Tagged index file descriptor */
	long	recno;		/* Record number */
 
	<output parameters>
	none


RETURN VALUE

The dbxakey() 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 dbxakey() function adds a key to each index tag in the tagged index file, .DBX for the record number specified.


EXAMPLE

The following example opens the table and tag index, locks the table and tag index, adds in records, flushes the buffers, then unlocks and closes the files.


#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);
 
	static char *text_table[] =  {
		"Santa Margarita		80.027.5   7000000	95/01/01	Spanish  ",
		"Santa Rosa		81.824.8  30000000	32/01/01	Spanish  ",
		"Unknown galleon	83.123.0	   	0	15/01/01	Spanish  ",
		"Jessie			97.127.4    100000	75/01/01	U.S.     ",
		"Lea				96.227.8   1000000	80/01/01	U.S.     ",
		"S.J. Lee			96.926.9    200000	75/01/01	U.S.     ",
		"Genovase			78.418.4   1850000	30/01/01	Spanish  ",
		"Unknown Vessel		77.517.9   		075	/01/01	U.S.     "
	};
 
	main()
	{
	int	rc; 			/* Return Code for error handling */
	char	*dbf; 		/* File descriptor for table */
	char	*dbx; 		/* File descriptor for tagged index */
	int	i;	 		/* Loop control variable */
	long	recno; 		/* Table record variable */
 
	rc = dbdcache(100);
	errorproc("dbdcache()","table cache specified.", rc);
	rc = dbicache(100);
	errorproc("dbicache()", "index cache specified.",rc);
	rc = dbfilemode(1,0);
	rc = dbopen("shipwreck.dbf", &dbf);
	errorproc("dbopen()","table opened in shared mode.", rc);
 
	rc = dbxopen(dbf, "shipwreck.dbx", &dbx);
	errorproc("dbxopen()","tagged index opened.", rc);
 
	for( i = 1; i <= 7; i++)  {
		rc = dbappend(dbf, text_table[i], &recno);
		errorproc("dbappend()", "record appended.", rc);
		rc = dbxlocki(dbx);
		errorproc("dbxlocki()",  "tagged index file locked.", rc);
		rc = dbxakey(dbx, recno);
		errorproc("dbxakey()",  "key added.", rc);
		rc = dbxunlocki(dbx);
		errorproc("dbxunlocki()",  "tagged index file unlocked.", rc);
	}
 
	rc = dbflush(dbf);
	errorproc("dbflush()", "table cache flushed.", rc);
	rc = dbxflsh(dbx);
	errorproc("dbxflsh()", "Tagged index cache flushed.", rc);
 
	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

dbappend(), dbxclose(), dbxflsh(), dbxlocki(), dbxopen(), dbxunlocki()