Difference between revisions of "Dbxcreate()"
From Recital Documentation Wiki
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
Line 12: | Line 12: | ||
<input parameters> | <input parameters> | ||
− | char *dbf; /* Table .DBF file descriptor | + | char *dbf; /* Table .DBF file descriptor */ |
− | char *tagname; /* Name of the tag to be created | + | char *tagname; /* Name of the tag to be created */ |
− | char *keyexpr; /* Address of a buffer containing key expression */ | + | char *keyexpr; /* Address of a buffer containing key expression */ |
− | char *forexpr; /* Address of a buffer containing for expression */ | + | char *forexpr; /* Address of a buffer containing for expression */ |
− | int keyunique; /* If >= 1, tag is created unique | + | int keyunique; /* If >= 1, tag is created unique */ |
− | int keydescend; /* If >= 1, tag is created in descending order | + | int keydescend; /* If >= 1, tag is created in descending order */ |
<output parameters> | <output parameters> | ||
− | char *dbx; /* Open tagged index file descriptor | + | char *dbx; /* Open tagged index file descriptor */ |
</code> | </code> | ||
Line 43: | Line 43: | ||
<code lang="c"> | <code lang="c"> | ||
#include <stdio.h> | #include <stdio.h> | ||
− | #include "dbl.h" | + | #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] = { | ||
"VESSEL", 'C', 18, 0, 0, | "VESSEL", 'C', 18, 0, 0, | ||
− | "LAT", 'N', 4, 1, 0, | + | "LAT", 'N', 4, 1, 0, |
− | "LONG", 'N', 4, 1, 0, | + | "LONG", 'N', 4, 1, 0, |
"AMOUNT", 'N', 10, 0, 0, | "AMOUNT", 'N', 10, 0, 0, | ||
− | "DATE", 'D', 8, 0, 0, | + | "DATE", 'D', 8, 0, 0, |
− | "FLAG", 'C', 9, 0, 0 | + | "FLAG", 'C', 9, 0, 0 |
}; | }; | ||
Line 62: | Line 62: | ||
main() | main() | ||
{ | { | ||
− | + | int rc; /* Return Code for error handling */ | |
− | + | char *dbf; /* File descriptor for table */ | |
− | + | char *dbx; /* File descriptor for tagged index */ | |
− | + | rc = dbdcache(100); | |
− | + | errorproc("dbdcache()","table cache specified.", rc); | |
− | + | rc = dbicache(100); | |
− | + | errorproc("dbicache()", "index cache specified.",rc); | |
− | + | rc = dbfilemode(0,0); | |
− | + | rc = dbopen("shipwreck.dbf", &dbf); | |
− | + | errorproc("dbopen()","table opened in exclusive mode.", rc); | |
− | + | rc = dbxcreate( dbf, | |
fields[0].fieldnm, /* "VESSEL", */ | fields[0].fieldnm, /* "VESSEL", */ | ||
&dbx, | &dbx, | ||
Line 81: | Line 81: | ||
0, | 0, | ||
0); | 0); | ||
− | + | errorproc("dbxcreate()","tag created", rc); | |
− | + | rc = dbxclose(dbx); | |
− | + | errorproc("dbxclose()", "tagged index closed.", rc); | |
− | + | rc = dbclose(dbf); | |
− | + | errorproc("dbclose()", "table closed.", rc); | |
− | + | exit(0); | |
} | } | ||
Line 97: | Line 97: | ||
{ | { | ||
if ( rc != SUCCESS ) { | if ( rc != SUCCESS ) { | ||
− | + | printf("\n Error performing function %s -> %d\n", func, rc); | |
− | + | exit(1); | |
} | } | ||
− | printf("Function: t%s, t%s - | + | printf("Function: \t%s, \t%s - Ok\n", func, str); |
return; | return; | ||
} | } |
Revision as of 15:01, 5 May 2009
PURPOSE
create an index tag in a tagged index file
SYNOPSIS
#include "dbl.h" int dbxcreate(dbf, tagname, dbx, keyexpr, forexpr, keyunique, keydescend) <input parameters> char *dbf; /* Table .DBF file descriptor */ char *tagname; /* Name of the tag to be created */ char *keyexpr; /* Address of a buffer containing key expression */ char *forexpr; /* Address of a buffer containing for expression */ int keyunique; /* If >= 1, tag is created unique */ int keydescend; /* If >= 1, tag is created in descending order */ <output parameters> char *dbx; /* Open tagged index file descriptor */
RETURN VALUE
The dbxcreate() 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 dbxcreate() function will create an index tag for the specified table, .DBF in a tagged index file, .DBX. If the tagged file does not already exist, it is created with the same name as the table.
EXAMPLE
The following example creates a tag on the VESSEL field for the shipwreck.dbf table.
#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 */ rc = dbdcache(100); errorproc("dbdcache()","table cache specified.", rc); rc = dbicache(100); errorproc("dbicache()", "index cache specified.",rc); rc = dbfilemode(0,0); rc = dbopen("shipwreck.dbf", &dbf); errorproc("dbopen()","table opened in exclusive mode.", rc); rc = dbxcreate( dbf, fields[0].fieldnm, /* "VESSEL", */ &dbx, fields[0].fieldnm, /* "VESSEL", */ NULL, 0, 0); errorproc("dbxcreate()","tag created", rc); 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; }