C Language Development Kit/Snippets/Database/CloseDatabase

From OptiWiki

Jump to: navigation, search
Description Closes an open database that was previously opened with OpenDatabase(), OpenIndexFile() or created with CreateDatabase(), CreateIndexFile().
Syntax
void CloseDatabase( SDBFile *dbFile );
Arguments SDBFile *dbFile

dbFile is pointer to a structure that holds information about the database. The SDBFile structure is defined as followed:

typedef struct
{
    short  sRecSz;        // record size of database
    int    fd;            // real handle to the open file
    long   lCurrRecord;   // current record number
    long   lTotalRecords; // total amount of records
    int    bOpen;         // check to see if db is open or closed
}SDBFile;
Returns None
Remarks The declaration of the SDBFile needs to be static to make sure all items are initialized to 0.
Example
#include "lib.h"
#include <stdio.h>
#include "database.h"  //Holds the database functions
 
void main( void )
{
    static SDBFile dbFile; // static initializes all items to 0
 
    printf("\fOpen database\n");
    if( !OpenDatabase("file1.txt", 32, &dbFile ))
        printf("Error code = %ld\n", GetDBErrorCode());
 
    printf("Close database\n");
    CloseDatabase( &dbFile );
 
    while( 1 )
        idle();
}


Views
Personal tools