Bt_Create() Function

 

<< Click to Display Table of Contents >>

Navigation:  Support Functions >

 

Bt_Create() Function

 

Previous pageReturn to chapter overviewNext page

 

Purpose

 

 

Create a new table from arrays or string definitions

 

 

 

Prototype

 

 

FUNCTION Bt_Create ( cFileName AS STRING, uFields AS USUAL, uIndexes AS USUAL,   nFlags  := 0 AS WORD, nPageSize  := 0 AS WORD, nid  := 0 AS WORD )  AS LOGIC PASCAL

 

 

 

Argument(s)

 

 

<cFileName>Name of the file to create. You may optionally include the drive and path.
<uFields>is an array or string containing the file definition.
<uIndexes>is an array or string containing the file definition.
<nFlags>(Optional) a numeric indicating optional supplemental flags for the file
<nPageSize>(Optional) a numeric indicating the requested pagesize. When omitted the        optimal pagesize is calculated from the number of index segments
<nId>(Optional) Client ID to use when creating the file.

 

 

 

 

Return

 

 

LOGICTrue if successful. False on failure. Use BT_ERROR() to get an error code.

 

 

 

Description

 

 

Creates a table from array or string definitions.

The structure of the file is in the form of an BtField Array, or a (array of) string(s) containing the field descriptions.

See the BtServer:Init() method for a description of the layout of these strings

 

You may have only one variable length field (M or ML) per record. If defined, it must be the last field in the record.

 

For a variable length field (type M or ML) specify the maximum length of the field. Keep the value as low as realistically possible; doing so will not affect disk space, but will use memory more efficiently.

 

Total record length (excluding variable length field, if present) must be under 4096 bytes.

 

Define the index fields and attributes.

 

The index information for the file is in a similar format: it can be an array of BtIndex objects, or an array or string containing the index definition(s). If an array, it contains one entry for each field. Each entry is a 32-byte string in the following format:

FFFFFFFFFFFFFFFFFFFFXXbbbDMNQSU;  where:

F = field name (20)

 

X = literal text: "X "

b = blank filler (3)

D = 'D' if index is Descending

N = 'N' if Nulls are allowed

Q = 'Q' if index is uniQue

S = 'S' if index is Static

U = 'U' if index is Uppercase

 

Attributes D, M, N, Q, S, U are recognized only if they are uppercase; a lowercase letter can be left as a place holder when an attribute is not in effect.

 

If <index> is type string, then concatenate the 32-character entries for all segments of the index. The length of the string must be exactly 32 * segment count.

 

Indexes may be on a single field or on multiple fields. Indexing on expressions is not supported.

 

A significant restriction for Btrieve indexing is that there is a limit on the number of index segments (fields) allowed in a Btrieve file. (See the Btrieve Programmer's Manual for details.) If the total segments of your indexes has reached the limit, you cannot, even temporarily, add another field or another index.

 

Set MORE if the index is segmented (that is, contains more that one field). However, on the last segment, MORE must be set to False.

 

Set UNIQUE if the index is a unique key for the table. If the index is segmented, all segments in the index must have the same setting.

 

Set UPPERCASE if the field is case insensitive. Fields in a segmented index can have different settings of UPPERCASE. In addition, if a field participates in more than one index, it can have different settings of UPPERCASE.

 

Set DESCENDING if the field is to be indexed in descending order. Fields in a segmented index can have different settings of DESCENDING. In addition, if a field participates in more than one index, it can have different settings of DESCENDING.

 

Set NULLS if the key should not be indexed if the field(s) in the index are empty. If the index is segmented, all segments in the index must have the same setting.

 

Specifying NULLS can save disk space if a specific key will often be left empty. An example might be an index on an alternate phone number field, which often might not be entered by the user.

At least one index in a table must be left as NULLS = .F.

 

Set STATIC if the key value cannot be modified once the record has been added. (This will not affect empty keys where NULLS has been specified.) If the key is segmented, all segments in the index must have the same setting.

 

Create the Table with Bt_Create()

 

If the Btrieve file already exists, the table will be created and the file will be overwritten.

 

Data Type/Length

The Bt_CvType function contains a list of all the valid datatypes for Btrieve fields.

 

When an error occurs creating the file, the return value is FALSE and the Bt_Error() function returns one of the following values:

02 I/O Error
18 Disk Full
22 Data Buffer Length
24 Page Size Error
25 Create I/O Error
26 Number of Keys
27 Invalid Key Position
28 Invalid Record Length
29 Invalid Key Length
48 Invalid Alternate Sequence Definition
49 Key Type Error
59 File Already Exists
104 Locale Not Found
105 Cannot Create with VAT

 

 

 

 

See Also

 

 

Bt_CreateIndex(), BtServer:Init(), Bt_CvType()