Product Documentation

c-treeDB API for C# - Developers Guide

Previous Topic

Next Topic

Changing Default Properties

After all fields and indexes have been defined and the table properties set, it is time to create the table by calling the CTTable.Create() method. This method takes as parameters the table name and the create mode.

Note: Delphi users should use the equivalent method CreateSession() instead of Create().

// create a new table object

CTTable ATable = new CTTable(ADatabase);


// add two fields to the table record definition

ATable.AddField("Field1", FIELD_TYPE.INTEGER, 4);

ATable.AddField("Field2", FIELD_TYPE.CHARS, 30);


// add index 0 - the first index

ATable.AddIndex("MyIndex1", KEY_TYPE.FIXED_INDEX, true, false);


// add index 0 segments

ATable.AddSegment("MyIndex1", "Field1", SEG_MODE.SCHSEG_SEG);


// add index 1 - the second index

ATable.AddIndex("MyIndex2", KEY_TYPE.FIXED_INDEX, false, false);


// add index 1 segments

ATable.AddSegment("MyIndex2", "Field2", SEG_MODE.SCHSEG_SEG);

ATable.AddSegment("MyIndex2", "Field1", SEG_MODE.SCHSEG_SEG);


// create the table

try

{

ATable.Create("MyTable", CREATE_MODE.NORMAL_CREATE);

}

catch (CTException err)

{

Console.Write("Create table failed with error {0}\n", err.GetErrorCode());

}

The table create modes are a combination of the following valid modes. You can specify more than one create mode by OR-ing the following constants defined in the CREATE_MODE enum:

Create Mode

Value

Explanation

NORMAL_CREATE

0

Normal table creation. Use this mode when no other create mode apply.

PREIMG_CREATE

1

This mode implements transaction processing for a table but does not support automatic file recovery. Files with CTCREATE_PREIMG mode do not take any space in the system transaction logs.

TRNLOG_CREATE

2

With this mode you will get the full benefit of transaction processing, including both atomicity and automatic recovery. If you are not sure of what mode to use, and you do want to use transaction processing, then use this mode.

WRITETHRU_CREATE

4

This mode forces the operating system to flush all disk cache buffers when a data write occurs. Setting this mode can slow performance of the file handler. On the other hand, it is an important feature to use if you want to ensure that all data writes are put to the disk immediately. It is particularly important if you are in an operating environment where the system crashes a lot, and you are not using transactions. However, this mode does not guarantee that operating system buffers will be flushed as expected.

CHECKLOCK_CREATE

8

Tables created with this mode require a record lock before a record can be updated. If a lock is not obtained, the error code DADV_ERR (57) is returned.

NORECBYT_CREATE

32

Create the table without the RECBYT index.

NOROWID_CREATE

64

Create the table without the ROWID index.

CHECKREAD_CREATE

128

Tables created with this mode require a record lock as records are read. Obtain at least a read lock on a record before it can be read, otherwise the function will return error code DADV_ERR (57).

HUGEFILE_CREATE

256

Create the table with huge file support. With this mode on, tables will support 8 byte addresses for file offsets.

NODELFLD_CREATE

512

This mode indicates that the is to be created without the $DELFLD$ field support.

NONULFLD_CREATE

1024

This mode indicates that the table is to be created without the $NULFLD$ field support.

TOCIndex