|
<< Click to Display Table of Contents >> DbiOpenDatabase |
![]() ![]()
|
C syntax
DBIResult DBIFN DbiOpenDatabase (pszDbName, pszDbType, eOpenMode, eShareMode, [pszPassword], iOptFlds, pOptFldDesc, pOptParams, phDb);
Delphi syntax
function DbiOpenDatabase (pszDbName: PChar; pszDbType: PChar; eOpenMode: DBIOpenMode; eShareMode: DBIShareMode; pszPassword: PChar; iOptFlds: Word; pOptFldDesc: pFLDDesc; pOptParams: Pointer; var hDb: hDBIDb): DBIResult stdcall;
Description
DbiOpenDatabase is called to open a database in the current session. On success, a database handle is returned.
Parameters
pszDbName Type: pCHAR (Input)
Pointer to the alias name string defined in the configuration file. Optional. If NULL, the standard database is opened. If pszDbName specifies a SQL database, pszDbType can be NULL. If pszDbName specifies an ODBC data source not in the configuration file, the BDE adds the data source and ODBC driver to the session automatically.
pszDbType Type: pCHAR (Input)
Pointer to the database type string. Optional. If both pszDbName and pszDbType are NULL, a standard database is opened.
eOpenMode Type: DBIOpenMode (Input)
Specifies the open mode.
eShareMode Type: DBIShareMode (Input)
Specifies the share mode.
pszPassword Type: pCHAR (Input)
Pointer to the password string. Optional. SQL only.
iOptFlds Type: UINT16 (Input)
Specifies the number of optional parameters. Refer to DbiCreateTable for use of optional parameters.
pOptFldDesc Type: pFLDDesc (Input)
Pointer to an array of field descriptors for the optional parameters. Refer to DbiCreateTable for use of optional parameters.
pOptParams Type: pBYTE (Input)
Pointer to the optional parameters required by the database. Refer to DbiCreateTable for use of optional parameters.
phDb Type: phDBIDb (Output)
Pointer to the database handle.
Usage
The database must be opened before a table can be opened in the database.
The database handle is passed into several functions. The values in pszDbName and pszDbType determine which database is opened. The eOpenMode and eShareMode parameters determine the access modes of the cursors within each database. For example, if eOpenMode is set to dbiREADONLY, its associated cursors are also READONLY.
ODBC: DbiOpenDatabase automatically adds ODBC drivers and data sources as BDE aliases to the active session when they aren't currently stored in the configuration file. The BDE also supports ODBC 3 drivers.
SQL: SQL configuration file settings might override the eOpenMode setting.
OptFields, pOptFldDesc and pOptParams are the optional parameters. The optional parameters passed by this function vary depending on the driver. They can be identified by calling the DbiOpenCfgInfoList function.
Standard: Connecting to a standard database:
| • | If pszDbName and pszDbType are both set to NULL, the unnamed standard database is opened. |
| • | If pszDbName specifies an alias for a standard database in the configuration file, this database is opened. |
SQL: Connecting to a SQL database:
| • | If pszDbName specifies a SQL ALIAS from the configuration file, pszDbType is NULL, and iOptFlds is 0, a SQL database is opened. (Supply the password if required.) |
| • | If pszDbName is NULL, and pszDbType is one of the SQL driver names (for example, Oracle, Sybase), a SQL database is opened. If optional parameters are not specified, driver-specific defaults are used. |
Prerequisites
DbiInit must be called prior to calling DbiOpenDatabase. The database must be successfully opened before any other calls can be made to access or manipulate data. If the database requires login, a password must be supplied.
DbiResult |
Meaning |
DBIERR_NONE |
The database was successfully opened. |
DBIERR_UNKNOWNDB |
The specified database or database type is invalid. |
DBIERR_NOCONFIGFILE |
The configuration file was not found. |
DBIERR_INVALIDDBSPEC |
When using an alias from the configuration file, the specification is invalid. |
DBIERR_DBLIMIT |
The maximum number of databases have been opened. |
See also