|
This section details data type mappings.
The following table shows data type mappings from Pervasive.SQL column types to Delphi data types. Types on the left stored in Pervasive.SQL databases will be exposed by PDAC components as the types listed on the right
The following table shows data type mapping from Delphi to Pervasive.SQL data types. When new database tables are created using PDAC, columns defined as the field types listed in the lefthand column will be stored by Pervasive.SQL using the types listed on the right.
The following table shows data type mapping from Btrieve to VCL.
Note
Binary flags refer to a flag in X$Fields.Xe$Flags
Call the CreateTable method at runtime to create a table using this dataset's current definition.
If the FieldDefs property contains values, these values are used to create field definitions. Otherwise the Fields property is used. One or both of these properties must contain values in order to recreate a dataset.
Use the Add method to assign field properties
Add is provided for backward compatibility. The recommended way to add new field definitions to the Items property array is using the AddFieldDef method. You should also use it to specify precision and scale for the ftBCD data type.
Add uses the values passed in the Name, DataType, Size, and Required parameters and assigns them to the respective properties of the new field definition object.
Note
Set "Required" to False if field is nullable. To activate the autoincrement property for AutoInc field, you have to create a unique index on this field.
PvTable1.DatabaseName := 'TestData'; PvTable1.TableName := 'TestData1'; with PvTable1.FieldDefs do begin Clear; Add('F_autoinc', ftAutoInc, 0, True); Add('F_currency', ftCurrency, 0, False); Add('F_integer', ftInteger, 0, False); Add('F_word', ftWord, 0, False); Add('F_fixchar', ftFixedchar, 30, False); Add('F_varbin', ftString, 25, False); Add('F_blob', ftBlob, 60, False); end; with PvTable1.FieldDefs.AddFieldDef do begin Name := 'F_BCD'; DataType := ftBCD; Size:=2; //Scale Precision := 10; //Precision Required := false; end; with PvTable1.IndexDefs do begin Clear; Add('Index1', 'F_autoinc', [ixPrimary, ixUnique]); Add('Index2', 'F_integer', [ixCaseInsensitive]); end; PvTable1.CreateTable;
PvTable1->DatabaseName="TestData"; PvTable1->TableName="Test1"; PvTable1->FieldDefs->Clear(); PvTable1->FieldDefs->Add("F_autoinc", ftAutoInc, 0, True); PvTable1->FieldDefs->Add("F_integer", ftInteger, 0, False); PvTable1->FieldDefs->Add("F_Curr", ftCurrency, 0, False); PvTable1->FieldDefs->Add("F_Word", ftWord, 0, False); PvTable1->FieldDefs->Add("F_fixchar", ftFixedChar, 0, False); PvTable1->FieldDefs->Add("F_String", ftString, 20, False); PvTable1->FieldDefs->Add("F_blob", ftBlob, 60, False); TFieldDef *FieldDef = PvTable1->FieldDefs- >AddFieldDef(); FieldDef->Name="F_BCD"; FieldDef->DataType=ftBCD; FieldDef->Size=2; FieldDef->Precision=10; FieldDef->Required=False; PvTable1->IndexDefs->Clear(); PvTable1->IndexDefs-> Add("Index1","F_autoinc",TIndexOptions() <<ixPrimary << ixUnique); PvTable1->CreateTable();
The following table shows data type mapping from VCL to Btrieve.
Note
Binary flags refer to a flag in X$Fields.Xe$Flags
There is a Pervasive-specific table create method (TPvTable.PvCreateTable) that allows you to tune additional parameters related to field types. It has the following definition:
In PvFieldDefs you can adjust several parameters:
TPvFieldDef = class(TCollectionItem) public FieldNum: integer; BtrType: integer; DrmType: word; ColumnSize: integer; DefaultValue: string; IsColumnCaseInsensitive: boolean; ACS_FileName: string; ACS_Name: string; ACS_ID: string; end;
Where:
If you do not want to set a particular field, it can be set to 0 (DrmType, ColumnSize), -1 (BtrType), false (IsColumnCaseInsensitive) or `' (all string fields). In this case, default values will be used. Field `FieldNum' is required.
Fields `IsColumnCaseInsensitive', `ACS_FileName', `ACS_Name', `ACS_ID' are mutually exclusive. That is, you can set only one of them.
To match Btrieve behavior, index option `ixCaseInsensitive' is ignored
The following is an example of using the PvCreateTable method:
with PvTable1.FieldDefs do begin Clear; Add('F_AutoInc', ftAutoInc, 0, true); Add('F_Bytes', ftBytes, 10, False); end; PvFieldDefs := TPvFieldDefs.Create(TPvFieldDef); try PvFieldDef := PvFieldDefs.Add(); PvFieldDef.FieldNum := 1; // F_Bytes PvFieldDef.BtrType := 10; PvFieldDef.DrmType := DRM_coltypVarText; PvFieldDef.ColumnSize := 20; PvFieldDef.IsColumnCaseInsensitive := true; PvTable1.PvCreateTable(PvFieldDefs); finally PvFieldDefs.Free(); end;
|
Chapter contents
Prev topic: PDAC Classes, Properties, Events, and Methods
|