PreviousWhat's New in Pervasive PSQL v9.0 (v9 SP2 (9.5) revision 1) Next

Programming Interfaces

Chapter contents

This release of Pervasive PSQL includes the following changes to the programming interfaces:

Btrieve API Improvements

Increased Accuracy in Extended Percentage Operations

The accuracy of GetByPercentage (44) and FindPercentage (45) operations have been improved with respect to finding a record or a percentage along a key path.

The improvements to the percentage operations for Pervasive PSQL v9 are:

If you do want to specify the granularity, you can do so when performing either operation by following these steps:

To specify a granularity in extended percentage operations

  1. Place ExPc in the second four bytes of the data buffer.
  2. Place the desired granularity in the third four bytes as a LoHi Intel integer. The granularity you choose can be any number from 1 to 0xFFFFFFFF.
  3. Ensure that your data buffer length is at least 12 bytes.

For example if you want to get the 100th record from a file that contains 365 records, you can use GetByPercentage with 100 as the percentage, and 365 as the granularity.

Delete and Rename Subfunctions for the Create Operation

The Create operation now has two additional subfunctions that you can use to delete or rename files.

In releases prior to Pervasive PSQL v8.5, it was always possible to manipulate Btrieve files through the operating system, because Btrieve depended on the rights and privileges given by the operating system to the Btrieve user.

If you have a secure Pervasive PSQL v9 database, however, these operating system access rights may have been removed in the process of securing the database from unauthorized access. This makes programmatically deleting or moving the files difficult since the rights required are not always available.

Using the Rename and Delete Subfunctions

The rename and delete subfunctions are implemented as Create operations with new key numbers. You do not need to provide a file specification as you do when creating a new data file. The following table shows how you set up the Create operation to use the rename or delete subfunctions.

Table 1-6 Create Operation Subfunctions
Function
Key Number to Use
Description
Place in Data Buffer
Place in Key Buffer
Rename File
-127
Rename an existing file in the data buffer to the name in the key buffer
Existing File Name
New File Name
Delete File
-128
Delete a file
N/A
Existing File Name

These APIs have all been modified to work with the security model in that they will accept a URI in place of a file name in the key buffer and data buffer, if needed, to indicate a Btrieve file to delete or rename. This allows you to provide security information with the operation.

The security information is processed just like a normal Create or Open operation. The user must be authenticated and have DB_RIGHT_CREATE, DB_RIGHT_ALTER and DB_RIGHT_OPEN privileges for the existing files and for the directory where the new file will be located if applicable.

Table 1-7 Create Subfunctions - use of URI Parameters in Key Buffer
Function
URI parameter file=
URI parameter dbfile=
URI parameter table=
Rename

Delete

Table 1-8 Create Subfunctions - use of URI Parameters in Data Buffer
Function
file=
dbfile=
table=
Rename

Delete
Not applicable
Not applicable
Not applicable

Notes on Rename and Delete Subfunctions

Distributed Tuning Interface Improvements

The Distributed Tuning Interface (DTI) has these improvements in Pervasive PSQL v9:

PvOpenDatabase()

Opens a database by name and returns a handle that can be used to manipulate the database catalog. This function replaces PvOpenDictionary().

Header file: CATALOG.H
Requires: W3DBAV90.DLL or higher version

Syntax
BTI_API PvOpenDatabase( 
	BTI_LONG           hConnection, 
	BTI_CHAR_PTR       dbName, 
	BTI_CHAR_PTR       dbUser, 
	BTI_CHAR_PTR       dbPassword, 
	BTI_WORD_PTR       dbHandle); 
Arguments

In
hConnection
Connection handle that identifies the server. Connection handles are obtained with the PvConnectServer() function.
In
dbName
Name of the database.
In
dbUser
Database user name if security is defined.
In
dbPassword
Database password if security is defined.
In
dbHandle
Returned handle to the database.

Return Values

P_OK
The operation was successful.
P_E_INVALID_HANDLE
Invalid connection handle.
P_E_NULL_PTR
Call with NULL pointer
P_E_ACCESS_RIGHT
Insufficient access right for the operation.
P_E_FAIL
Failed to open the database for other reasons.
PCM_errSessionSecurityError
Invalid user name or password

Remarks

The following preconditions must be met:

PvCloseDatabase()

Closes an open database handle.

Header file: CATALOG.H
Requires: W3DBAV90.DLL or higher version

Syntax
PRESULT PvCloseDatabase( 
	PS_UINT16       dbHandle); 
Arguments

In
dbHandle
Handle to a database opened by PvOpenDatabase().

Return Values

PCM_Success
The operation was successful.
PCM_errFailed
Operation was not successful.
PCM_errMemoryAllocation
An error occurred during memory allocation
PCM_errDictionaryNotOpen
No database open with specified handle.

Remarks

The following preconditions must be met:

PvSecureDatabase()

Enables database security for an existing database.

Header file: CATALOG.H
Requires: W3DBAV90.DLL or higher version

Syntax
BTI_API PvSecureDatabase( 
	BTI_LONG           hConnection, 
	BTI_CHAR_PTR       dbName, 
	BTI_CHAR_PTR       dbUser, 
	BTI_CHAR_PTR       dbPassword); 
Arguments

In
hConnection
Connection handle that identifies the server. Connection handles are obtained with the PvConnectServer() function.
In
dbName
Name of the database.
In
dbUser
Database user name - must be Master to set security.
In
dbPassword
Database password to use for Master user.

Return Values

P_OK
The operation was successful.
P_E_INVALID_HANDLE
Invalid connection handle.
P_E_NULL_PTR
Call with NULL pointer
P_E_ACCESS_RIGHT
Insufficient access right for the operation.
P_E_FAIL
Failed to open the database for other reasons.
PCM_errSessionSecurityError
Invalid user name or password

Remarks

The following preconditions must be met:

PvUnSecureDatabase()

Disables database security on a database.

Header file: CATALOG.H
Requires: W3DBAV90.DLL or higher version

Syntax
BTI_API PvUnSecureDatabase( 
	BTI_LONG           hConnection, 
	BTI_CHAR_PTR       dbName, 
	BTI_CHAR_PTR       dbUser, 
	BTI_CHAR_PTR       dbPassword); 
Arguments

In
hConnection
Connection handle that identifies the server. Connection handles are obtained with the PvConnectServer() function.
In
dbName
Name of the database.
In
dbUser
Database user name - must be Master to enable or disable security.
In
dbPassword
Database password for Master user.

Return Values

P_OK
The operation was successful.
P_E_INVALID_HANDLE
Invalid connection handle.
P_E_NULL_PTR
Call with NULL pointer
P_E_ACCESS_RIGHT
Insufficient access right for the operation.
P_E_FAIL
Failed to open the database for other reasons.
PCM_errSessionSecurityError
Invalid user name or password

Remarks

The following preconditions must be met:

PvIsDatabaseSecured()

Determines whether a given database has security enabled.

Header file: CATALOG.H
Requires: W3DBAV90.DLL or higher version

Syntax
BTI_API PvIsDatabaseSecured( 
	BTI_LONG           hConnection, 
	BTI_CHAR_PTR       dbName, 
	BTI_LONG_PTR       secured); 
Arguments

In
hConnection
Connection handle that identifies the server. Connection handles are obtained with the PvConnectServer() function.
In
dbName
Name of the database to check.
Out
secured
1 if database is secured
0 if database is not secure

Return Values

P_OK
The operation was successful.
P_E_INVALID_HANDLE
Invalid connection handle.
P_E_NULL_PTR
Call with NULL pointer
P_E_ACCESS_RIGHT
Insufficient access right for the operation.
P_E_FAIL
Failed to open the database for other reasons.

Remarks

The following preconditions must be met:

PvCopyDatabase()

Copies a database to a new database, adjusting the referential integrity of needed.

Header file: CATALOG.H
Requires: W3DBAV90.DLL or higher version

Syntax
BTI_API PvCopyDatabase( 
	BTI_LONG           hConnection, 
	BTI_CHAR_PTR       dbName, 
	BTI_CHAR_PTR       newdbName, 
	BTI_CHAR_PTR       newdictPath, 
	BTI_CHAR_PTR       newdataPath); 
Arguments

In
hConnection
Connection handle that identifies the server. Connection handles are obtained with the PvConnectServer() function.
In
dbName
Name of the database to copy.
In
newdbName
Name of the new database.
In
newdictPath
Dictionary path of the new database. .
In
newdatapath
Data path. Pass an empty string to use the default data path (that is, the same as the dictionary path)
If you want to create a new database that consists of MicroKernel data files located in multiple paths, specify this parameter as a semicolon (;) delimited list. For example: C:\data\path1;C:\data\path2

Return Values

P_OK
The operation was successful.
P_E_INVALID_HANDLE
Invalid connection handle.
P_E_NULL_PTR
Call with NULL pointer
P_E_ACCESS_RIGHT
Insufficient access right for the operation
P_E_DICTIONARY_ALREADY_EXISTS
Cannot create dictionary because it already exists.
P_E_SHARED_DDF_EXIST
Cannot create DDF files because
P_E_DUPLICATE_NAME
Named database already exists on the server.
P_E_FAIL
Failed for other reasons.

Remarks

The following preconditions must be met:

Example
BTI_LONG connectionHandle = P_LOCAL_DB_CONNECTION; 
BTI_CHAR_PTR newdataPath = "c:\\data\\gallery2"; 
BTI_CHAR_PTR newdictPath = "c:\\data\\gallery2"; 
BTI_CHAR_PTR databaseName = "Gallery"; 
BTI_CHAR_PTR newdatabaseName = "GalleryCopy"; 
BTI_SINT status = 0; 
BTI_CHAR_PTR server = "MyServer"; 
BTI_CHAR_PTR user = "Administrator"; 
BTI_CHAR_PTR pwd = "Admin"; 
//only need to connect to server if it is remote 
//otherwise can pass P_LOCAL_DB_CONNECTION for the 
handle 
status = PvCopyDatabase( 
connectionHandle, 
databaseName, 
newdatabaseName 
dictPath, 
dataPath); 

Enhanced PvConnectServer() Error Messages

Prior to this release, the PvConnect() API returned the error message P_E_FAIL (connection failed) for all connection-related failures. The true cause of the connection failure was not easily ascertained.

In this release, PvConnect() will return any of the following status codes in place of P_E_FAIL (status 7004).

Table 1-9 New Error Messages for PvConnectServer()
New Code
Explanation
P_E_SERVER_NOT_FOUND
The specified server was not found
P_E_ENGINE_NOT_LOADED
The specified engine is not running.
P_E_REQUESTER_NOT_LOADED
The client requester is not loaded.
P_E_SERVER_TABLE_FULL
The internal server name table is full.
P_E_CLIENT_CONNECTIONS_
LIMIT_REACHED
The operation could not connect because the limit on client connections has been reached. Check the configuration of the server.
P_E_PERMISSION_ERROR
The operation encountered a permissions error.
P_E_NO_MEMORY
The operation encountered a memory error.
P_E_NO_AVAILABLE_TRANSPORT
No remote connection could be established.
P_E_CONNECTION_LOST
The remote connection to the server was lost.


Chapter contents
Book contents

Prev topic: Network Communications
Next topic: Relational Interface Support