Accuracer: The First And Only BDE Alternative
Client-Server Single-File Embedded Database for Delphi / C++Builder / Kylix



Creating a table

Previous  Top  Next


Introduction

Creating tables is accomplished through the CreateTable method of the TAccuracer component. The properties used by the CreateTable method include the FieldDefs, IndexDefs, TableName and Exists properties.

Specifying the Fields to Create

The FieldDefs property is used to specify which fields to define for the new table. The FieldDefs property is an array of TFieldDef objects, each of which contains information about the field to create. You may add new TFieldDef objects using the Add method of the TFieldDefs object stored in the FieldDefs property. The Add method accepts the following parameters for the field being defined:

Field Name (String)
Field Name parameter indicates the name to give the field.    
Data Type (TFieldType)
DataType parameter indicates the data type of the field Available TFieldType data types
Size (Word)
Size parameter indicates the size of the field. This should be specified for the String type only. For all other data types this parameter should be set as 0. For the String type this parameter indicates the length of the field. For the WideString type this parameter indicates the size of the wide string in bytes.
Required (Boolean)
Required parameter indicates whether or not the new field should be required (not Null) while adding or modifying records.

          

Advanced FieldDefs

Accuracer provides some advanced functionality that cannot be specified by FieldDefs like minimum, maximum and default values, autoincrement fields settings, blob and varchar fields compression settings. Use AdvFieldDefs instead of FieldDefs for specifing fields with advanced parameters. If you use AdvFieldDefs you should empty FieldDefs list by calling FieldDefs.Clear and vice versa. See Reference Guide for more information about AdvFieldDefs (TACRAdvFieldDef class).



Specifying the Indexes to Create

The IndexDefs property is used to specify which indexes to be defined for the new table. The IndexDefs property is an array of TIndexDef objects, each of them containing information about the index to create. You may add new TIndexDef objects using the Add method of the TIndexDefs object contained in the IndexDefs property. The Add method accepts the following parameters for the index being defined:

Index Name (String)
Index Name parameter contains the name to be given to the index.
Fields List (String)
Fields List parameter contains the list of fields to be included into the index. Multiple field names specified in this parameter should be separated with a semicolon (;).
Index Options (TIndexOptions)
Index Options parameter provides information about the type of index being created (please see the component reference supplied with Accuracer for more information on the available TIndexOption options).

         
                  

Setting the Table Information

The TableName property specifies the name for the created table.

Creating the Table

Any table can have a primary key on fields of any type. You may create this key with the index by means [ixPrimary] option.
The final step in creating a table is to call the CreateTable method. It is also recommended to check the Exists property of the TAccuracer component first to make sure that you are not attempting to overwrite an existing table. The following example shows how to create the CUSTOMER table included with the Delphi demo in existing database DBDemos.adb' using the CreateTable method:

begin
with MyAccuracer do
begin
TableName:='customer';
with FieldDefs do
begin
Clear;
Add('CustNo',ftAutoInc,0,False);
Add('Company',ftString,30,False);
Add('Addr1',ftString,30,False);
Add('Addr2',ftString,30,False);
Add('City',ftString,15,False);
Add('State',ftString,20,False);
Add('Zip',ftString,10,False);
Add('Country',ftString,20,False);
Add('Phone',ftString,15,False);
Add('FAX',ftString,15,False);
Add('TaxRate',ftFloat,0,False);
Add('Contact',ftString,20,False);
Add('LastInvoiceDate',ftDateTime,0,False);
end;
with IndexDefs do
begin
Clear;
Add('PrimaryKey','CustNo',[ixPrimary]);
Add('ByCompany','Company',[ixCaseInsensitive]);
end;
if not Exists then
CreateTable;
end;
end;


© AidAim Software Accuracer: