DbiCreateTable

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

DbiCreateTable

Return to chapter overview

C syntax

DBIResult DBIFN DbiCreateTable (hDb, bOverWrite, pcrTblDsc);

Delphi syntax

function DbiCreateTable (hDb: hDBIDb; bOverWrite: Bool; var crTblDsc: CRTblDesc): DBIResult stdcall;

Description

DbiCreateTable creates a table in the database associated with the given database handle.

Parameters

hDb                Type: hDBIDb                (Input)
Specifies the database handle.

bOverWrite                Type: BOOL                (Input)
Specifies whether to overwrite an existing table or not. If TRUE is specified, and there is an existing table, it will be overwritten. If FALSE is specified, and there is an existing table, an error is returned.

pcrTblDsc                Type: pCRTblDesc                (Input)
Pointer to the table descriptor structure (CRTblDesc). Refer to DbiGetFieldTypeDesc and DbiGetIndexTypeDesc for more information on the legal values for these structures for each Borland Database Engine driver.

Optional parameters

The optional parameter fields iOptParams, pfldOptParams, and pOptData are used to set other driver-specific attributes of the table. These parameters are used to describe a single record that is constructed by the client and contains the null-terminated ASCII strings that specify the values for these driver-specific attributes.

iOptParams is the number of optional parameters. pfldOptParams contains a pointer to an array of FLDDesc of iOptParams size. Each of these field descriptors is given a field name equal to the name of the optional parameter (for example, MDXBLOCKSIZE) and has iLen and iOffset set to the length (including the NULL terminator) and position in the pOptData record buffer of the ASCII string containing the value of this parameter (for example, 512). All other elements of the FLDDesc are ignored. The pOptData record buffer need only be large enough to hold all the null-terminated strings for each optional parameter value. This style of setting optional parameters is also used by DbiOpenDatabase. The names of the optional parameters can be obtained using DbiOpenCfgInfoList with a configuration path of DRIVERS\DRIVERNAME\TABLECREATE.

Usage

The required descriptors are specified in CRTblDesc; different drivers might require different descriptors.

Text: DbiCreateTable can be used to create a text file to export the data to it. For text file creation, only szTblName and szTblType values in the CRTblDesc are used and the rest of the values are ignored (szTblType is specified as ASCIIDRV). A text file is created with the given name; no field descriptions are necessary.

Paradox: Referential integrity can be created only when creating or restructuring the detail table. The master table must already exist and must be in the same directory as the table being created. A lookup table may exist in any accessible directory, but must exist at the time this table is created.

SQL: All indexes are maintained; there are no non-maintained indexes.

Oracle8: Not supported for object types (ADT, REF, nested table, VARARRAY).

Integrity Constraints: When creating a table by using DbiCreateTable, you can use integrity constraints to ensure that references in the key fields of secondary tables (in the same database) or foreign tables (in another database) are maintained to key fields in a primary table. For example, if several tables have keys referencing primary key Customer ID in the Customer table, then this dependecy must be checked so that referenced customer IDs cannot be deleted, thereby orphaning records in secondary or foreign tables.

Prerequisites

If the client chooses to overwrite an existing table; the existing table must be closed. DbiCreateTable supports up to 255 val-checks.

Completion state

All files associated with the table are created.

DbiResult

Meaning

DBIERR_NONE

The table was created successfully.

DBIERR_INVALIDFILEEXTN

The driver type or file extension is invalid.

DBIERR_INVALIDOPTION

The index description is invalid.

DBIERR_INVALIDINDEXSTRUCT

Invalid index structure. For SQL servers, all indexes are maintained; verify that bMaintained in pidxDesc specifies TRUE.

DBIERR_FILEEXISTS

The table already exists (returned when bOverWrite is FALSE).

DBIERR_INVALIDHNDL

The specified database handle is invalid or NULL.

DBIERR_UNKNOWNTBLTYPE

The specified driver type is invalid.

DBIERR_MULTILEVELCASCADE

An illegal attempt was made to create a referential integrity link that is already in use as a link to a higher level cascade update (Paradox only).

DBIERR_FLDLIMIT

iFldCount exceeds maximum number of fields.

DBIERR_INVALIDFIELDNAME

An invalid field name was specified.

DBIERR_NAMENOTUNIQUE

The specified field name or index name is not unique.

DBIERR_INVALIDFLDTYPE

The specified field type is unknown or not allowed.

DBIERR_RECTOOBIG

The record size exceeds the maximum allowed.

DBIERR_INVALIDINDEXNAME

The specified index name is invalid.

DBIERR_INVALIDINDEXTYPE

The specified index type is invalid.

DBIERR_INDEXNAMEREQUIRED

No index name was specified.

DBIERR_LOOKUPTBLOPENERR

The specified lookup table could not be opened.

See also

DbiCopyTable, DbiSortTable, DbiDoRestructure