[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
USAGE
signed int scdikmake(
signed int datahandle,
signed int indexhandle,
void **key );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdikmake will build an index key using the key expression of the
index file specified by indexhandle and the data found in the record
buffer of the data file datahandle. Memory space for the key will
be allocated and the address of this block will be returned.
The key expression can consist of either the data field name or one of
five FoxBASE+ functions or a combination thereof. Data field types of
date, numeric, character or logical are allowed. FoxBASE+ functions:
dtoc, left, right, str, and substr are currently
supported by scdikmake.
Following is a brief description of the five expression functions:
dtoc will convert data from a date field to an ASCIIZ string of the
format mm/dd/yy. Syntax is:
dtoc(field_name)
left will return the left portion of a character field as an ASCIIZ
string. The number of characters returned is specified after the field
name. Syntax is:
left(field_name,number)
right will return the right portion of a character field as an ASCIIZ
string. The number of characters returned is specified after the field
name. This is a count from the right side of the field. Syntax is:
right(field_name,number)
str will convert a numeric field to an ASCIIZ string. The total length
of the string and the number of decimal places are optional parameters.
The default string length is 10 and the number of decimal places is 0.
Syntax is:
str(field_name,length,decimal_places)
substr will return the middle portion of a character field. The
starting offset into the field is a required parameter. The number of
characters to be used is an optional parameter whose default value is the
remainder of the field. Syntax is:
substr(field_name,start,count)
An example of a more complex key expression:
right(dtoc(date),2)+left(dtoc(date,2)
This expression would cause scdikmake to create an index key string
consisting of the year and month ("yymm"). For example if date equals
"2/13/89" the resultant key would be "8902".
NOTES
For key expressions consisting of only one data field scdikmake is
probably an overkill. You can easily generate these keys yourself. See
scdikdate for information on date string to key translation, and
scdiknum for numeric field to key translation. scdikmake is a
fairly large module and if not needed probably should not be used. This
function is best used when the key expression is more complex.
Memory is allocated for the generated key and it is the responsibility of
the caller to free this memory when finished.
EXAMPLE
#include <sc_base.h>
void main()
{
int idx, dbf;
char *key, name[65];
long recno;
scdinit(20,0);
if (scddopenx(&dbf, "TOC.DBF", 0) == SC_SUCCESS) {
if (scdiopenx(&idx, "TOCNAME.IDX", SC_BUFFER) == SC_SUCCESS) {
scddfput(dbf,0,name);
scddrput(dbf,&recno,SC_ADD);
scdikmake(dbf,idx,(void **) &key);
scdikadd(idx,key,recno);
free(key); /* free memory allocated for key */
scdiclose(idx);
}
scddclose(dbf);
}
scdterm();
}
See Also:
scdicreate
scdikdate
scdiknum
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson