Difference between revisions of "Dbxgetrk()"

From Recital Documentation Wiki
Jump to: navigation, search
 
 
(One intermediate revision by one user not shown)
Line 12: Line 12:
  
 
<input parameters>
 
<input parameters>
char *dbf; /* Table file descriptor */
+
char *dbf; /* Table file descriptor */
char *dbx; /* Tagged index file descriptor */
+
char *dbx; /* Tagged index file descriptor */
char *key; /* Address of the buffer containing a key to search for */
+
char *key; /* Address of the buffer containing a key to search for */
  
  
 
<output parameters>
 
<output parameters>
char *record; /* Address of a buffer where the record data is returned */
+
char *record; /* Address of a buffer where the record data is returned */
char *status; /* Record status, if marked for deletion = 0, otherwise 1 */
+
char *status; /* Record status, if marked for deletion = 0, otherwise 1 */
 
</code>
 
</code>
  
Line 25: Line 25:
 
==RETURN VALUE==
 
==RETURN VALUE==
  
The dbxgetrk() function returns 0 for success, or < 0 if an error occurs. See the section on return code vales for a detailed list of return codes.
+
The dbxgetrk() 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 42: Line 42:
 
<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 61: Line 61:
 
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 record[58]; /* Array of char for records */
+
char record[58]; /* Array of char for records */
char status; /* Deleted record flag */
+
char status; /* Deleted record flag */
long recno; /* Table record variable */
+
long recno; /* Table record variable */
char key[21]; /* Storage location for keys */
+
char key[21]; /* Storage location for keys */
  
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(1,0);
+
rc = dbfilemode(1,0);
rc = dbopen("shipwreck.dbf", &dbf);
+
rc = dbopen("shipwreck.dbf", &dbf);
errorproc("dbopen()","table opened in shared  mode.", rc);
+
errorproc("dbopen()","table opened in shared  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 = dbxtkey(dbx, "Santa Rosa   ", &recno, 0);
+
rc = dbxtkey(dbx, "Santa Rosa   ", &recno, 0);
errorproc("dbxtkey()", "record number found by key.", rc);
+
errorproc("dbxtkey()", "record number found by key.", rc);
printf("ttrecord number: t%dn", recno);
+
printf("\t\trecord number: \t%d\n", recno);
  
rc = dbxgetrk(dbf, dbx, "Santa Rosa   ", record, &status);
+
rc = dbxgetrk(dbf, dbx, "Santa Rosa   ", record, &status);
errorproc("dbxgetrk()", "record retrieved by key.", rc);
+
errorproc("dbxgetrk()", "record retrieved by key.", rc);
printf("tt%sn", record);
+
printf("\t\t%s\n", record);
  
rc = dbxckey(dbx, key, &recno);
+
rc = dbxckey(dbx, key, &recno);
errorproc("dbxckey()", "current key read.", rc);
+
errorproc("dbxckey()", "current key read.", rc);
printf("ttcurrent key: t%sn", key);
+
printf("\t\tcurrent key: \t%s\n", key);
 
 
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);
 
}
 
}
  
Line 105: Line 105:
 
{
 
{
 
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 15:36, 5 May 2009

PURPOSE

get data record by key in tag


SYNOPSIS

#include "dbl.h"
 
	int	dbxgetrk(dbf, dbx, key, record, status)
 
	<input parameters>
	char	*dbf;		/* Table file descriptor */
	char	*dbx;	/* Tagged index file descriptor */
	char	*key;	/* Address of the buffer containing a key to search for */
 
 
	<output parameters>
	char	*record;	/* Address of a buffer where the record data is returned */
	char	*status;	/* Record status, if marked for deletion = 0, otherwise 1 */


RETURN VALUE

The dbxgetrk() 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 dbxgetrk() function searches for the specified key in the active tag of the .DBX file. If found, the record data is returned.


EXAMPLE

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


#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("\t\trecord number: \t%d\n", recno);
 
		rc = dbxgetrk(dbf, dbx, "Santa Rosa	  ", record, &status);
		errorproc("dbxgetrk()", "record retrieved by key.", rc);
		printf("\t\t%s\n", record);
 
		rc = dbxckey(dbx, key, &recno);
		errorproc("dbxckey()", "current key read.", rc);
		printf("\t\tcurrent key: \t%s\n", 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 -> %d\n", func, rc);
		exit(1);
	}
	printf("Function: \t%s, \t%s - Ok\n", func, str);
	return;
}


SEE ALSO

dbxckey(), dbxclose(), dbxopen(), dbxtkey()