Difference between revisions of "Dbxgetnr()"
From Recital Documentation Wiki
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
(One intermediate revision by one user not shown) | |||
Line 11: | Line 11: | ||
<input parameters> | <input parameters> | ||
− | char *dbf; | + | char *dbf; /* Table file descriptor */ |
− | char *dbx; /* Tagged index file descriptor */ | + | char *dbx; /* Tagged index file descriptor */ |
<output parameters> | <output parameters> | ||
− | char *record; /* Address of a buffer where the record data is returned */ | + | char *record; /* Address of a buffer where the record data is returned */ |
− | char *status; /* Record status, if marked for deletion = 0, otherwise 1 */ | + | char *status; /* Record status, if marked for deletion = 0, otherwise 1 */ |
</code> | </code> | ||
Line 38: | Line 38: | ||
<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 57: | Line 57: | ||
main() | main() | ||
{ | { | ||
− | + | int rc; /* Return Code for error handling */ | |
− | + | char *dbf; /* File descriptor for table */ | |
− | + | char *dbx; /* File descriptor for tagged index */ | |
− | + | int i; /* Loop control variable */ | |
− | + | char record[58]; /* Array of char for records */ | |
− | + | char nextkey[10][20]; /* Key buffers */ | |
− | + | char status; /* Deleted record flag */ | |
− | + | long rec_no[10]; /* Record number array */ | |
− | + | rc = dbdcache(100); | |
− | + | errorproc("dbdcache()","table cache specified.", rc); | |
− | + | rc = dbicache(100); | |
− | + | errorproc("dbicache()", "index cache specified.", rc); | |
− | + | rc = dbfilemode(1,0); | |
− | + | rc = dbopen("shipwreck.dbf", &dbf); | |
− | + | errorproc("dbopen()","table opened in shared mode.", rc); | |
− | + | rc = dbxopen(dbf, "shipwreck.dbx", &dbx); | |
− | + | errorproc("dbxopen()","tagged index opened.", rc); | |
− | + | rc = dbxfwd(dbx); | |
− | + | errorproc("dbxfwd()", "index pointer placed at bottom.", rc); | |
− | + | rc = dbxpkey(dbx, nextkey[0], rec_no); | |
− | + | errorproc("dbxpkey()", "previous key found in tagged index.", rc); | |
− | + | printf("\t\tprev key: t%s\n", nextkey[0]); | |
− | + | rc = dbxgetpr(dbf, dbx, record, &status); | |
− | + | errorproc("dbxgetpr()", "previous record (by key) retrieved.", rc); | |
− | + | printf("Previous: \t%s\n", record); | |
− | + | rc = dbxrewind(dbx); | |
− | + | errorproc("dbxrewind()", "Tagged index rewound.", rc); | |
− | + | for( i = 1; i <= 6; i++) { | |
− | + | rc = dbxgetnr(dbf, dbx, record, &status); | |
− | + | printf("\t\t%d: %s\n", i,record); | |
− | + | } | |
− | + | errorproc("dbxgetnr()", "6 records retrieved by tag key.", rc); | |
− | + | rc = dbxnkey(dbx, nextkey[0], rec_no); | |
− | + | errorproc("dbxnkey()", "next key retrieved in tagged index.", rc); | |
− | + | printf("\t\tnext key: \t%s\n", nextkey[0]); | |
− | + | rc = dbxclose(dbx); | |
− | + | errorproc("dbxclose()", "tagged index closed.", rc); | |
− | + | rc = dbclose(dbf); | |
− | + | errorproc("dbclose()", "table closed.", rc); | |
− | + | exit(0); | |
} | } | ||
Line 114: | Line 114: | ||
{ | { | ||
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; | ||
} | } | ||
Line 130: | Line 130: | ||
[[Category:Documentation]] | [[Category:Documentation]] | ||
− | [[Category:Library] | + | [[Category:Library]] |
Latest revision as of 15:28, 5 May 2009
PURPOSE
get next data record by key in active tag
SYNOPSIS
#include "dbl.h" int dbxgetnr (dbf, dbx, record, status) <input parameters> char *dbf; /* Table file descriptor */ char *dbx; /* Tagged index file descriptor */ <output parameters> char *record; /* Address of a buffer where the record data is returned */ char *status; /* Record status, if marked for deletion = 0, otherwise 1 */
RETURN VALUE
The dbxgetnr() 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 dbxgetnr()]] reads the next record in descending order in the active tag and returns the record data.
EXAMPLE
The following example opens the table and tag index, goes to the bottom of the index, reads the previous key by position then by key, rewinds the index, reads the next 6 records in the index, reads the next record by key and then closes the files.
#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 */ int i; /* Loop control variable */ char record[58]; /* Array of char for records */ char nextkey[10][20]; /* Key buffers */ char status; /* Deleted record flag */ long rec_no[10]; /* Record number array */ rc = dbdcache(100); errorproc("dbdcache()","table cache specified.", rc); rc = dbicache(100); errorproc("dbicache()", "index cache specified.", rc); rc = dbfilemode(1,0); rc = dbopen("shipwreck.dbf", &dbf); errorproc("dbopen()","table opened in shared mode.", rc); rc = dbxopen(dbf, "shipwreck.dbx", &dbx); errorproc("dbxopen()","tagged index opened.", rc); rc = dbxfwd(dbx); errorproc("dbxfwd()", "index pointer placed at bottom.", rc); rc = dbxpkey(dbx, nextkey[0], rec_no); errorproc("dbxpkey()", "previous key found in tagged index.", rc); printf("\t\tprev key: t%s\n", nextkey[0]); rc = dbxgetpr(dbf, dbx, record, &status); errorproc("dbxgetpr()", "previous record (by key) retrieved.", rc); printf("Previous: \t%s\n", record); rc = dbxrewind(dbx); errorproc("dbxrewind()", "Tagged index rewound.", rc); for( i = 1; i <= 6; i++) { rc = dbxgetnr(dbf, dbx, record, &status); printf("\t\t%d: %s\n", i,record); } errorproc("dbxgetnr()", "6 records retrieved by tag key.", rc); rc = dbxnkey(dbx, nextkey[0], rec_no); errorproc("dbxnkey()", "next key retrieved in tagged index.", rc); printf("\t\tnext key: \t%s\n", nextkey[0]); 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; }