Dbxtag()

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

Jump to: navigation, search

PURPOSE

change the active tag


SYNOPSIS

#include "dbl.h"
 
	int	dbxtag(dbx, tagname)
 
	<input parameters>
	char	*dbx		/* Tagged index file descriptor	*/
	char	*tagname	/* Address of a buffer containing the tag to make active	*/
 
 
	<output parameters>
	none


RETURN VALUE

The dbxtag() 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 dbxtag() function changes the active tag in the specified tag file, .DBX. All dbx functions in this library perform their operations on the active tag.


EXAMPLE

The following example creates the shipwreck table and tags on the VESSEL and FLAG fields. It appends a record, reads the current key using the default VESSEL tag then changes the active tag to FLAG and reads the current key.


#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   700000095/01/01Spanish  "
	};
 
	main()
	{
		int		rc; 		/* Return Code for error handling	*/
		char		*dbf; 		/* File descriptor for table		*/
		char		*dbx; 		/* File descriptor for tagged index	*/
		FLDNUM	fieldcount;	/* Number of fields to create		*/
		int		i;	 	/* Loop control variable		*/
		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(0,0);
 
	fieldcount = 6;
	rc = dbcreat("shipwreck.dbf", fieldcount, fields);
	errorproc("dbcreat()","database created.", rc);
 
	rc = dbopen("shipwreck.dbf", &dbf);
	errorproc("dbopen()","table opened.", rc);
 
	rc = dbxcreate( dbf,
			fields[0].fieldnm,		/* "VESSEL",  */
			&dbx,
			fields[0].fieldnm,		/* "VESSEL",  */
			NULL,
			0,
			0);
	errorproc("dbxcreate()","tag created", rc);
 
	rc = dbxcreate( dbf,
			fields[5].fieldnm,		/* "FLAG",  */
			&dbx,
			fields[5].fieldnm,		/* "FLAG",  */
			NULL,
			0,
			0);
	errorproc("dbxcreate()","tag created", rc);
	rc = dbxclose(dbx);
	errorproc("dbxclose()", "tagged index closed.", rc);
 
	rc = dbxopen(dbf, "shipwreck.dbx", &dbx);
	errorproc("dbxopen()","tagged index opened.", rc);
 
	rc = dbappend(dbf, text_table[0], &recno);
	errorproc("dbappend()", "record appended.", rc);
	rc = dbxakey(dbx, recno);
	errorproc("dbxakey()",  "key added.", rc);
 
	rc = dbflush(dbf);
	errorproc("dbflush()", "table cache flushed.", rc);
	rc = dbxflsh(dbx);
	errorproc("dbxflsh()", "tagged index cache flushed.", rc);
 
	rc = dbxckey(dbx, key, &recno);
	errorproc("dbxckey()", "current key read.", rc);
	printf("ttcurrent key: t%sn", key);
 
	rc = dbxtag(dbx, fields[5].fieldnm);
	errorproc("dbxtag()", "current tag changed to flag.", rc);
 
	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(), dbxopen()