Difference between revisions of "Library dblsamp"
From Recital Documentation Wiki
		
		
		
| Yvonnemilne  (Talk | contribs) | Yvonnemilne  (Talk | contribs)  | ||
| Line 144: | Line 144: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBCREATX() - Enables the addition of table field descriptions.	 | + | 	/* DBCREATX() - Enables the addition of table field descriptions. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	strcpy(flddes[0], "The vessel's name."); | 	strcpy(flddes[0], "The vessel's name."); | ||
| Line 157: | Line 157: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBOPEN() - example opens table 'shipwreck.dbf' returning the table  | + | 	/* DBOPEN() - example opens table 'shipwreck.dbf' returning the table */ | 
| − | 	/* file descriptor (dbf) used in upcoming functions	 | + | 	/* file descriptor (dbf) used in upcoming functions */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbopen("shipwreck.dbf", &dbf); | 	rc = dbopen("shipwreck.dbf", &dbf); | ||
| Line 164: | Line 164: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBGETF() - obtain table information on the table referenced by the	 | + | 	/* DBGETF() - obtain table information on the table referenced by the */ | 
| − | 	/* 'dbf' file descriptor.	 | + | 	/* 'dbf' file descriptor. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbgetf(dbf, &reclen, &month, &day, &year, &nofields, dbfields); | 	rc = dbgetf(dbf, &reclen, &month, &day, &year, &nofields, dbfields); | ||
| Line 174: | Line 174: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBGETFX() - obtain extended table information including the numeric	 | + | 	/* DBGETFX() - obtain extended table information including the numeric */ | 
| − | 	/* field location array (fldpos) and the field descriptions (flddes).	 | + | 	/* field location array (fldpos) and the field descriptions (flddes). */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbgetfx(dbf, &reclen, &month, &day, &year, &nofields, dbfields, | 	rc = dbgetfx(dbf, &reclen, &month, &day, &year, &nofields, dbfields, | ||
| Line 184: | Line 184: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBLOCKF() - locks the table for the additions that follow.	 | + | 	/* DBLOCKF() - locks the table for the additions that follow. */ | 
| − | 	/* Synonymous with DBTLOCKF(), which tests the lock	 | + | 	/* Synonymous with DBTLOCKF(), which tests the lock */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dblockf(dbf); | 	rc = dblockf(dbf); | ||
| Line 195: | Line 195: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBCLOSE() - close the active table	 | + | 	/* DBCLOSE() - close the active table */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbclose(dbf); | 	rc = dbclose(dbf); | ||
| Line 201: | Line 201: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Exclusive read write access of the table is required to create or delete	*/ | + | 	/* Exclusive read write access of the table is required to create or delete */ | 
| − | 	/* tags.	 | + | 	/* tags. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbfilemode(0, 0); | 	rc = dbfilemode(0, 0); | ||
| Line 209: | Line 209: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform basic tagged index functions.	 | + | 	/* Perform basic tagged index functions. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXCREATE() - in this example creates a tag on field VESSEL	 | + | 	/* DBXCREATE() - in this example creates a tag on field VESSEL */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxcreate(dbf, | 	rc = dbxcreate(dbf, | ||
| Line 225: | Line 225: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXCREATE() - in this example creates a tag on field FLAG	 | + | 	/* DBXCREATE() - in this example creates a tag on field FLAG */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxcreate(dbf, | 	rc = dbxcreate(dbf, | ||
| Line 237: | Line 237: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXNOTAGS() - obtains the number of tagged indexes	 | + | 	/* DBXNOTAGS() - obtains the number of tagged indexes */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxnotags(dbx, ¬ags); | 	rc = dbxnotags(dbx, ¬ags); | ||
| Line 244: | Line 244: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXKEXPR() - obtains tagged index information	 | + | 	/* DBXKEXPR() - obtains tagged index information */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	for (i = 1; i <= notags; i++) { | 	for (i = 1; i <= notags; i++) { | ||
| Line 271: | Line 271: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXDROPTAGS() - Drop the specified tag	 | + | 	/* DBXDROPTAGS() - Drop the specified tag */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxdroptag(dbx, fields[5].fieldnm); | 	rc = dbxdroptag(dbx, fields[5].fieldnm); | ||
| Line 277: | Line 277: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXCLOSE() - close the active tagged index	 | + | 	/* DBXCLOSE() - close the active tagged index */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxclose(dbx); | 	rc = dbxclose(dbx); | ||
| Line 283: | Line 283: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBCLOSE() - close the active table	 | + | 	/* DBCLOSE() - close the active table */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbclose(dbf); | 	rc = dbclose(dbf); | ||
| Line 289: | Line 289: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Reopen the table in shared, read-write access mode	 | + | 	/* Reopen the table in shared, read-write access mode */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbfilemode(1, 0); | 	rc = dbfilemode(1, 0); | ||
| Line 296: | Line 296: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXOPEN() - example opens index file 'shipwreck.dbx' returning the  | + | 	/* DBXOPEN() - example opens index file 'shipwreck.dbx' returning the */ | 
| − | 	/* tagged index file descriptor (dbx) used in upcoming functions	 | + | 	/* tagged index file descriptor (dbx) used in upcoming functions */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxopen(dbf, "shipwreck.dbx", &dbx); | 	rc = dbxopen(dbf, "shipwreck.dbx", &dbx); | ||
| Line 303: | Line 303: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform basic index functions.	 | + | 	/* Perform basic index functions. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBICREAT() - in this example creates an index on field VESSEL	 | + | 	/* DBICREAT() - in this example creates an index on field VESSEL */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbicreat("shipwreck.ndx", fields[0].fieldnm, 18, 'C'); | 	rc = dbicreat("shipwreck.ndx", fields[0].fieldnm, 18, 'C'); | ||
| Line 313: | Line 313: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBIOPEN() - opens index to active status	 | + | 	/* DBIOPEN() - opens index to active status */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbiopen("shipwreck.ndx", &ndx); | 	rc = dbiopen("shipwreck.ndx", &ndx); | ||
| Line 319: | Line 319: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBKEXPR() - obtains index information	 | + | 	/* DBKEXPR() - obtains index information */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbkexpr(ndx, &keytype, keyexpr, &kexprlen, &keylen); | 	rc = dbkexpr(ndx, &keytype, keyexpr, &kexprlen, &keylen); | ||
| Line 329: | Line 329: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Lock data file	 | + | 	/* Lock data file */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dblockf(dbf); | 	rc = dblockf(dbf); | ||
| Line 339: | Line 339: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBLOCKI() - locks the index for following additions	 | + | 	/* DBLOCKI() - locks the index for following additions */ | 
| − | 	/* Synonymous with DBTLOCKI() which tests the lock	 | + | 	/* Synonymous with DBTLOCKI() which tests the lock */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dblocki(ndx); | 	rc = dblocki(ndx); | ||
| Line 346: | Line 346: | ||
| 		printf("Function: \tdblocki() \tindex locked successfully.\n"); | 		printf("Function: \tdblocki() \tindex locked successfully.\n"); | ||
| 	} else { | 	} else { | ||
| − | 		printf("Lock Failed. tError: % | + | 		printf("Lock Failed. tError: %d\n", rc); | 
| 	} | 	} | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform basic memo file functions.	 | + | 	/* Perform basic memo file functions. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBMCREAT() - creates a table memo file (if one needs creating)	 | + | 	/* DBMCREAT() - creates a table memo file (if one needs creating) */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbmcreat("shipwreck.dbt"); | 	rc = dbmcreat("shipwreck.dbt"); | ||
| Line 360: | Line 360: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBMOPEN() - opens an associated memo file	 | + | 	/* DBMOPEN() - opens an associated memo file */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbmopen("shipwreck.dbt", &dbt); | 	rc = dbmopen("shipwreck.dbt", &dbt); | ||
| Line 366: | Line 366: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform table input functions.	 | + | 	/* Perform table input functions. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBAPPEND() - appends a record to the end of the active table	 | + | 	/* DBAPPEND() - appends a record to the end of the active table */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbappend(dbf, text_table[0], &recno); | 	rc = dbappend(dbf, text_table[0], &recno); | ||
| Line 376: | Line 376: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBAKEY() - adds a key to the active index after dbappend()	 | + | 	/* DBAKEY() - adds a key to the active index after dbappend() */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbakey(ndx, "Santa Margarita   ", recno); | 	rc = dbakey(ndx, "Santa Margarita   ", recno); | ||
| Line 382: | Line 382: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXAKEY() - adds a key to the tagged index after dbappend()	 | + | 	/* DBXAKEY() - adds a key to the tagged index after dbappend() */ | 
| − | 	/* The tagged index file must be lock first	 | + | 	/* The tagged index file must be lock first */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxlocki(dbx); | 	rc = dbxlocki(dbx); | ||
| Line 393: | Line 393: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBFLUSH() - flushes the record cache to disk	 | + | 	/* DBFLUSH() - flushes the record cache to disk */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbflush(dbf); | 	rc = dbflush(dbf); | ||
| Line 399: | Line 399: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBIFLSH() - flushes the index cache to disk	 | + | 	/* DBIFLSH() - flushes the index cache to disk */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbiflsh(ndx); | 	rc = dbiflsh(ndx); | ||
| Line 405: | Line 405: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXFLSH() - flushes the tagged index cache to disk	 | + | 	/* DBXFLSH() - flushes the tagged index cache to disk */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxflsh(dbx); | 	rc = dbxflsh(dbx); | ||
| Line 411: | Line 411: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBGETR() - retrieves a record	 | + | 	/* DBGETR() - retrieves a record */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbgetr(dbf, (long) 1, record, &status); | 	rc = dbgetr(dbf, (long) 1, record, &status); | ||
| Line 418: | Line 418: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBPUTM() - put the memo information	 | + | 	/* DBPUTM() - put the memo information */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbputm(dbt, "128' 30% coral cover.", &record[53]); | 	rc = dbputm(dbt, "128' 30% coral cover.", &record[53]); | ||
| Line 424: | Line 424: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBUPDR() - updates the record in buffer 'record'	 | + | 	/* DBUPDR() - updates the record in buffer 'record' */ | 
| − | 	/* As of v8.0 this function automatically updates any attached indexes.	 | + | 	/* As of v8.0 this function automatically updates any attached indexes. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbupdr(dbf, (long) 1, record); | 	rc = dbupdr(dbf, (long) 1, record); | ||
| Line 431: | Line 431: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBGETM() - this example extracts the memo from the record buffer	 | + | 	/* DBGETM() - this example extracts the memo from the record buffer */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbgetm(dbt, &record[53], tmpbuf, 0); | 	rc = dbgetm(dbt, &record[53], tmpbuf, 0); | ||
| Line 437: | Line 437: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBUPDM() - Updates the memo field for this record	 | + | 	/* DBUPDM() - Updates the memo field for this record */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	strcat(tmpbuf, " Appending this string to the end of memo..."); | 	strcat(tmpbuf, " Appending this string to the end of memo..."); | ||
| Line 444: | Line 444: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBPUTRK() - the following example adds a record and index	 | + | 	/* DBPUTRK() - the following example adds a record and index */ | 
| − | 	/* to the respective files.	 | + | 	/* to the respective files. */ | 
| − | 	/* DBRECOUT() - scatter the record stored in buffer 'record' to a two	 | + | 	/* DBRECOUT() - scatter the record stored in buffer 'record' to a two */ | 
| − | 	/* dimensional character array 'fldbuf'	 | + | 	/* dimensional character array 'fldbuf' */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Read in 6 more records	 | + | 	/* Read in 6 more records */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| Line 462: | Line 462: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBFLUSH() - flushes the record cache to disk	 | + | 	/* DBFLUSH() - flushes the record cache to disk */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbflush(dbf); | 	rc = dbflush(dbf); | ||
| Line 468: | Line 468: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBIFLSH() - flushes the index cache to disk	 | + | 	/* DBIFLSH() - flushes the index cache to disk */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbiflsh(ndx); | 	rc = dbiflsh(ndx); | ||
| Line 474: | Line 474: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXFLSH() - flushes the tagged index cache to disk	 | + | 	/* DBXFLSH() - flushes the tagged index cache to disk */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxflsh(dbx); | 	rc = dbxflsh(dbx); | ||
| Line 480: | Line 480: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBFIELD() - this example extracts the field 'VESSEL' from the	 | + | 	/* DBFIELD() - this example extracts the field 'VESSEL' from the */ | 
| − | 	/* record (#5) stored in buffer 'record'	 | + | 	/* record (#5) stored in buffer 'record' */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbgetr(dbf, (long) 5, record, &status); | 	rc = dbgetr(dbf, (long) 5, record, &status); | ||
| Line 490: | Line 490: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Modify a single field in record number 5	 | + | 	/* Modify a single field in record number 5 */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBSCATTER() - scatter the record into specified field buffers	 | + | 	/* DBSCATTER() - scatter the record into specified field buffers */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbscatter(dbf, record, fldbuf); | 	rc = dbscatter(dbf, record, fldbuf); | ||
| Line 505: | Line 505: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBGATHER() - gather the field buffers and place the contents	 | + | 	/* DBGATHER() - gather the field buffers and place the contents */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbgather(dbf, record, fldbuf); | 	rc = dbgather(dbf, record, fldbuf); | ||
| Line 515: | Line 515: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform index / index conversion functions.	 | + | 	/* Perform index / index conversion functions. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBREWIND() - position the record pointer to the top of the index file	 | + | 	/* DBREWIND() - position the record pointer to the top of the index file */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbrewind(ndx); | 	rc = dbrewind(ndx); | ||
| Line 525: | Line 525: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBGETNR() - after 'rewinding' to the top of the table, the first record	 | + | 	/* DBGETNR() - after 'rewinding' to the top of the table, the first record */ | 
| − | 	/* can be retrieved with dbgetnr() using the active key	 | + | 	/* can be retrieved with dbgetnr() using the active key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	for (i = 1; i <= 6; i++) { | 	for (i = 1; i <= 6; i++) { | ||
| Line 535: | Line 535: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBNKEY() - get next key	 | + | 	/* DBNKEY() - get next key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbnkey(ndx, nextkey[0], rec_no); | 	rc = dbnkey(ndx, nextkey[0], rec_no); | ||
| Line 542: | Line 542: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBFWD() - position the pointer to the end of the table	 | + | 	/* DBFWD() - position the pointer to the end of the table */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbfwd(ndx); | 	rc = dbfwd(ndx); | ||
| Line 548: | Line 548: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBPKEY() - get previous key	 | + | 	/* DBPKEY() - get previous key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbpkey(ndx, nextkey[0], rec_no); | 	rc = dbpkey(ndx, nextkey[0], rec_no); | ||
| Line 555: | Line 555: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBGETPR() - obtain the previous record by key	 | + | 	/* DBGETPR() - obtain the previous record by key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbgetpr(dbf, ndx, record, &status); | 	rc = dbgetpr(dbf, ndx, record, &status); | ||
| Line 562: | Line 562: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Rewind the index	 | + | 	/* Rewind the index */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	dbrewind(ndx); | 	dbrewind(ndx); | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform table retrieval functions using indexes.	 | + | 	/* Perform table retrieval functions using indexes. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBTKEY() - translates supplied key to record number	 | + | 	/* DBTKEY() - translates supplied key to record number */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbtkey(ndx, "Santa Rosa	  ", &recno); | 	rc = dbtkey(ndx, "Santa Rosa	  ", &recno); | ||
| Line 578: | Line 578: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBGETRK() - obtains the record from the specified key	 | + | 	/* DBGETRK() - obtains the record from the specified key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbgetrk(dbf, ndx, "Santa Rosa		", record, &status); | 	rc = dbgetrk(dbf, ndx, "Santa Rosa		", record, &status); | ||
| Line 585: | Line 585: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBCKEY() - read the current key	 | + | 	/* DBCKEY() - read the current key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbckey(ndx, key, &recno); | 	rc = dbckey(ndx, key, &recno); | ||
| Line 592: | Line 592: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform tagged index functions.	 | + | 	/* Perform tagged index functions. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXREWIND() - position the pointer to the top of the index file	 | + | 	/* DBXREWIND() - position the pointer to the top of the index file */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxrewind(dbx); | 	rc = dbxrewind(dbx); | ||
| Line 602: | Line 602: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXGETNR() - after 'rewinding' to the top of the table, the first record	 | + | 	/* DBXGETNR() - after 'rewinding' to the top of the table, the first record */ | 
| − | 	/* can be retrieved with dbgetnr() using the active key	 | + | 	/* can be retrieved with dbgetnr() using the active key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	for (i = 1; i <= 6; i++) { | 	for (i = 1; i <= 6; i++) { | ||
| Line 612: | Line 612: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXNKEY() - get next key	 | + | 	/* DBXNKEY() - get next key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxnkey(dbx, nextkey[0], rec_no); | 	rc = dbxnkey(dbx, nextkey[0], rec_no); | ||
| Line 619: | Line 619: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXFWD() - position the pointer to the end of the table	 | + | 	/* DBXFWD() - position the pointer to the end of the table */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxfwd(dbx); | 	rc = dbxfwd(dbx); | ||
| Line 625: | Line 625: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXPKEY() - get previous key	 | + | 	/* DBXPKEY() - get previous key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxpkey(dbx, nextkey[0], rec_no); | 	rc = dbxpkey(dbx, nextkey[0], rec_no); | ||
| Line 632: | Line 632: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXGETPR() - obtain the previous record by key	 | + | 	/* DBXGETPR() - obtain the previous record by key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxgetpr(dbf, dbx, record, &status); | 	rc = dbxgetpr(dbf, dbx, record, &status); | ||
| Line 639: | Line 639: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Rewind the index	 | + | 	/* Rewind the index */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	dbxrewind(dbx); | 	dbxrewind(dbx); | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform table retrieval functions using tagged indexes.	 | + | 	/* Perform table retrieval functions using tagged indexes.*/ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBTKEY() - translates supplied key to record number	 | + | 	/* DBTKEY() - translates supplied key to record number */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbtkey(ndx, "Santa Rosa	  ", &recno); | 	rc = dbtkey(ndx, "Santa Rosa	  ", &recno); | ||
| Line 655: | Line 655: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXGETRK() - obtains the record from the specified key	 | + | 	/* DBXGETRK() - obtains the record from the specified key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxgetrk(dbf, dbx, "Santa Rosa	   ", record, &status); | 	rc = dbxgetrk(dbf, dbx, "Santa Rosa	   ", record, &status); | ||
| Line 662: | Line 662: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXCKEY() - read the current key	 | + | 	/* DBXCKEY() - read the current key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxckey(dbx, key, &recno); | 	rc = dbxckey(dbx, key, &recno); | ||
| Line 669: | Line 669: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform field level functions including index/ASCII functions.	 | + | 	/* Perform field level functions including index/ASCII functions. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBATOFLD() - converts ASCII string to Recital field	 | + | 	/* DBATOFLD() - converts ASCII string to Recital field */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbatofld("23.3", 4, 1, tmpbuf); | 	rc = dbatofld("23.3", 4, 1, tmpbuf); | ||
| Line 679: | Line 679: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBATOKEY() - converts a ASCII string to Recital date key	 | + | 	/* DBATOKEY() - converts a ASCII string to Recital date key */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	key[0] = 'D'; | 	key[0] = 'D'; | ||
| Line 686: | Line 686: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBFLDTOA() - converts extracted field to ASCII	 | + | 	/* DBFLDTOA() - converts extracted field to ASCII */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbfldtoa(record + 18, 4, tmpbuf); | 	rc = dbfldtoa(record + 18, 4, tmpbuf); | ||
| Line 692: | Line 692: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBSTRCPY() - formats character strings to Recital types	 | + | 	/* DBSTRCPY() - formats character strings to Recital types */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	dbstrcpy(key, 'L', 10, "  320000"); | 	dbstrcpy(key, 'L', 10, "  320000"); | ||
| Line 698: | Line 698: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBSTRING() - formats non-'C' strings to C strings (null term)	 | + | 	/* DBSTRING() - formats non-'C' strings to C strings (null term) */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	dbstring("Santa Pedro", 13, tmpbuf); | 	dbstring("Santa Pedro", 13, tmpbuf); | ||
| Line 704: | Line 704: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBKEYTOA() - converts an extracted key to ASCII	 | + | 	/* DBKEYTOA() - converts an extracted key to ASCII */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	tmpbuf[0] = 0; /* Number of decimal places */ | 	tmpbuf[0] = 0; /* Number of decimal places */ | ||
| Line 712: | Line 712: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform record/index deletion and file access	 | + | 	/* Perform record/index deletion and file access */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBSIZE() - retrieve the size of the table	 | + | 	/* DBSIZE() - retrieve the size of the table */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbsize(dbf, &db_size); | 	rc = dbsize(dbf, &db_size); | ||
| Line 723: | Line 723: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBPUTR() - adds a record to the end of the table	 | + | 	/* DBPUTR() - adds a record to the end of the table */ | 
| − | 	/* You can also 'insert' a record using this function	 | + | 	/* You can also 'insert' a record using this function */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbputr(dbf, db_size + 1L, text_table[7]); | 	rc = dbputr(dbf, db_size + 1L, text_table[7]); | ||
| Line 731: | Line 731: | ||
| 	errorproc("dbakey()", "key added.", rc); | 	errorproc("dbakey()", "key added.", rc); | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Add record to the Production Index as well  | + | 	/* Add record to the Production Index as well */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxakey(dbx, db_size + 1L); | 	rc = dbxakey(dbx, db_size + 1L); | ||
| Line 741: | Line 741: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBDELETE() - mark a record (number 8) for deletion	 | + | 	/* DBDELETE() - mark a record (number 8) for deletion */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbdelete(dbf, 8L); | 	rc = dbdelete(dbf, 8L); | ||
| Line 747: | Line 747: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBRECALL() - recall a record marked for deletion (number 8)	 | + | 	/* DBRECALL() - recall a record marked for deletion (number 8) */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbrecall(dbf, 8L); | 	rc = dbrecall(dbf, 8L); | ||
| Line 753: | Line 753: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBRMVKEY() - physically remove a key.  As of v8.0, this function	 | + | 	/* DBRMVKEY() - physically remove a key.  As of v8.0, this function */ | 
| − | 	/* is not permitted on tables opened shareable.	 | + | 	/* is not permitted on tables opened shareable. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* rc = dbrmvkey(ndx, "Unknown Vessel	", db_size+1L);	 | + | 	/* rc = dbrmvkey(ndx, "Unknown Vessel	", db_size+1L); */ | 
| − | 	/* errorproc("dbrmvkey()", "key physically removed.", rc);	 | + | 	/* errorproc("dbrmvkey()", "key physically removed.", rc); */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBRMVR() - physically remove a data record. As of v8.0 this	 | + | 	/* DBRMVR() - physically remove a data record. As of v8.0 this */ | 
| − | 	/* function is not permitted on tables opened shareable.	 | + | 	/* function is not permitted on tables opened shareable. */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* rc = dbrmvr(dbf, db_size+1L);	 | + | 	/* rc = dbrmvr(dbf, db_size+1L); */ | 
| − | 	/* errorproc("dbrmvr()", "record 7 physically removed.", rc);	 | + | 	/* errorproc("dbrmvr()", "record 7 physically removed.", rc); */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBUNLOCKF() - unlocks a table file	 | + | 	/* DBUNLOCKF() - unlocks a table file */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbunlockf(dbf); | 	rc = dbunlockf(dbf); | ||
| 	if (rc == SUCCESS) { | 	if (rc == SUCCESS) { | ||
| − | 		printf("Function: \tdbunlockf() tFile unlocked successfully\n"); | + | 		printf("Function: \tdbunlockf() \tFile unlocked successfully\n"); | 
| 	} else { | 	} else { | ||
| 		printf("Unlock Failed. \tError: %d\n", rc); | 		printf("Unlock Failed. \tError: %d\n", rc); | ||
| Line 777: | Line 777: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBUNLOCKI() - unlocks an index file	 | + | 	/* DBUNLOCKI() - unlocks an index file */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbunlocki(ndx); | 	rc = dbunlocki(ndx); | ||
| Line 787: | Line 787: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBLOCKR() - tests available record locking in a multi user	 | + | 	/* DBLOCKR() - tests available record locking in a multi user */ | 
| − | 	/* environment.  Same as DBTLOCKR() in multi access	 | + | 	/* environment.  Same as DBTLOCKR() in multi access */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dblockr(dbf, (long) 7); | 	rc = dblockr(dbf, (long) 7); | ||
| Line 794: | Line 794: | ||
| 		printf("Function: \tdblockr() \trecord locked successfully.\n"); | 		printf("Function: \tdblockr() \trecord locked successfully.\n"); | ||
| 	} else { | 	} else { | ||
| − | 		printf("Lock Failed. tError: % | + | 		printf("Lock Failed. tError: %d\n", rc); | 
| 	} | 	} | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBUNLOCKR() - unlocks a table Record	 | + | 	/* DBUNLOCKR() - unlocks a table Record */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbunlockr(dbf, (long) 7); | 	rc = dbunlockr(dbf, (long) 7); | ||
| Line 804: | Line 804: | ||
| 		printf("Function \tdbunlockr(): \trecord unlocked successfully\n"); | 		printf("Function \tdbunlockr(): \trecord unlocked successfully\n"); | ||
| 	} else { | 	} else { | ||
| − | 		printf("Unlock Failed. tError: %d\n", rc); | + | 		printf("Unlock Failed. \tError: %d\n", rc); | 
| 	} | 	} | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform record/index close functions	 | + | 	/* Perform record/index close functions */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBICLOSE() - close the active index	 | + | 	/* DBICLOSE() - close the active index */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbiclose(ndx); | 	rc = dbiclose(ndx); | ||
| Line 818: | Line 818: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBXCLOSE() - close the active tagged index	 | + | 	/* DBXCLOSE() - close the active tagged index */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbxclose(dbx); | 	rc = dbxclose(dbx); | ||
| Line 824: | Line 824: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBCLOSE() - close the active table	 | + | 	/* DBCLOSE() - close the active table */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbclose(dbf); | 	rc = dbclose(dbf); | ||
| Line 830: | Line 830: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBMCLOSE() - close the active memo table	 | + | 	/* DBMCLOSE() - close the active memo table */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	rc = dbmclose(dbt); | 	rc = dbmclose(dbt); | ||
| Line 836: | Line 836: | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* Perform miscellaneous Recital/Library functions	 | + | 	/* Perform miscellaneous Recital/Library functions */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| − | 	/* DBONERROR() - enables/disables (1/0) recovery from errors	 | + | 	/* DBONERROR() - enables/disables (1/0) recovery from errors */ | 
| 	/*---------------------------------------------------------------------------------------*/ | 	/*---------------------------------------------------------------------------------------*/ | ||
| 	dbonerror(0); /* Recovery disabled */ | 	dbonerror(0); /* Recovery disabled */ | ||
| Line 852: | Line 852: | ||
| /*-----------------------------------------------------------------------------------------*/ | /*-----------------------------------------------------------------------------------------*/ | ||
| − | /* This procedure handles the return codes from called RECITAL/library	 | + | /* This procedure handles the return codes from called RECITAL/library */ | 
| − | /* functions.  Intended to eliminate cryptic  'if...else...' statements	 | + | /* functions.  Intended to eliminate cryptic  'if...else...' statements */ | 
| − | /* following library calls.	 | + | /* following library calls. */ | 
| /*-----------------------------------------------------------------------------------------*/ | /*-----------------------------------------------------------------------------------------*/ | ||
Revision as of 11:10, 6 May 2009
The following program is written in 'C' as an example program using the RECITAL/Library functions. This file is stored in the SDK dbl sub-directory and is called "dblsamp.c".
/*#================================================== *# Copyright (C) 1988-2009 Recital Corporation Inc. *# As an unpublished licensed proprietary work. *# All rights reserved worldwide. *# *# This program may be freely copied and used as a template for user *# programs which make use of the Recital/Library in so long as the above *# copyright notice is included. *# #=================================================== * *MODULE : dblsamp.c * *PURPOSE : Recital Database Library sample program. * *AUTHOR : RECITAL CORPORATION * *==================================================*/ #include <stdio.h> #include "dbl.h" /* Recital Library include file */ #include "dblproto.h" /* Recital Library prototype file */ extern int g_disable_txcount; /*-----------------------------------------------------------------------------------------*/ /* Table structure for db to be constructed. */ /* Structure dBFIELD defined in dbl.h */ /*-----------------------------------------------------------------------------------------*/ static dBFIELD fields[7] = { "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, "MEMO", 'M', 4, 0, 0 }; /*-----------------------------------------------------------------------------------------*/ /* Static Error Handling procedure. */ /*-----------------------------------------------------------------------------------------*/ static int errorproc(); /*-----------------------------------------------------------------------------------------*/ /* Table records to add. */ /*-----------------------------------------------------------------------------------------*/ static char *text_table[] = { "Santa Margarita 80.027.5 700000095/01/01Spanish ", "Santa Rosa 81.824.8 3000000032/01/01Spanish ", "Unknown galleon 83.123.0 015/01/01Spanish ", "Jessie 97.127.4 10000075/01/01U.S. ", "Lea 96.227.8 100000080/01/01U.S. ", "S.J. Lee 96.926.9 20000075/01/01U.S. ", "Genovase 78.418.4 185000030/01/01Spanish ", "Unknown Vessel 77.517.9 075/01/01U.S. " }; /*-----------------------------------------------------------------------------------------*/ /* Main program entry point. */ /*-----------------------------------------------------------------------------------------*/ main() { int rc; /* Return Code for error handling */ char *dbf; /* File descriptor for table */ char *dbx; /* File descriptor for tagged index */ char *ndx; /* File descriptor for index */ char *dbt; /* File descriptor for memo file */ char record[58]; /* Array of char for records */ char keytype; /* Variable for varying keytype */ char key[21]; /* Storage location for keys */ char tagname[21]; /* Storage location for tag name */ char keyexpr[512]; /* Storage location for key expr */ char forexpr[512]; /* Storage location for for expr */ int kexprlen; /* The key expression length */ int keylen; /* The key length */ dBFIELD dbfields[128]; /* Storage location for field names */ FLDNUM fieldcount; /* Number of fields to create */ int fldpos[128]; /* Fields position buffer */ char flddes[128][26]; /* Fields description buffer */ char tmpbuf[81]; /* Temporary storage buffer */ char fldbuf[128][256]; /* Field buffer (recin()/out()) */ char nextkey[10][20]; /* Key buffers (dbnkey()) */ char status; /* Deleted record flag */ long recno; /* Table record variable */ long rec_no[10]; /* Record number array (dbnkey()) */ long db_size; /* Size of table variable */ int reclen; /* Table record length variable */ char month; /* Month variable */ char day; /* Day variable */ char year; /* Year variable */ FLDNUM nofields; /* Number of table fields variable */ int i; /* Loop control variable */ double n; /* Double numeric variable */ int keyunique; /* Boolean for unique tag key */ int keydescend; /* Boolean for descending tag key */ int notags; /* number of tags in a dbx file */ /*---------------------------------------------------------------------------------------*/ /* Perform operational Library environment functions. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBDCACHE() - this example allocates a 100 record caching area */ /*---------------------------------------------------------------------------------------*/ rc = dbdcache(100); errorproc("dbdcache()", "table cache specified.", rc); /*---------------------------------------------------------------------------------------*/ /* DBICACHE() - this example allocates 51200 bytes for index caching */ /*---------------------------------------------------------------------------------------*/ rc = dbicache(100); errorproc("dbicache()", "index cache specified.", rc); /*---------------------------------------------------------------------------------------*/ /* DBFILEMODE() - shared, read write access */ /*---------------------------------------------------------------------------------------*/ rc = dbfilemode(1, 0); errorproc("dbfilemode()", "file mode specified.", rc); /*---------------------------------------------------------------------------------------*/ /* DBSET() - Set exact index match to true */ /*---------------------------------------------------------------------------------------*/ rc = dbset("EXACT", 1); errorproc("dbset()", "filemode specified.", rc); /*---------------------------------------------------------------------------------------*/ /* Perform basic table functions. */ /*---------------------------------------------------------------------------------------*/ fieldcount = 7; /* Number of Fields */ /*---------------------------------------------------------------------------------------*/ /* DBCREAT() - this example creates a table according to the 'dBFIELD' */ /* array fields. */ /*---------------------------------------------------------------------------------------*/ rc = dbcreat("shipwreck.dbf", fieldcount, fields); errorproc("dbcreat()", "database created.", rc); /*---------------------------------------------------------------------------------------*/ /* DBCREATX() - Enables the addition of table field descriptions. */ /*---------------------------------------------------------------------------------------*/ strcpy(flddes[0], "The vessel's name."); strcpy(flddes[1], "The latitude."); strcpy(flddes[2], "The longitude."); strcpy(flddes[3], "The value."); strcpy(flddes[4], "The date."); strcpy(flddes[5], "The vessel's flag."); strcpy(flddes[6], "Notes."); rc = dbcreatx("shipwreck.dbf", fieldcount, fields, flddes); /*---------------------------------------------------------------------------------------*/ /* DBOPEN() - example opens table 'shipwreck.dbf' returning the table */ /* file descriptor (dbf) used in upcoming functions */ /*---------------------------------------------------------------------------------------*/ rc = dbopen("shipwreck.dbf", &dbf); errorproc("dbopen()", "table opened.", rc); /*---------------------------------------------------------------------------------------*/ /* DBGETF() - obtain table information on the table referenced by the */ /* 'dbf' file descriptor. */ /*---------------------------------------------------------------------------------------*/ rc = dbgetf(dbf, &reclen, &month, &day, &year, &nofields, dbfields); errorproc("dbgetf()", "information retrieved.", rc); printf("\t\tRecord length in bytes: %d\n", reclen); printf("\t\tCreation date: \t\t%d/%d/%d\n", month, day, year); printf("\t\tNumber of fields: \t%d\n", nofields); /*---------------------------------------------------------------------------------------*/ /* DBGETFX() - obtain extended table information including the numeric */ /* field location array (fldpos) and the field descriptions (flddes). */ /*---------------------------------------------------------------------------------------*/ rc = dbgetfx(dbf, &reclen, &month, &day, &year, &nofields, dbfields, fldpos, flddes); errorproc("dbgetfx()", "extra information retrieved.", rc); printf("\t\tLocation of fields in buffer: \t%d,%d,%d,%d,%d,%d\n", fldpos[1], fldpos[2], fldpos[3], fldpos[4], fldpos[5], fldpos[6]); /*---------------------------------------------------------------------------------------*/ /* DBLOCKF() - locks the table for the additions that follow. */ /* Synonymous with DBTLOCKF(), which tests the lock */ /*---------------------------------------------------------------------------------------*/ rc = dblockf(dbf); if (rc == SUCCESS) { printf("Function: \tdblockf() \tfile locked successfully.\n"); } else { printf("Lock Failed. tError: %d\n", rc); } /*---------------------------------------------------------------------------------------*/ /* DBCLOSE() - close the active table */ /*---------------------------------------------------------------------------------------*/ rc = dbclose(dbf); errorproc("dbclose()", "table closed.", rc); /*---------------------------------------------------------------------------------------*/ /* Exclusive read write access of the table is required to create or delete */ /* tags. */ /*---------------------------------------------------------------------------------------*/ rc = dbfilemode(0, 0); rc = dbopen("shipwreck.dbf", &dbf); errorproc("dbopen()", "table opened in exclusive mode.", rc); /*---------------------------------------------------------------------------------------*/ /* Perform basic tagged index functions. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBXCREATE() - in this example creates a tag on field VESSEL */ /*---------------------------------------------------------------------------------------*/ rc = dbxcreate(dbf, fields[0].fieldnm, /* "VESSEL", */ &dbx, fields[0].fieldnm, /* "VESSEL", */ NULL, 0, 0); errorproc("dbxcreate()", "tag created", rc); /*---------------------------------------------------------------------------------------*/ /* DBXCREATE() - in this example creates a tag on field FLAG */ /*---------------------------------------------------------------------------------------*/ rc = dbxcreate(dbf, fields[5].fieldnm, /* "FLAG", */ &dbx, fields[5].fieldnm, /* "FLAG", */ NULL, 0, 0); errorproc("dbxcreate()", "tag created", rc); /*---------------------------------------------------------------------------------------*/ /* DBXNOTAGS() - obtains the number of tagged indexes */ /*---------------------------------------------------------------------------------------*/ rc = dbxnotags(dbx, ¬ags); errorproc("dbxnotags()", "tagged index count obtained.", rc); printf("\t Key count: \t%d\n", notags); /*---------------------------------------------------------------------------------------*/ /* DBXKEXPR() - obtains tagged index information */ /*---------------------------------------------------------------------------------------*/ for (i = 1; i <= notags; i++) { rc = dbxkexpr(dbx, &i, tagname, &keytype, keyexpr, forexpr, &kexprlen, &keylen, &keyunique, &keydescend); errorproc("dbxkexpr()", "key information retrieved.", rc); printf("\t Key number: \t%d\n", i); printf("\t Key name: \t%s\n", tagname); printf("\t Key type: \t%c\n", keytype); printf("\t Key expression: %s\n", keyexpr); printf("\t Key length: %d Expression length: %d\n", kexprlen, keylen); printf("\t For expression: %s\n", forexpr); printf("\t Key unique: \t%s\n", keyunique ? "Yes" : "No"); printf("\t Key descending: \t%s\n", keydescend ? "Yes" : "No"); } /*---------------------------------------------------------------------------------------*/ /* DBXDROPTAGS() - Drop the specified tag */ /*---------------------------------------------------------------------------------------*/ rc = dbxdroptag(dbx, fields[5].fieldnm); errorproc("dbxdroptag()", "tagged index 'FLAG' dropped.", rc); /*---------------------------------------------------------------------------------------*/ /* DBXCLOSE() - close the active tagged index */ /*---------------------------------------------------------------------------------------*/ rc = dbxclose(dbx); errorproc("dbxclose()", "tagged index closed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBCLOSE() - close the active table */ /*---------------------------------------------------------------------------------------*/ rc = dbclose(dbf); errorproc("dbclose()", "table closed.", rc); /*---------------------------------------------------------------------------------------*/ /* Reopen the table in shared, read-write access mode */ /*---------------------------------------------------------------------------------------*/ rc = dbfilemode(1, 0); rc = dbopen("shipwreck.dbf", &dbf); errorproc("dbopen()", "table opened in shared mode.", rc); /*---------------------------------------------------------------------------------------*/ /* DBXOPEN() - example opens index file 'shipwreck.dbx' returning the */ /* tagged index file descriptor (dbx) used in upcoming functions */ /*---------------------------------------------------------------------------------------*/ rc = dbxopen(dbf, "shipwreck.dbx", &dbx); errorproc("dbxopen()", "tagged index opened.", rc); /*---------------------------------------------------------------------------------------*/ /* Perform basic index functions. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBICREAT() - in this example creates an index on field VESSEL */ /*---------------------------------------------------------------------------------------*/ rc = dbicreat("shipwreck.ndx", fields[0].fieldnm, 18, 'C'); errorproc("dbicreat()", "index created", rc); /*---------------------------------------------------------------------------------------*/ /* DBIOPEN() - opens index to active status */ /*---------------------------------------------------------------------------------------*/ rc = dbiopen("shipwreck.ndx", &ndx); errorproc("dbiopen()", "index opened.", rc); /*---------------------------------------------------------------------------------------*/ /* DBKEXPR() - obtains index information */ /*---------------------------------------------------------------------------------------*/ rc = dbkexpr(ndx, &keytype, keyexpr, &kexprlen, &keylen); errorproc("dbkexpr()", "key information retrieved.", rc); printf("\t Key type: \t%c\n", keytype); printf("\t Key expression: %s\n", keyexpr); printf("\t Key length: %d Expression length: %d\n", kexprlen, keylen); /*---------------------------------------------------------------------------------------*/ /* Lock data file */ /*---------------------------------------------------------------------------------------*/ rc = dblockf(dbf); if (rc == SUCCESS) { printf("Function: \tdblockf() \tfile locked successfully.\n"); } else { printf("Lock Failed. \tError: %d\n", rc); } /*---------------------------------------------------------------------------------------*/ /* DBLOCKI() - locks the index for following additions */ /* Synonymous with DBTLOCKI() which tests the lock */ /*---------------------------------------------------------------------------------------*/ rc = dblocki(ndx); if (rc == SUCCESS) { printf("Function: \tdblocki() \tindex locked successfully.\n"); } else { printf("Lock Failed. tError: %d\n", rc); } /*---------------------------------------------------------------------------------------*/ /* Perform basic memo file functions. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBMCREAT() - creates a table memo file (if one needs creating) */ /*---------------------------------------------------------------------------------------*/ rc = dbmcreat("shipwreck.dbt"); errorproc("dbmcreat()", "memo file create", rc); /*---------------------------------------------------------------------------------------*/ /* DBMOPEN() - opens an associated memo file */ /*---------------------------------------------------------------------------------------*/ rc = dbmopen("shipwreck.dbt", &dbt); errorproc("dbmopen()", "memo file open.", rc); /*---------------------------------------------------------------------------------------*/ /* Perform table input functions. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBAPPEND() - appends a record to the end of the active table */ /*---------------------------------------------------------------------------------------*/ rc = dbappend(dbf, text_table[0], &recno); errorproc("dbappend()", "record appended.", rc); /*---------------------------------------------------------------------------------------*/ /* DBAKEY() - adds a key to the active index after dbappend() */ /*---------------------------------------------------------------------------------------*/ rc = dbakey(ndx, "Santa Margarita ", recno); errorproc("dbakey()", "key added.", rc); /*---------------------------------------------------------------------------------------*/ /* DBXAKEY() - adds a key to the tagged index after dbappend() */ /* The tagged index file must be lock first */ /*---------------------------------------------------------------------------------------*/ rc = dbxlocki(dbx); errorproc("dbxlocki()", "tagged index file locked.", rc); rc = dbxakey(dbx, recno); errorproc("dbxakey()", "key added.", rc); rc = dbxunlocki(dbx); errorproc("dbxunlocki()", "tagged index file unlocked.", rc); /*---------------------------------------------------------------------------------------*/ /* DBFLUSH() - flushes the record cache to disk */ /*---------------------------------------------------------------------------------------*/ rc = dbflush(dbf); errorproc("dbflush()", "table cache flushed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBIFLSH() - flushes the index cache to disk */ /*---------------------------------------------------------------------------------------*/ rc = dbiflsh(ndx); errorproc("dbiflsh()", "index cache flushed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBXFLSH() - flushes the tagged index cache to disk */ /*---------------------------------------------------------------------------------------*/ rc = dbxflsh(dbx); errorproc("dbxflsh()", "Tagged index cache flushed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBGETR() - retrieves a record */ /*---------------------------------------------------------------------------------------*/ rc = dbgetr(dbf, (long) 1, record, &status); errorproc("dbgetr()", "record retrieved.", rc); printf("\t\t%s\n", record); /*---------------------------------------------------------------------------------------*/ /* DBPUTM() - put the memo information */ /*---------------------------------------------------------------------------------------*/ rc = dbputm(dbt, "128' 30% coral cover.", &record[53]); errorproc("dbputm", "memo placed in buffer", rc); /*---------------------------------------------------------------------------------------*/ /* DBUPDR() - updates the record in buffer 'record' */ /* As of v8.0 this function automatically updates any attached indexes. */ /*---------------------------------------------------------------------------------------*/ rc = dbupdr(dbf, (long) 1, record); errorproc("dbupdr()", "record updated.", rc); /*---------------------------------------------------------------------------------------*/ /* DBGETM() - this example extracts the memo from the record buffer */ /*---------------------------------------------------------------------------------------*/ rc = dbgetm(dbt, &record[53], tmpbuf, 0); errorproc("dbgetm()", "retrieved memo.", rc); /*---------------------------------------------------------------------------------------*/ /* DBUPDM() - Updates the memo field for this record */ /*---------------------------------------------------------------------------------------*/ strcat(tmpbuf, " Appending this string to the end of memo..."); rc = dbupdm(dbt, tmpbuf, &record[53], &record[53]); errorproc("dbupdm()", "updated memo.", rc); /*---------------------------------------------------------------------------------------*/ /* DBPUTRK() - the following example adds a record and index */ /* to the respective files. */ /* DBRECOUT() - scatter the record stored in buffer 'record' to a two */ /* dimensional character array 'fldbuf' */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* Read in 6 more records */ /*---------------------------------------------------------------------------------------*/ for (i = 1; i <= 6; i++) { dbrecout(dbf, dbfields, fldpos, text_table[i], fldbuf); rc = dbputrk(dbf, ndx, fldbuf[0], text_table[i]); errorproc("dbputrk()", "record placed by key.", rc); } errorproc("dbputrk()", "6 records placed by key.", rc); /*---------------------------------------------------------------------------------------*/ /* DBFLUSH() - flushes the record cache to disk */ /*---------------------------------------------------------------------------------------*/ rc = dbflush(dbf); errorproc("dbflush()", "table cache flushed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBIFLSH() - flushes the index cache to disk */ /*---------------------------------------------------------------------------------------*/ rc = dbiflsh(ndx); errorproc("dbiflsh()", "index cache flushed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBXFLSH() - flushes the tagged index cache to disk */ /*---------------------------------------------------------------------------------------*/ rc = dbxflsh(dbx); errorproc("dbxflsh()", "Tagged index cache flushed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBFIELD() - this example extracts the field 'VESSEL' from the */ /* record (#5) stored in buffer 'record' */ /*---------------------------------------------------------------------------------------*/ rc = dbgetr(dbf, (long) 5, record, &status); /* rc = dbfield( dbf, record, "FLAG", tmpbuf); */ rc = dbfield(dbf, record, fields[5].fieldnm, tmpbuf); errorproc("dbfield()", "field extracted.", rc); printf("\t\tFlag: \t%s\n", tmpbuf); /*---------------------------------------------------------------------------------------*/ /* Modify a single field in record number 5 */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBSCATTER() - scatter the record into specified field buffers */ /*---------------------------------------------------------------------------------------*/ rc = dbscatter(dbf, record, fldbuf); errorproc("dbscatter()", "record scattered.", rc); for (i = 0; i < nofields; i++) { fprintf(stdout, "\t\tfldbuf[%d]='%s'\n", i, fldbuf[i]); } strcpy(fldbuf[5], "Spanish"); /* Modify Field */ /*---------------------------------------------------------------------------------------*/ /* DBGATHER() - gather the field buffers and place the contents */ /*---------------------------------------------------------------------------------------*/ rc = dbgather(dbf, record, fldbuf); errorproc("dbgather()", "record gathered.", rc); printf("\t\t%s\n", record); rc = dbupdr(dbf, (long) 5, record); /* Finish Example */ errorproc("dbupdr()", "record updated.", rc); /*---------------------------------------------------------------------------------------*/ /* Perform index / index conversion functions. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBREWIND() - position the record pointer to the top of the index file */ /*---------------------------------------------------------------------------------------*/ rc = dbrewind(ndx); errorproc("dbrewind()", "index rewound.", rc); /*---------------------------------------------------------------------------------------*/ /* DBGETNR() - after 'rewinding' to the top of the table, the first record */ /* can be retrieved with dbgetnr() using the active key */ /*---------------------------------------------------------------------------------------*/ for (i = 1; i <= 6; i++) { rc = dbgetnr(dbf, ndx, record, &status); printf("\t\t%d: %s\n", i, record); } errorproc("dbgetnr()", "6 records retrieved by key.", rc); /*---------------------------------------------------------------------------------------*/ /* DBNKEY() - get next key */ /*---------------------------------------------------------------------------------------*/ rc = dbnkey(ndx, nextkey[0], rec_no); errorproc("dbnkey()", "next key retrieved.", rc); printf("\t\tnext key: \t%s\n", nextkey[0]); /*---------------------------------------------------------------------------------------*/ /* DBFWD() - position the pointer to the end of the table */ /*---------------------------------------------------------------------------------------*/ rc = dbfwd(ndx); errorproc("dbfwd()", "index pointer placed at bottom.", rc); /*---------------------------------------------------------------------------------------*/ /* DBPKEY() - get previous key */ /*---------------------------------------------------------------------------------------*/ rc = dbpkey(ndx, nextkey[0], rec_no); errorproc("dbpkey()", "previous key found.", rc); printf("\t\tprev key: \t%s\n", nextkey[0]); /*---------------------------------------------------------------------------------------*/ /* DBGETPR() - obtain the previous record by key */ /*---------------------------------------------------------------------------------------*/ rc = dbgetpr(dbf, ndx, record, &status); errorproc("dbgetpr()", "previous record (by key) retrieved.", rc); printf("Previous: \t%s\n", record); /*---------------------------------------------------------------------------------------*/ /* Rewind the index */ /*---------------------------------------------------------------------------------------*/ dbrewind(ndx); /*---------------------------------------------------------------------------------------*/ /* Perform table retrieval functions using indexes. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBTKEY() - translates supplied key to record number */ /*---------------------------------------------------------------------------------------*/ rc = dbtkey(ndx, "Santa Rosa ", &recno); errorproc("dbtkey()", "record number found by key.", rc); printf("\t\trecord number: \t%d\n", recno); /*---------------------------------------------------------------------------------------*/ /* DBGETRK() - obtains the record from the specified key */ /*---------------------------------------------------------------------------------------*/ rc = dbgetrk(dbf, ndx, "Santa Rosa ", record, &status); errorproc("dbgetrk()", "record retrieved by key.", rc); printf("\t\t%s\n", record); /*---------------------------------------------------------------------------------------*/ /* DBCKEY() - read the current key */ /*---------------------------------------------------------------------------------------*/ rc = dbckey(ndx, key, &recno); errorproc("dbckey()", "current key read.", rc); printf("\t\tcurrent key: \t%s\n", key); /*---------------------------------------------------------------------------------------*/ /* Perform tagged index functions. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBXREWIND() - position the pointer to the top of the index file */ /*---------------------------------------------------------------------------------------*/ rc = dbxrewind(dbx); errorproc("dbxrewind()", "Tagged index rewound.", rc); /*---------------------------------------------------------------------------------------*/ /* DBXGETNR() - after 'rewinding' to the top of the table, the first record */ /* can be retrieved with dbgetnr() using the active key */ /*---------------------------------------------------------------------------------------*/ 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); /*---------------------------------------------------------------------------------------*/ /* DBXNKEY() - get next key */ /*---------------------------------------------------------------------------------------*/ 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]); /*---------------------------------------------------------------------------------------*/ /* DBXFWD() - position the pointer to the end of the table */ /*---------------------------------------------------------------------------------------*/ rc = dbxfwd(dbx); errorproc("dbxfwd()", "index pointer placed at bottom.", rc); /*---------------------------------------------------------------------------------------*/ /* DBXPKEY() - get previous key */ /*---------------------------------------------------------------------------------------*/ 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]); /*---------------------------------------------------------------------------------------*/ /* DBXGETPR() - obtain the previous record by key */ /*---------------------------------------------------------------------------------------*/ rc = dbxgetpr(dbf, dbx, record, &status); errorproc("dbxgetpr()", "previous record (by key) retrieved.", rc); printf("Previous: \t%s\n", record); /*---------------------------------------------------------------------------------------*/ /* Rewind the index */ /*---------------------------------------------------------------------------------------*/ dbxrewind(dbx); /*---------------------------------------------------------------------------------------*/ /* Perform table retrieval functions using tagged indexes.*/ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBTKEY() - translates supplied key to record number */ /*---------------------------------------------------------------------------------------*/ rc = dbtkey(ndx, "Santa Rosa ", &recno); errorproc("dbtkey()", "record number found by key.", rc); printf("\t\trecord number: \t%d\n", recno); /*---------------------------------------------------------------------------------------*/ /* DBXGETRK() - obtains the record from the specified key */ /*---------------------------------------------------------------------------------------*/ rc = dbxgetrk(dbf, dbx, "Santa Rosa ", record, &status); errorproc("dbxgetrk()", "record retrieved by key.", rc); printf("\t\t%s\n", record); /*---------------------------------------------------------------------------------------*/ /* DBXCKEY() - read the current key */ /*---------------------------------------------------------------------------------------*/ rc = dbxckey(dbx, key, &recno); errorproc("dbxckey()", "current key read.", rc); printf("\t\tcurrent key: \t%s\n", key); /*---------------------------------------------------------------------------------------*/ /* Perform field level functions including index/ASCII functions. */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBATOFLD() - converts ASCII string to Recital field */ /*---------------------------------------------------------------------------------------*/ rc = dbatofld("23.3", 4, 1, tmpbuf); errorproc("dbatofld()", "string converted.", rc); /*---------------------------------------------------------------------------------------*/ /* DBATOKEY() - converts a ASCII string to Recital date key */ /*---------------------------------------------------------------------------------------*/ key[0] = 'D'; rc = dbatokey("16430411", key); errorproc("dbatokey()", "string converted to key.", rc); /*---------------------------------------------------------------------------------------*/ /* DBFLDTOA() - converts extracted field to ASCII */ /*---------------------------------------------------------------------------------------*/ rc = dbfldtoa(record + 18, 4, tmpbuf); errorproc("dbfldtoa()", "field converted.", rc); /*---------------------------------------------------------------------------------------*/ /* DBSTRCPY() - formats character strings to Recital types */ /*---------------------------------------------------------------------------------------*/ dbstrcpy(key, 'L', 10, " 320000"); printf("Function: \tdbstrcpy() \toutput: %s\n", key); /*---------------------------------------------------------------------------------------*/ /* DBSTRING() - formats non-'C' strings to C strings (null term) */ /*---------------------------------------------------------------------------------------*/ dbstring("Santa Pedro", 13, tmpbuf); printf("Function: \tdbstring() \toutput: %s\n", tmpbuf); /*---------------------------------------------------------------------------------------*/ /* DBKEYTOA() - converts an extracted key to ASCII */ /*---------------------------------------------------------------------------------------*/ tmpbuf[0] = 0; /* Number of decimal places */ tmpbuf[1] = 'N'; /* Key Type */ rc = dbkeytoa(key, tmpbuf); errorproc("dbkeytoa()", "key converted.", rc); /*---------------------------------------------------------------------------------------*/ /* Perform record/index deletion and file access */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBSIZE() - retrieve the size of the table */ /*---------------------------------------------------------------------------------------*/ rc = dbsize(dbf, &db_size); errorproc("dbsize()", "size retrieved.", rc); printf("\t No. of Records: \t%d\n", db_size); /*---------------------------------------------------------------------------------------*/ /* DBPUTR() - adds a record to the end of the table */ /* You can also 'insert' a record using this function */ /*---------------------------------------------------------------------------------------*/ rc = dbputr(dbf, db_size + 1L, text_table[7]); errorproc("dbputr()", "record placed.", rc); rc = dbakey(ndx, "Unknown Vessel ", db_size + 1L); errorproc("dbakey()", "key added.", rc); /*---------------------------------------------------------------------------------------*/ /* Add record to the Production Index as well */ /*---------------------------------------------------------------------------------------*/ rc = dbxakey(dbx, db_size + 1L); errorproc("dbxakey()", "key added.", rc); dbflush(dbf); dbiflsh(ndx); dbxflsh(dbx); /*---------------------------------------------------------------------------------------*/ /* DBDELETE() - mark a record (number 8) for deletion */ /*---------------------------------------------------------------------------------------*/ rc = dbdelete(dbf, 8L); errorproc("dbdelete()", "record 8 marked for deletion.", rc); /*---------------------------------------------------------------------------------------*/ /* DBRECALL() - recall a record marked for deletion (number 8) */ /*---------------------------------------------------------------------------------------*/ rc = dbrecall(dbf, 8L); errorproc("dbrecall()", "record 8 recalled.", rc); /*---------------------------------------------------------------------------------------*/ /* DBRMVKEY() - physically remove a key. As of v8.0, this function */ /* is not permitted on tables opened shareable. */ /*---------------------------------------------------------------------------------------*/ /* rc = dbrmvkey(ndx, "Unknown Vessel ", db_size+1L); */ /* errorproc("dbrmvkey()", "key physically removed.", rc); */ /*---------------------------------------------------------------------------------------*/ /* DBRMVR() - physically remove a data record. As of v8.0 this */ /* function is not permitted on tables opened shareable. */ /*---------------------------------------------------------------------------------------*/ /* rc = dbrmvr(dbf, db_size+1L); */ /* errorproc("dbrmvr()", "record 7 physically removed.", rc); */ /*---------------------------------------------------------------------------------------*/ /* DBUNLOCKF() - unlocks a table file */ /*---------------------------------------------------------------------------------------*/ rc = dbunlockf(dbf); if (rc == SUCCESS) { printf("Function: \tdbunlockf() \tFile unlocked successfully\n"); } else { printf("Unlock Failed. \tError: %d\n", rc); } /*---------------------------------------------------------------------------------------*/ /* DBUNLOCKI() - unlocks an index file */ /*---------------------------------------------------------------------------------------*/ rc = dbunlocki(ndx); if (rc == SUCCESS) { printf("Function: \tdbunlocki() \tFile unlocked successfully\n"); } else { printf("Unlock Failed. \tError: %d\n", rc); } /*---------------------------------------------------------------------------------------*/ /* DBLOCKR() - tests available record locking in a multi user */ /* environment. Same as DBTLOCKR() in multi access */ /*---------------------------------------------------------------------------------------*/ rc = dblockr(dbf, (long) 7); if (rc == SUCCESS) { printf("Function: \tdblockr() \trecord locked successfully.\n"); } else { printf("Lock Failed. tError: %d\n", rc); } /*---------------------------------------------------------------------------------------*/ /* DBUNLOCKR() - unlocks a table Record */ /*---------------------------------------------------------------------------------------*/ rc = dbunlockr(dbf, (long) 7); if (rc == SUCCESS) { printf("Function \tdbunlockr(): \trecord unlocked successfully\n"); } else { printf("Unlock Failed. \tError: %d\n", rc); } /*---------------------------------------------------------------------------------------*/ /* Perform record/index close functions */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBICLOSE() - close the active index */ /*---------------------------------------------------------------------------------------*/ rc = dbiclose(ndx); errorproc("dbiclose()", "index closed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBXCLOSE() - close the active tagged index */ /*---------------------------------------------------------------------------------------*/ rc = dbxclose(dbx); errorproc("dbxclose()", "tagged index closed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBCLOSE() - close the active table */ /*---------------------------------------------------------------------------------------*/ rc = dbclose(dbf); errorproc("dbclose()", "table closed.", rc); /*---------------------------------------------------------------------------------------*/ /* DBMCLOSE() - close the active memo table */ /*---------------------------------------------------------------------------------------*/ rc = dbmclose(dbt); errorproc("dbmclose()", "memo table closed.", rc); /*---------------------------------------------------------------------------------------*/ /* Perform miscellaneous Recital/Library functions */ /*---------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------*/ /* DBONERROR() - enables/disables (1/0) recovery from errors */ /*---------------------------------------------------------------------------------------*/ dbonerror(0); /* Recovery disabled */ printf("Function: \tdbonerror() \terror checking disabled\n"); printf("\nEnd of Recital C Library test program....\n"); exit(0); } /*-----------------------------------------------------------------------------------------*/ /* This procedure handles the return codes from called RECITAL/library */ /* functions. Intended to eliminate cryptic 'if...else...' statements */ /* following library calls. */ /*-----------------------------------------------------------------------------------------*/ static int 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; }
