|
This section explains how to accomplish the major tasks involved in creating an application using the ActiveX interface. The tasks are as follows:
To add Pervasive's ActiveX interface data source and bound controls to a Visual Basic project:
The VAccess control is the master control which points to your data and to which all other Pervasive PSQL controls are bound. It handles all communication with Pervasive PSQL.
To add the data source control to a Visual Basic form:

You also may notice the Pervasive PSQL splash screen indicating that the Pervasive PSQL workstation engine has been started.
Now you must set this VAccess control's properties. Read the sections Accessing Properties , Setting Properties , and Connecting to a Pervasive PSQL File .
The properties of a control can be set in three places:
When you right-click on a control and choose Properties from the pop-up menu, the Property Pages appear. This is a tabbed dialog box that lets you set Pervasive PSQL ActiveX properties for the control. For more information, see Figure 2-1.

The Visual Basic Properties window displays the complete set of properties for the selected object, including properties specific to Visual Basic. See Figure 2-2 .

When you double-click on a form or a control, the Visual Basic Code Editor opens. Refer to Visual Basic documentation for information on using the Code Editor. Refer to this manual for syntax and other details about each property.
To set properties for a control:
Note
Some properties can be set at either design time or run time, while others can be set only at design time or only at run time.
There are three important properties of the VAccess control that connect it to a Pervasive PSQL data file: DdfPath, TableName, and Location. The easiest way to access these properties is through the Property Pages, available when you right-click on the control and choose Properties from the pop-up menu. You can also access them through the Properties window.

The three important properties that connect to your data are the following:
To set properties to point to your data:
All bound controls that you bind to this VAccess control will now refer to this table.
.MKD file containing that table. To complete the connection to your data, set the IndexNumber property to select the index you wish to access.
Note
If you set these properties from code at run time, the same order applies.
The IndexNumber property of the VAccess control determines the index used by the VAccess control when record retrieval methods are invoked. It can be set in the Properties window of the VAccess control at design time or in code at run time.
To set the index number at design time:
You can set the IndexNumber property in the Properties window by selecting it from the pop-up menu.
You can also set IndexNumber from the Property Pages as follows:

There are two ways to set the index number at run time-with code and with the VAComboBox control.
To set the index number at run time with code:
To set the index number at run time with a combo box:
The VAccess control opens a Pervasive PSQL data file in one of two ways based on how you set its AutoOpen property. (AutoOpen is a design time-only property.)
See also the Example .
To set the AutoOpen property:
You can set the AutoOpen property in the Properties window by selecting True or False from the pop up menu.
You can also set AutoOpen from the Property Pages as follows:
This example shows how to close a file and open another one when AutoOpen is set to False.
'Close the currently opened file VAccess1.Close 'Set the Data Dictionary information VAccess1.DdfPath = "file_path\PSQL\Demodata" VAccess1.TableName = "Student" 'Open the file VAccess1.Open
After you have added a VAccess control to a form and set the control's properties, you can add any bound controls you want and bind them to the VAccess control. This links them to the data to which the VAccess control points. For information about the specific bound controls, see ActiveX Control Reference .
To link any of the eight Pervasive bound controls to your data:
You can retrieve records in three ways:
To retrieve records with a scroll bar:
To retrieve records with a command button:
See VAOperation for a list of available Pervasive PSQL operations.
To retrieve records with code:
'Display names of persons 'Set the Data Dictionary information 'VAccess1.DdfPath = "file_path\PSQL\Demodata" 'VAccess1.TableName = "Person" 'VAccess1.IndexNumber = 1 (Last_Name + 'First_Name) Stat = VAccess1.GetFirst While Stat = 0 List1.AddItem VAccess1.FieldValue("Last_Name") _ & " " & VAccess1.FieldValue("First_Name") Stat = VAccess1.GetNext Wend
You can search for a specific record in two ways:
To search for a specific record with a text box:
To search for a specific record with code:
'enter the search values into the key fields VAccess1.FieldValue("last_name") = "Reich" VAccess1.FieldValue("first_name") = "Steve" 'Set the correct index number and get the record VAccess1.IndexNumber = 1 stat = VAccess1.GetEqual If stat = 0 Then MsgBox "Found the record." Else MsgBox "No such record on file." End If
There are two ways to add, update, or delete records:
To add, update, or delete records with a command button:
To add, update, or delete records with code:
Use one of the custom methods from the following table for the VAccess control to write to the database in code.
'change the major of a given student VAccess1.TableName = "Student" VAccess1.IndexNumber = 1 FieldValue (ID) = 2001100 stat = GetEqual , s If stat = 0 VAccess1.FieldValue ("Major") = "Music" VAccess1.Update End If
Pervasive PSQL provides two kinds of locks which are supported by Pervasive's ActiveX interface: single record no-wait locks and multiple record no-wait locks.
To apply these locks using Pervasive's ActiveX interface, use one of the following approaches:
Use the Unlock method to unlock records.
In Pervasive PSQL Programmer's Guide, see Data Integrity for a complete discussion of record locking and concurrency controls.
'Lock a record, change the student name, and update the record Const SINGLE_NOWAIT_LOCK = 200 Const MULTIPLE_NOWAIT_LOCK = 400 VAccess1.FieldValue("ID") = "<valid #>" 'retrieving the record with a lock bias locks the record stat = VAccess1.GetEqual SINGLE_NOWAIT_LOCK 'change the student name and update the record 'updating the record releases its lock If stat = 0 VAccess1.FieldValue("Major") = "Astronomy" VAccess1.Update End If
The Join property of the VAccess control allows you to specify that two files are to be linked by a key value, so that any changes in the record positioning of the first file will also affect the records retrieved from the second. The Join property provides a simple mechanism for browsing a relational database.
The joined fields in the "self-control must be index fields and must contain the same raw data as their corresponding fields in the master control. The fields in the master control do not have to be indexes. The IndexNumber property of the slave control must remain set to the index involved in the join or the join will be broken.
One-to-one, many-to-one, one-to-many, and many-to-many joins are all supported. The data can be displayed in a VAListBox in record list mode by setting its VAccessName property to the name of the slave control and its VAFieldName property to the fields to be displayed.
To join two VAccess controls:
Extended operations allow you to push the processing of requests for multiple records off to the Pervasive PSQL transactional interface. On network server-based Pervasive PSQL systems, extended operations can dramatically reduce network traffic and speed up data retrieval.
Extended operations are most useful when you are reading a number of records at a time. For example: scanning a file to collect and tabulate statistical data; requesting a number of records at once to populate a list, report, or grid; or performing an ad-hoc search of a database which does not have an appropriate index to collate the records you need.
Extended operations do not replace indexed record retrieval for accessing individual records, but they provide a powerful tool for retrieving sets of data quickly.
To enable extended operations:
Pervasive's ActiveX interface supports the following extended fetch methods:
Use the Init method after any changes to the SelectedFields or SelectedRecords properties, or between re-establishing current cursor positioning in the file with a single-record fetch method and invoking an extended fetch method.
With AutoMode enabled, the VAccess data source caches all of the rows which meet the selection criteria in memory as they are retrieved, allowing you to build a "snapshot" of the data. You can use the Row property to traverse the returned record set, or the RowColumnValue method to retrieve the value at any row and column in the set.
To use AutoMode:
AutoMode makes extended operations easier to use in some circumstances, but it is limited by available memory. You can disable AutoMode (default) and use the explicit extended fetch methods GetNextExtended, GetPreviousExtended, StepNextExtended, or StepPreviousExtended, to return data sets in discreet blocks.
The extended fetch methods GetNextExtended, GetPreviousExtended, StepNextExtended, and StepPreviousExtended begin at the current cursor position in a file and return a set of rows (records) and columns (fields) which meet a specified selection criterion. The Get methods use the current index to return records in index order. The Step methods return records ordered by physical position. Step methods are generally faster and should be used if the order of the records returned is not important.
Several properties are involved in setting the maximum number of records returned by a given extended fetch operation.
Current cursor positioning after an extended fetch operation corresponds to the last record scanned by the operation. This cursor positioning is indeterminate to the application if record selection criteria have been specified, as it may be beyond the last row actually retrieved.
The IncludeCurrent property setting determines whether the next extended fetch operation will scan the record at the current cursor position, or start with the subsequent record. In most circumstances you will not need to set this property. It is automatically set True by the Init method, False after an extended fetch. To include the record at the current cursor position in subsequent extended fetch operations, set this property to True immediately prior to the operation.
The ExtendedOps property can speed up and simplify joining VAccess data controls in a one-to-many relationship, such as the classic "order header record to order line items" example. Enabling extended operations on the joined data source, in this example the "order lines" control, will automatically build the appropriate query and cause the control to perform the join using extended operations, returning all of the records from the joined file which meet the join criteria as an extended fetch record set.
To use extended fetch operations most efficiently, first position the cursor at or as close as you can to the first record which will match your search criteria. Often you'll be able to use the GetEqual or GetGreaterOrEqual method with an index to establish initial positioning and limit the range of records Pervasive PSQL will have to scan to return the ones you need, and then use GetNextExtended to retrieve the subsequent records.
The CacheRejectMax property is useful if your SelectedRecords criterion limits records on the current index. You can use it to tell the Pervasive PSQL server process to stop when it encounters the first record that does not match your criteria, for example, setting the CacheRejectMax property value to 1.
If you have to scan an entire file, but the order of the records is not important, you can save some time by using the StepFirst method to position the cursor at the beginning of the file and the StepNextExtended method to scan it. The step methods are generally faster since they do not have to collate records along an index path.
You can also save time and resources by specifying only the fields you're interested in for the SelectedFields property. The limiting factor in extended fetch operations is the size of the data buffer, and the less memory you need for each row, the more rows you can return at a time.
Remember that because extended operations are executed by another task, typically a Pervasive PSQL server process, your application relinquishes control of the process as soon as it executes the extended query, and the other process takes over until the query conditions are satisfied. Therefore planning and optimizing extended queries can make a big difference in the performance of your application.
'Print a list of all Student ID's given a scholarship Q = Chr$(34) 'Student ID is an index, so we could use it to sort records, but 'our selection criteria has no index. Therefore, we must scan 'the entire database. To be efficient we will use Extended Ops VAccess1.ExtendedOps = True 'We can get Pervasive PSQL filter the records at the server by 'specifying the record selection criteria. VAccess1.SelectedRecords = "Scholarship_Amount > " & Q & "0" & Q 'Since all we need are the amounts and the Student ID's we can 'retrieve more records at once, by only returning this information. VAccess1.SelectedFields = "ID,Scholarship_Amount" 'Since we don't need to order the data, we should use step operations. 'Step operations are based on physical positions and will go through 'the database fastest. VAccess1.StepFirst VAccess1.Init Do Stat = VAccess1.StepNextExtended 'Note: extended fetch may return a status value, such as End of 'File (9), yet still return valid data. For R = 1 to VAccess1.Rows List1.AddItem VAccess1.RowColumnValue(R, 1) & Chr$(9) & _ Format(VAccess1.RowColumnValue(R, 2), "Currency") Next R Loop While Stat = 0
|
Chapter contents
Prev topic: Files and Directories
|