Difference between revisions of "Dbxupd()"

From Recital Documentation Wiki
Jump to: navigation, search
 
(One intermediate revision by one user not shown)
Line 11: Line 11:
  
 
<input parameters>
 
<input parameters>
char *dbx; /* Tagged index file descriptor */
+
char *dbx; /* Tagged index file descriptor */
long recno; /* Record number to update tag from */
+
long recno; /* Record number to update tag from */
  
  
Line 21: Line 21:
 
==RETURN VALUE==
 
==RETURN VALUE==
  
The dbxupd() 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.
+
The dbxupd() function returns 0 for success, or < 0 if an error occurs.  See the section on [[Library Return Code Values|return code values]] for a detailed list of return codes.
  
  
Line 38: Line 38:
  
 
#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] = {
 
"VESSEL", 'C', 18, 0, 0,
 
"VESSEL", 'C', 18, 0, 0,
 
"LAT", 'N', 4, 1, 0,
 
"LAT", 'N', 4, 1, 0,
Line 48: Line 48:
 
"DATE", 'D', 8, 0, 0,
 
"DATE", 'D', 8, 0, 0,
 
"FLAG", 'C', 9, 0, 0
 
"FLAG", 'C', 9, 0, 0
};
+
};
  
static void errorproc(
+
static void errorproc(
 
char *func,
 
char *func,
 
char *str,
 
char *str,
 
int rc);
 
int rc);
  
static char *text_table[] =  {
+
static char *text_table[] =  {
 
"Santa Margarita  80.027.5  700000095/01/01Spanish  "
 
"Santa Margarita  80.027.5  700000095/01/01Spanish  "
};
+
};
  
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 */
FLDNUM fieldcount; /* Number of fields to create */
+
FLDNUM fieldcount; /* Number of fields to create */
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);
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);
 
 
fieldcount = 6;
+
fieldcount = 6;
 
 
rc = dbcreat("shipwreck.dbf", fieldcount, fields);
+
rc = dbcreat("shipwreck.dbf", fieldcount, fields);
errorproc("dbcreat()","database created.", rc);
+
errorproc("dbcreat()","database created.", rc);
 
 
rc = dbopen("shipwreck.dbf", &dbf);
+
rc = dbopen("shipwreck.dbf", &dbf);
errorproc("dbopen()","table opened.", rc);
+
errorproc("dbopen()","table opened.", rc);
 
 
rc = dbxcreate( dbf,
+
rc = dbxcreate( dbf,
 
fields[0].fieldnm, /* "VESSEL",  */
 
fields[0].fieldnm, /* "VESSEL",  */
 
&dbx,
 
&dbx,
Line 89: Line 89:
 
0,
 
0,
 
0);
 
0);
errorproc("dbxcreate()","tag created", rc);
+
errorproc("dbxcreate()","tag created", rc);
  
rc = dbxcreate( dbf,
+
rc = dbxcreate( dbf,
 
fields[5].fieldnm, /* "FLAG",  */
 
fields[5].fieldnm, /* "FLAG",  */
 
&dbx,
 
&dbx,
Line 98: Line 98:
 
0,
 
0,
 
0);
 
0);
errorproc("dbxcreate()","tag created", rc);
+
errorproc("dbxcreate()","tag created", rc);
rc = dbxclose(dbx);
+
rc = dbxclose(dbx);
errorproc("dbxclose()", "tagged index closed.", rc);
+
errorproc("dbxclose()", "tagged index closed.", 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 = dbappend(dbf, text_table[0], &recno);
+
rc = dbappend(dbf, text_table[0], &recno);
errorproc("dbappend()", "record appended.", rc);
+
errorproc("dbappend()", "record appended.", rc);
rc = dbxakey(dbx, recno);
+
rc = dbxakey(dbx, recno);
errorproc("dbxakey()",  "key added.", rc);
+
errorproc("dbxakey()",  "key added.", rc);
 
 
rc = dbflush(dbf);
+
rc = dbflush(dbf);
errorproc("dbflush()", "table cache flushed.", rc);
+
errorproc("dbflush()", "table cache flushed.", rc);
rc = dbxflsh(dbx);
+
rc = dbxflsh(dbx);
errorproc("dbxflsh()", "tagged index cache flushed.", rc);
+
errorproc("dbxflsh()", "tagged index cache flushed.", rc);
  
rc = dbxrmvkey(dbx, "Santa Margarita  ", recno);
+
rc = dbxrmvkey(dbx, "Santa Margarita  ", recno);
errorproc("dbxrmvkey()", "key physically removed.", rc);  
+
errorproc("dbxrmvkey()", "key physically removed.", rc);  
  
rc = dbxakey(dbx, recno);
+
rc = dbxakey(dbx, recno);
errorproc("dbxakey()",  "key added back in.", rc);
+
errorproc("dbxakey()",  "key added back in.", rc);
  
rc = dbxupd(dbx, recno);
+
rc = dbxupd(dbx, recno);
errorproc("dbxupd()", "update key.", rc);
+
errorproc("dbxupd()", "update key.", rc);
 
 
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 136: Line 136:
 
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;
 
}
 
}

Latest revision as of 10:45, 6 May 2009

PURPOSE

update all tags in the tagged index file for the specified record


SYNOPSIS

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

RETURN VALUE

The dbxupd() 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 dbxupd() function will update all tags in the specified tagged index file, .DBX, for the given record number


EXAMPLE

The following example creates the shipwreck table and tags on the VESSEL and FLAG fields. It appends a record, adds the key, then removes and updates the 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 */
 
		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 = dbxrmvkey(dbx, "Santa Margarita   ", recno);
		errorproc("dbxrmvkey()", "key physically removed.", rc); 
 
		rc = dbxakey(dbx, recno);
		errorproc("dbxakey()",  "key added back in.", rc);
 
		rc = dbxupd(dbx, recno);
		errorproc("dbxupd()", "update key.", 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

dbxakey(), dbxrmvkey()