Dbxtkey()

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

Jump to: navigation, search

PURPOSE

translate tag key to record number


SYNOPSIS

#include "dbl.h"
 
	int	dbxtkey(dbx, key, recno, softseek)
 
	<input parameters>
	char		*dbx;		/* Tagged index file pointer 							*/
	char		key;			/* Address of a buffer containing the key				*/
	int		softseek;		/* If 1, then perform a softseek						*/
 
 
	<output parameters>
	long		*recno;		/* Address of a buffer where record number is returned		*/


RETURN VALUE

The dbxtkey(() 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 dbxtkey() function translates a key into its associated record number by searching for the specified key in the active tag.


EXAMPLE

The following example searches for "Santa Rosa" in the VESSEL tag of the shipwreck table and returns the record number.


#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	record[58];	/* Array of char for records		*/
		char	status;		/* Deleted record flag			*/
		long	recno;		/* Table record variable			*/
		char	key[21];		/* Storage location for keys		*/
 
		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);
 
		rc = dbxtkey(dbx, "Santa Rosa	  ", &recno, 0);
		errorproc("dbxtkey()", "record number found by key.", rc);
		printf("ttrecord number: t%dn", recno);
 
		rc = dbxgetrk(dbf, dbx, "Santa Rosa	  ", record, &status);
		errorproc("dbxgetrk()", "record retrieved by key.", rc);
		printf("tt%sn", record);
 
		rc = dbxckey(dbx, key, &recno);
		errorproc("dbxckey()", "current key read.", rc);
		printf("ttcurrent key: t%sn", key);
 
		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

dbxckey(), dbxclose(), dbxgetrk(), dbxopen()