Difference between revisions of "Dbtkey()"

From Recital Documentation Wiki
Jump to: navigation, search
 
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==

Revision as of 14:35, 1 April 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 foundn");
		return(ERROR);
	}


SEE ALSO

dbakey(), dbgetrk(), dbrmvkey()