Difference between revisions of "Dbtkey()"

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 *ndx; /* .NDX file descriptor */
+
char *ndx; /* .NDX file descriptor */
char *key; /* Address of a buffer containing the key */
+
char *key; /* Address of a buffer containing the key */
  
 
<output parameter>
 
<output parameter>
long *recno /* Address of the variable where the record number is returned by the function */
+
long *recno /* Address of the variable where the record number is returned by the function */
  
 
</code>
 
</code>
Line 29: Line 29:
  
 
This function translates a key into its associated record number by searching for the specified key in the .NDX file and reading the corresponding record number.  If the key is numeric and it is not found in the .NDX file, the function returns d_NOKEY.  If the key is not found, but it is of type character, the function keeps searching for similar keys (each time one character shorter than the key in the previous search).  If such a key is located, the function returns semi-successful return code d_MAYBE.
 
This function translates a key into its associated record number by searching for the specified key in the .NDX file and reading the corresponding record number.  If the key is numeric and it is not found in the .NDX file, the function returns d_NOKEY.  If the key is not found, but it is of type character, the function keeps searching for similar keys (each time one character shorter than the key in the previous search).  If such a key is located, the function returns semi-successful return code d_MAYBE.
 +
  
 
==EXAMPLE==
 
==EXAMPLE==
Line 37: Line 38:
 
#include "dbl.h"
 
#include "dbl.h"
  
char *ndx; /* .NDX file descriptor */
+
char *ndx; /* .NDX file descriptor */
char key[10]; /* Key buffer */
+
char key[10]; /* Key buffer */
long recno; /* Record number */
+
long recno; /* Record number */
int rc; /* Return code */
+
int rc; /* Return code */
  
 
rc = dbtkey(ndx, key, &recno);
 
rc = dbtkey(ndx, key, &recno);
 
if (rc != SUCCESS && rc != d_MAYBE) {
 
if (rc != SUCCESS && rc != d_MAYBE) {
printf("Key not foundn");
+
printf("Key not found\n");
 
return(ERROR);
 
return(ERROR);
 
}
 
}

Latest revision as of 15:36, 1 May 2009

PURPOSE

translate key into record number


SYNOPSIS

#include "dbl.h"
 
	int	dbtkey(ndx, key, recno)
 
	<input parameters>
	char	*ndx;		/* .NDX file descriptor */
	char	*key;		/* Address of a buffer containing the key */
 
	<output parameter>
	long	*recno		/* Address of the variable where the record number is returned by the function */


RETURN VALUE

The dbtkey() 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

This function translates a key into its associated record number by searching for the specified key in the .NDX file and reading the corresponding record number. If the key is numeric and it is not found in the .NDX file, the function returns d_NOKEY. If the key is not found, but it is of type character, the function keeps searching for similar keys (each time one character shorter than the key in the previous search). If such a key is located, the function returns semi-successful return code d_MAYBE.


EXAMPLE

This example translates a character key "char key[10]" to a record number which is returned in "long recno". The .NDX file descriptor is in "char *ndx".

#include "dbl.h"
 
	char	*ndx;	/* .NDX file descriptor */
	char	key[10];	/* Key buffer */
	long	recno;	/* Record number */
	int	rc;		/* Return code */
 
	rc = dbtkey(ndx, key, &recno);
	if (rc != SUCCESS && rc != d_MAYBE) {
		printf("Key not found\n");
		return(ERROR);
	}


SEE ALSO

dbakey(), dbgetrk(), dbrmvkey()