Step Two Open a database object

This step will connect to a database. The BDE accesses all tables through the context of a database. Single-tier applications will generally create an alias to a file system directory and utilize that as the database context. The function DbiOpenDatabase is used to open a database:

DbiOpenDatabase('DBDEMOS*,'STANDARD', dbiREAOWRITE, dbiOPENSHAREO, nil, 0, nil, nil, hOB)

This sample function call opens the DBDEMOS database, assuming that it has been properly configured within the BDE. The second parameter, STANDARD in this case, determines the type of database that is being accessed. A database can be opened in either Read/Write or Read only modes and in Shared or Exclusive mode. These choices are set through the settings found in the third and fourth parameters of this statement. The remaining parameters are optional with the exception of the crucial database handle found in the last slot.

DbiInit must be called prior to calling this function and DbiOpenDatabase must return a satisfactory result value prior to attempting any table access. The success of any BDE function is determined by querying the return value of the function. This result is returned as a type DBIResult. This data object will tell your application if an error was encountered; a result of DBIERR_NONE, no errors, means that the function call was a success.

When an error occurs, the BDE will place much more detailed information about the error onto the BDE error stack. These error contexts can be examined further through a set of error handling functions built into the BDE. These are:

280 ■ Part Ill-The Well-Rounded Application

  • DbiGetErrorEntry
  • DbiGetErrorString
  • DbiGetErrorContext
  • DbiGetErrorlnfo

Further information about these functions is contained in Appendix A.

0 0

Post a comment

  • Receive news updates via email from this site