|
The Create operation (B_CREATE) lets you generate a new data file from within your application. The Create operation also has subfunctions that allow you to delete or rename a file (see Delete and Rename Subfunctions for the Create Operation ).
If you are creating an empty file over an existing file, ensure that the existing file is closed before executing the Create operation.
For more information about path names the transactional interface supports, refer to Getting Started With Pervasive PSQL.
Table 2-1 illustrates the order in which the file and key specifications must be stored.
|
Description
|
Data Type1
|
Byte #
|
Example Value2
|
||
|---|---|---|---|---|---|
|
File Specification
|
|||||
|
Logical Fixed Record Length3
|
Short Int4
|
0, 1
|
Size of all fields combined.
|
||
|
Page Size.
|
Pervasive PSQL 6.x-9.4
|
Short Int
|
2, 3
|
512
|
|
|
Pervasive PSQL 6.x and later
|
1,024
|
||||
|
Pervasive PSQL 6.x-9.4
|
1,536
|
||||
|
Pervasive PSQL 6.x and later
|
2,048
|
||||
|
Pervasive PSQL 6.x-9.4
|
3,072
|
||||
|
3,584
|
|||||
|
Pervasive PSQL 6.x and later
|
4,096
|
||||
|
Pervasive PSQL 9.0-9.4x
|
8,192
|
||||
|
Pervasive PSQL 9.5 and later
|
16,384
|
||||
|
A minimum size of 4096 bytes works best for most files. When creating 9.5 file format files, if the logical page size specified is valid for the file format the MicroKernel will round the specified value to the next higher valid value if one exists. For all other values and file formats the operation will fail with status 24. No rounding is done for the older file formats.
|
|||||
|
Number of Keys (Indexes)
|
Byte
|
4
|
|
||
|
File Version
|
Byte
|
5
|
0x60
|
Version 6.0
|
|
|
0x70
|
Version 7.0
|
||||
|
0x80
|
Version 8.0
|
||||
|
0x90
|
Version 9.0
|
||||
|
0x95
|
Version 9.5
|
||||
|
0x00
|
Use database engine default
|
||||
|
Reserved. (Not used during a Create operation.)
|
Reserved
|
6- 9
|
0
|
||
|
File Flags. Specifies the file attributes. The example file does not use any.
|
Short Int
|
10, 11
|
0
|
||
|
Number of Extra Pointers. Sets the number of duplicate pointers to reserve for future key additions. Used if the file attributes specify Reserve Duplicate Pointers.
|
Byte
|
12
|
0
|
||
|
Reserved. (Not used during a Create operation.)
|
Reserved
|
13
|
0
|
||
|
Preallocated Pages. Sets the number of pages to preallocate. Used if the file attributes specify Page Preallocation.
|
Short Int
|
14, 15
|
0
|
||
|
Key Specification for Key 0 (Last Name)
|
|||||
|
Key Position. Provides the position of the first byte of the key within the record. The first byte in the record is 1.
|
Short Int
|
16, 17
|
1
|
||
|
Key Length. Specifies the length of the key, in bytes.
|
Short Int
|
18, 19
|
25
|
||
|
Key Flags. Specifies the key attributes.
|
Short Int
|
20, 21
|
EXTTYPE_KEY + NOCASE_KEY + DUP + MOD
|
||
|
Not Used for a Create.
|
Byte
|
22-25
|
0
|
||
|
Extended Key Type. Used if the key flags specify Use Extended Key Type. Specifies one of the extended data types.
|
Byte
|
26
|
ZSTRING
|
||
|
Null Value (legacy nulls only). Used if the key flags specify Null Key (All Segments) or Null Key (Any Segment). Specifies an exclusion value for the key. See Null Value for more conceptual information on legacy nulls and true nulls.
|
Byte
|
27
|
0
|
||
|
Not Used for a Create.
|
Byte
|
28, 29
|
0
|
||
|
Manually Assigned Key Number. Used if the file attributes specify Key Number. Assigns a key number.
|
Byte
|
30
|
0
|
||
|
ACS Number. Used if the key flags specify Use Default ACS, Use Numbered ACS in File, or Use Named ACS. Specifies the ACS number to use.
|
Byte
|
31
|
0
|
||
|
Key Specification for Key 1 (Employee ID)
|
|||||
|
Key Position. (Employee ID starts at first byte after Middle Initial.)
|
Short Int
|
32, 33
|
52
|
||
|
Key Length.
|
Short Int
|
34, 35
|
4
|
||
|
Key Flags.
|
Short Int
|
36, 37
|
EXTTYPE_KEY + MOD
|
||
|
Not Used for a Create.
|
Byte
|
38-41
|
0
|
||
|
Extended Key Type.
|
Byte
|
42
|
INTEGER
|
||
|
Null Value.
|
Byte
|
43
|
0
|
||
|
Not Used for a Create.
|
Byte
|
44, 45
|
0
|
||
|
Manually Assigned Key Number.
|
Byte
|
46
|
0
|
||
|
ACS Number.
|
Byte
|
47
|
0
|
||
|
1Unless specified otherwise, all data types are unsigned.
2For simplification, the non-numeric example values are for C applications.
3For files with variable-length records, the logical record length refers only to the fixed-length portion of the record.
4Short Integers (Short Int) must be stored in the "Little Endian" byte order, which is the Low To High ordering of Intel-class computers.
|
Note
You must allocate the "not used" and "reserved" areas of the Data Buffer, even though the transactional interface does not use them for a Create operation. Initialize the reserved areas to zero to maintain compatibility with future releases.
Store the file specification in the first 16 bytes of the Data Buffer. The bytes are numbered beginning with 0. Store the information for the record length, page size, and number of indexes as integers.
Logical Record Length. (Offset 0x00) The logical record length is the number of bytes of fixed-length data in the file. (Do not include variable-length data in the logical record length.)
Page Size. (Offset 0x02) Page size is determined by your file format version. The latest version supports sizes 1K, 2K, 4K, 8K and 16K. For more information about choosing the optimal page size, refer to the Pervasive PSQL Programmer's Guide.
Number of Indexes. (Offset 0x04) The number of indexes is the number of keys (not key segments) you are defining for the file. To create a data-only file, set the number of indexes to 0.
File Version. (Offset 0x05) The transactional interface file version to be created. In prior releases, the transactional interface used a two byte integer to receive the number of indexes on a create operation. The high order byte of this integer was always zero because the maximum number of indexes is 119. This high-order byte has always been used in the Stat operation to return the file version and it can now be used to specify the file version in the Create operation without breaking any previous applications. The supported file versions for Create are 6.x, 7.x, 8.x, 9.x, 9.5 which are represented in the specified byte with hex values 0x50, 0x60, 0x70, 0x80, 0x90, 0x95.
Physical Page Size. (Offset 0xA). This field is ignored. File Flags. (Offset 0x0A) The bit settings in the File Flags word specify file attributes. Table 2-2 shows the binary, hexadecimal, and decimal representations of the file flag values.
|
Attribute
|
Constant
|
Binary
|
Hex
|
Decimal
|
|---|---|---|---|---|
|
Variable Length Records
|
VAR_RECS
|
0000 0000 0000 0001
|
1
|
1
|
|
Blank Truncation
|
BLANK_TRUNC
|
0000 0000 0000 0010
|
2
|
2
|
|
Page Preallocation
|
PRE_ALLOC
|
0000 0000 0000 0100
|
04
|
4
|
|
Data Compression
|
DATA_COMP
|
0000 0000 0000 1000
|
08
|
8
|
|
Key-Only File
|
KEY_ONLY
|
0000 0000 0001 0000
|
10
|
16
|
|
Balanced Index
|
BALANCED_KEYS
|
0000 0000 0010 0000
|
20
|
32
|
|
10% Free Space
|
FREE_10
|
0000 0000 0100 0000
|
40
|
64
|
|
20% Free Space
|
FREE_20
|
0000 0000 10 00 0000
|
80
|
128
|
|
30% Free Space
|
FREE_30
|
0000 0000 1100 0000
|
C0
|
192
|
|
Reserve Duplicate Pointers
|
DUP_PTRS
|
0000 0001 0000 0000
|
100
|
256
|
|
Include System Data1
|
INCLUDE_SYSTEM_DATA
|
0000 0010 0000 0000
|
200
|
512
|
|
Do Not Include System Data
|
NO_INCLUDE_
SYSTEM_DATA |
0001 0010 0000 0000
|
1200
|
4,608
|
|
Key Number
|
SPECIFY_KEY_
NUMS |
0000 0100 0000 0000
|
400
|
1,024
|
|
Use VATs
|
VATS_SUPPORT
|
0000 1000 0000 0000
|
800
|
2,048
|
|
1If you do not explicitly specify whether to include system data in the file, the Btrieve API uses the current setting of the transactional interface configuration option "Include System Data."
|
Avoid using incompatible flags; flags are incompatible if they use the same bit positions. Unused bits are reserved for future use. Set them to 0.
To combine file attributes, add their respective File Flag values. For example, to specify a file that allows variable-length records and uses blank truncation, initialize the File Flags word to 3 (2 + 1). The transactional interface ignores the Blank Truncation and Free Space bits if the Variable Length Records bit is set to 0.
If you set the Page Preallocation bit, use the last 2 bytes in the file specification block (allocation) to store an integer value that specifies the number of pages to preallocate to the file. If you set the Data Compression bit, the transactional interface ignores the Variable Length Records bit. If you set the Key-only File bit, the transactional interface ignores the System Data bits.
Note
The transactional interface automatically uses data compression on files that use system data and have a record length greater than 4,076 bytes.
Set the Duplicate Pointers bit if you anticipate adding an index sometime after creating a file, and if that index has many duplicate values. Setting this bit causes the transactional interface to reserve space in each record of the file for pointers that link the duplicate values. By reserving this space, you can possibly lower retrieval time and save disk space, especially if the keys are long and you anticipate that many records will have duplicate key values.
Note
You can reserve duplicate pointer space only for indexes that are added after file creation. Therefore, when reserving space for pointers to duplicate values, do not include space for the indexes created during this Create operation. Also, the transactional interface does not reserve duplicate pointer space for any key you specify as a repeating-duplicatable key.
Set the Key Number bit if you need to assign a specific number to a key, and place the desired key number in the Manually Assigned Key Number element (offset 0x0E) of the Key Specification block. The transactional interface does not require consecutive key numbers; files can have gaps between key numbers. When a key is created, by default the transactional interface assigns the lowest available key number to that index (beginning with 0). However, some applications may require a key number different from the default assignment.
Set the Use VATs bit if the file uses Variable-tail Allocation Tables. To use VATs, a file must use variable-length records.
Number of Duplicate Pointers to Reserve. (Offset 0x0C) You can specify the number of duplicate pointers to reserve for each file. Use this element only if you specified the Reserve Duplicate Pointers file flag. For more information about duplicatable keys, refer to the following topic in Pervasive PSQL Programmer's Guide: Duplicatable Keys .
Allocation. (Offset 0x0E) You can specify the number of pages to preallocate. Use this element only if you specified the Page Preallocation file flag. For more information about page preallocation, see the following topic in Pervasive PSQL Programmer's Guide: Page Preallocation .
Place the key specification blocks immediately after the file specification. Allocate a 16-byte key specification block for each key segment in the file. Store the information for the Key Position and the Key Length as integers.
The maximum number of key segments allowed depends on the file's page size.
See also the status codes 26: The number of keys specified is invalid and 29: The key length is invalid , both in Status Codes and Messages.
Key Position. (Offset 0x00) The key position is the byte offset at which the key or key segment begins. Positions are relative to 1; A key at the beginning of the record starts at position 1. There is no position 0.
Key Length. (Offset 0x02) The length of the key or key segment. The maximum length of a key, including all key segments, is 255 bytes.
Key Flags. (Offset 0x04) The bit settings in the Key Flags word specify key attributes. Table 2-3 shows the binary, hexadecimal, and decimal representations of the Key Flags values.
Avoid using incompatible flags; flags are incompatible if they use the same bit positions. Unused bits are reserved for future use. Set them to 0.
To combine key attributes, add their respective Key Flags values. For example, if the key is an extended type, part of a segmented key, and to be collated in descending order, initialize the Key Flags word to 336 (256 + 16 + 64).
The Segmented Key attribute indicates that the next key specification block in the Data Buffer refers to the next segment of the same key. Follow these rules for segmented keys:
ACSs are applicable only to STRING, LSTRING, and ZSTRING keys. You cannot define a key that is both case-insensitive and uses an ACS. In a file in which a key has an ACS designated for some segments but not for others, the segments that designate an ACS are sorted by the specified ACS; the segments with no ACSs are sorted according to their respective types.
Extended Data Type. (Offset 0x0A) You specify the Extended Data Type in byte 10 of the Key Specification block as a binary value. Table 2-4 shows the codes for the extended data types.
Extended data type codes 12, 13, 16, and 21-24 are reserved for future use.
You can define the STRING and UNSIGNED BINARY data types as either standard or extended types. This maintains compatibility with applications that were developed with earlier versions of Btrieve API, while allowing newer applications to use extended data types exclusively.
Regarding the data type you assign to a key, transactional interface does not ensure that the records you input adhere to the data types defined for the keys. For example, you could define a TIMESTAMP key in a file, but store a character string there. Your Btrieve API application would work fine, but an ODBC application that tries to access the same data using the ODBC TIMESTAMP format might fail, because the byte format could be different and the algorithms used to generate the timestamp value could be different. For complete descriptions of the data types, refer to SQL Engine Reference.
Null Value. (Offset 0x0B) of the Key Specification block represents an exclusion value for the key. If you have defined a key as a null key, you must supply a value for the transactional interface to recognize as the null value for each key segment. This is in reference to the legacy null and does not reflect true nulls. For a discussion of null support, see the following topic in Pervasive PSQL Programmer's Guide: Null Value .
Manually Assigned Key Number. (Offset 0x0E) The transactional interface allows an application to assign specific key numbers when creating a file with indexes. To manually assign key numbers to each index for a file, specify each key's number as a binary value in byte 14 of the key specification block, and set the Key Number bit (0x400) in the File Flags word.
Key numbers must be unique to the file and must be specified in ascending order, beginning with key 0. They must also be valid (less than the maximum number of keys for the file's page size).
The ability to manually assign key numbers complements to the ability to delete a key and not have the transactional interface renumber all keys that have a key number greater than the deleted key. For example, if an application drops an index and instructs the transactional interface not to renumber higher-numbered keys, and if a user then clones the affected file without assigning specific key numbers, the cloned file has different key numbers than the original.
ACS Number. (Offset 0x0F) For keys that use a specific ACS, offset 0x0F in the key specification block provides the ACS number by which to collate the key. The ACS number is based on its position in the Data Buffer. The first ACS following the last key specification block is ACS number 0. Following ACS 0 is ACS 1, which is followed by ACS 2, and so on.
Your application specifies ACSs one after the other immediately following the last key specification block in the Data Buffer.
User-Defined ACSs. To create an ACS that sorts string values differently from the ASCII standard, your application must place 265 bytes directly into the Data Buffer, using the format displayed in Table 2-5.
For examples of user-defined ACSs, refer to the following topic in Pervasive PSQL Programmer's Guide: Alternate Collating Sequences .
International Sort Rules (ISRs). To specify an ISR, your application must place 265 bytes directly into the Data Buffer, using the following format:
The Data Buffer Length must be long enough to include the file specifications, the key specifications, and any ACSs that have been defined. Do not specify the file's record length in this parameter.
For example, to create a file that has two keys of one segment each and an ACS, the Data Buffer for the Create operation should be at least 313 bytes long, as follows:
The Create operation's Key Number parameter is used to determine if the transactional interface warns you when a file of the same name already exists, and also to determine whether the transactional interface should use a local or remote engine when creating the file.
Use Table 2-7 to determine which value you should use for the Key Number parameter.
Note
The Create operation makes no distinction between workstation, workgroup, and server engines when you specify that the local engine should create the file.
The Create operation has two additional subfunctions that you can use to delete or rename files.
In releases prior to Pervasive.SQL v8.5, it was always possible to manipulate transactional interface files through the operating system, because the transactional interface depended on the rights and privileges given by the operating system to the Pervasive PSQL user.
Now, if you have a secure Pervasive PSQL database, these operating system access rights may have been removed in the process of securing the database from unauthorized access. This makes programmatically deleting or moving the files difficult since the rights required are not always available.
The rename and delete subfunctions are implemented as Create operations with alternate key numbers. You do not need to provide a file specification as you do when creating a new data file. The following table shows how you set up the Create operation to use the rename or delete subfunctions.
These subfunctions have been modified to work with the security model in that they will accept a URI in place of a file name in the key buffer and data buffer, if needed, to indicate a transactional interface file to delete or rename. This allows you to provide security information with the operation.
The security information is processed just like a normal Create or Open operation. The user must be authenticated and have DB_RIGHT_CREATE, DB_RIGHT_ALTER and DB_RIGHT_OPEN privileges for the existing files and for the directory where the new file will be located if applicable.
|
Function
|
URI parameter file=
|
URI parameter dbfile=
|
URI parameter table=
|
|---|---|---|---|
|
Rename
|
|
|
|
|
Delete
|
|
|
|
|
Function
|
file=
|
dbfile=
|
table=
|
|---|---|---|---|
|
Rename
|
|
|
|
|
Delete
|
Not applicable
|
Not applicable
|
Not applicable
|
If the Create operation is successful, the transactional interface either warns you of the existence of a file with the same name or creates the new file according to your specifications. The new file does not contain any records. The Create operation does not open the file. Your application must perform an Open operation before it can access the file.
If the Create operation is unsuccessful, the transactional interface returns one of the following status codes:
The Create operation establishes no currency on the file.
|
Chapter contents
Prev topic: Continuous Operation (42)
|