Difference between revisions of "Dbatokey()"

From Recital Documentation Wiki
Jump to: navigation, search
 
Line 31: Line 31:
  
 
<pre>
 
<pre>
YYYYMMDD YYYY - Year: '1900' through '2999'
+
YYYYMMDD YYYY - Year: '1900' through '2999'
 
MM - Month: '01' through '12'
 
MM - Month: '01' through '12'
 
DD - Day: '01' through '28'/'29'/'30'/'31'
 
DD - Day: '01' through '28'/'29'/'30'/'31'
Line 51: Line 51:
  
 
rc = dbatokey("124.52", key);
 
rc = dbatokey("124.52", key);
if (rc = = SUCCESS) {
+
if (rc == SUCCESS) {
 
if (dbakey(ndx,key,(long)15) printf("Key added \n");
 
if (dbakey(ndx,key,(long)15) printf("Key added \n");
 
else {
 
else {
Line 78: Line 78:
  
 
rc = dbatokey("19680408",key);
 
rc = dbatokey("19680408",key);
if (rc = = SUCCESS) {
+
if (rc == SUCCESS) {
if (dbakey(ndx,key,(long) 420) && rc= = SUCCESS)
+
if (dbakey(ndx,key,(long) 420) && rc == SUCCESS)
 
Printf("Key added \n");
 
Printf("Key added \n");
Else {
+
else {
 
Printf("Error number %d \n", rc);
 
Printf("Error number %d \n", rc);
 
Exit(1);
 
Exit(1);

Latest revision as of 11:24, 1 May 2009

PURPOSE

ASCII to index key value


SYNOPSIS

#include<dbl.h>
 
	int	dbatokey(ascii, key)
 
	<input parameters>
	char 	*ascii;		/* ASCII string to be converted */
	char	*key;		/* Key type: 'D' or 'd' is for a date key, 'N' or 'n' is for a numeric key */
 
	<output parameters>
	char 	*key;		/* Address of the buffer where converted key is returned, thus "key" serves as both the input and output parameter */


RETURN VALUE

The dbatokey() function returns 0 for success. See the section on return code values for a detailed list of return codes.


DESCRIPTION

This function converts the string pointed to by ascii to the .NDX file key format. The input ASCII string should represent either a valid floating point number or a date in the following format:-


	YYYYMMDD		YYYY -	Year: '1900' through '2999'
				MM -		Month: '01' through '12'
				DD -		Day: '01' through '28'/'29'/'30'/'31'


EXAMPLE

This example converts the ASCII string "124.52" into the .NDX file key format and adds the numeric key to the index specified by "char *ndx;" with associated record number, 15.

#include "dbl.h"
 
	char	*ndx;		/* .NDX file descriptor	*/
	int	rc;			/* Return code */
	char	key[8];		/* Numeric key location */
 
	key[0] ='N';		/* Indicate numeric key */
 
	rc = dbatokey("124.52", key);
	if (rc == SUCCESS) {
		if (dbakey(ndx,key,(long)15) printf("Key added \n");
		else {
			printf("Error number %\n",rc);
			exit(1);
		}
	} else {
		printf("Error number %d \n", rc);
		exit (1);
	}


This example converts a date, 19680408 (April 8, 1968) in ASCII representation into .NDX file key format and adds the new key to the specified .NDX file with associated record number, 420.


#include "dbl.h"
 
	char	*ndx;		/* .NDX file descriptor */
	int	rc;			/* Return code */
	char	key[8];		/* Numeric key location */
 
	key[0] ='D';		/* Indicate date key */
 
	rc = dbatokey("19680408",key);
	if (rc == SUCCESS) {
		if (dbakey(ndx,key,(long) 420) && rc == SUCCESS)
			Printf("Key added \n");
		else {
			Printf("Error number %d \n", rc);
			Exit(1);
		}
	} else {
		printf("Error number %d \n", rc);
		exit (1);
	}


NOTE: The buffer to hold the converted key value ("key" in our examples) must be at least eight bytes long.


SEE ALSO

dbakey(), dbkeytoa(), dbstring(), dbstrcpy()