Btrieve (transactional) Interface Components
The set of Btrieve components includes the following:
•
TPvSession
•
TPvDatabase
•
TPvTable
•
TPvBatchMove
•
TwwPvTable
These components use no relational functionality, and do not require the Pervasive PSQL relational interface or ODBC at runtime.
The components replace Embarcadero ones as listed in the following table.
Pervasive Direct Access Component
Replaces This Embarcadero Component
TPvBatchMove
TBatchMove
TPvDatabase
TDatabase
TPvSession
TSession
TPvTable, TwwPvTable
TTable
The components can be used standalone (that is, without the Borland Database Engine (BDE) installed) or coincident with the BDE within a single application. Use of the components is the same as the corresponding BDE components, with exceptions noted under specific components where applicable and in
PDAC Classes, Properties, Events, and Methods
.
TPvSession
Provides thread safety and Client ID support. Its functionality is similar to the TSession VCL component.
Related Information
See the following in this chapter pertaining to TPvSession:
•
Class TPvSessionList/TPvSqlSessionList
(under
Supporting Classes
)
•
Global Variables
(under
General Differences from VCL
)
•
TPvSession and TPvSqlSession
(under
Specific Class Differences from VCL
)
•
TPvSession Specific
(under
Specific Class Differences from VCL
)
TPvDatabase
Provides database connection-specific functionality for non-SQL databases, such as login control, transaction support, persistent database connections. Its functionality is similar to the TDatabase VCL component.
Functional Differences Between TPvDatabase and Embarcadero Components
•
Property DriverName, Locale, and TTraceFlags have been dropped
•
Handle's type is changed to DRM_DBID
•
IsSQLBased
always returns False
•
TransIsolation has only two possible values: tiDirtyRead and tiReadCommitted (the default).
Secure Tables and Prompting for User Name and Password
If you are connecting to a secure table, PDAC prompts you for the user name and password. If you want suppress these prompts, set up connection parameters in TPvDatabase using the following as an example. (See also
Table Security
under
TPvTable
.)
PvSession.ServerName:='ServerName';
PvSession.SessionName:='session1';
PvSession.Active:=True;
PvDatabase.AliasName:= 'DatabaseName';
PvDatabase.DatabaseName:='DB';
PvDatabase.SessionName:='session1';
PvDatabase.Params.Clear();
// here you specify user name and password to
// connect to remote database.
PvDatabase.Params.Add('User Name=UserName');
PvDatabase.Params.Add('password=Password');
PvDatabase.Connected:=True;
PvTable.DatabaseName:='DB';
PvTable.SessionName:='session1';
PvTable.TableName:='person';
PvTable.Active:=True;
Related Information
See the following in this chapter pertaining to TPvDatabase:
•
TransIsolation Property Differences
(under
Differences Betweeen PDAC and Embarcadero Components
•
TPvDatabase and TPvSqlDatabase
(under
Specific Class Differences from VCL
)
•
TPvDatabase Specific
(under
Specific Class Differences from VCL
)
TPvTable
Provides single-table access and manipulation. Its functionality is similar to the TTable VCL component.
Functional Differences Between TPvTable and Embarcadero Components
•
All alias management functions perform ”named database” management.
•
Inherits from TPvDataSet rather than TDBDataSet;
•
Properties TableLevel, UpdateObject, UnlockTable, OpenIndexFile, CloseIndexFile have been dropped, TableType is ignored.
•
The Database Name property can be provided at both design time and runtime as a DSN, a Pervasive Named Database, or as a fully-qualified path to the database.
Table Security
PDAC security for the Btrieve interface uses owner names for individual tables. Using this security model, you provide the owner name for the table. See Btrieve operation 29,
Set Owner (29)
, in the
Btrieve API Guide
for more information.
The TPvTable has the property
Owner: string
and the following method:
SetOwnerOnTable(AOwner:
string
; AccessMode:
integer
).
With the
Owner
property you can set the owner name, and with the
SetOwnerOnTable
method you can set or clear the owner name on the table.
Table 3
PDAC Access Modes
Code
Description
0
Requires an owner name for any access mode (no data encryption)
1
Permits read-only access without an owner name (no data encryption)
2
Requires an owner name for any access mode (with data encryption)
3
Permits read-only access without an owner name (with data encryption)
To access the Btrieve table, provide a valid owner name.
Table Creation
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
procedure Add(const Name: string; DataType: TFieldType; Size: Word; Required: Boolean);
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 the field is nullable.
To activate the autoincrement property for AutoInc field, you have to create a unique index on this field.
Delphi Example
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;
C++ Builder Example
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();
Related Information
See the following in this chapter pertaining to TPvTable:
•
TransIsolation Property Differences
(under
Differences Betweeen PDAC and Embarcadero Components
•
TPvTable, TPvQuery, and TPvStoredProc
(under
Specific Class Differences from VCL
)
•
TPvTable Specific
(under
Specific Class Differences from VCL
)
•
Pervasive PSQL and Embarcadero Data Types
TPvBatchMove
Enables applications to perform database operations on groups of records or entire tables. Its functionality is similar to the TBatchMove VCL component.
Related Information
See the following in this chapter pertaining to TPvTable:
•
TPvBatchMove
(under
Specific Class Differences from VCL
)
TwwPvTable
Included with PDAC for InfoPower compatibility. It is directly derived from TPvTable and has an extra property, “Control Type.”