Programming Interfaces
Show this topic in Library frames
This release of Pervasive.SQL 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.SQL 9 are:
- Revisions to the percentage operations implementation that improve the accuracy of the operations.
- The addition of a granularity setting in both operations that allow you to choose the factor by which the percentage is measured. In previous releases, this value was always 10,000.
Note
The improved accuracy in Pervasive.SQL 9 is available whether or not you use the expanded API to specify a granularity other than 10,000.
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
- Place
ExPc in the second four bytes of the data buffer.
- 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.
- 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.SQL 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.SQL 9 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
- The previous functionality of the Create operation is intact. Follow the existing documentation on the Create operation if you want to create a new MicroKernel data file.
- The RenameFile and DeleteFile subfunctions cannot be used on files that are bound to specific databases because they do not affect the contents of the miscellaneous page.
- If a file contains an Owner name, the owner name check is not performed by the new subfunctions. The owner name is still needed to view the contents of the files.
Distributed Tuning Interface Improvements
The Distributed Tuning Interface (DTI) has these improvements in Pervasive.SQL 9:
- New APIs to better integrate with the security features introduced with Pervasive.SQL v8.5.
For more information, see:
As part of this addition, the PvCreateDictionary() and PvOpenDictionary() APIs are now deprecated. Future releases will not support these APIs although support is not removed for them in Pervasive.SQL 9.
- New PvCopyDatabase() API to copy an entire database to a new database, adjusting referential integrity if needed.
For more information, see PvCopyDatabase() .
- Expanded return codes for PvConnectServer() so that you can better detect the exact cause of a connection failure.
For more information, see Enhanced PvConnectServer() Error Messages .
- PvDropDatabase - a previously reserved parameter is now used as an options bitmask. Substitute the following table row for the options parameter for PvDropDatabase() in the Pervasive.SQL v8.5 SDK documentation.
|
In
|
option
|
Bit mask that specifies options. Set the low order bit to one (0001h) if you want data files to be deleted in addition to the database name. Otherwise, only the database name will be deleted but data and DDF files will remain.
|
- The following restrictions have been added to PvAddTable().
- If you use PvOpenDictionary() to obtain a dictionary handle, you will encounter an error (
PCM_errFailed) if you use PvAddTable() against a secured database. Use PvOpenDatabase() instead and specify security credentials.
- When describing the indexes, you must ensure that every index has segment numbers beginning with zero. When the index contain multiple segments, each segment must start numbering at zero. If no zero is found, you will encounter the error
PCM_errFirstSegmentNumberMustBeZero.
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:
- DTI session started by calling PvStart()
- Connection established by PvConnectServer() or if you are performing the operation on a local machine, P_LOCAL_DB_CONNECTION may be used as the connection handle.
- If the database has security enabled, you must specify a valid database user name and password. Security for the returned database handle is enforced based on the access rights defined for the database, and should match behavior seen in SQL or ODBC interfaces.
PvCloseDatabase()
Closes an open database handle.
Header file: CATALOG.H
Requires: W3DBAV90.DLL or higher version
Syntax
PRESULT PvCloseDatabase(
PS_UINT16 dbHandle);
Arguments
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:
- DTI session started by calling PvStart()
- Connection established by PvConnectServer() or if you are performing the operation on a local machine, P_LOCAL_DB_CONNECTION may be used as the connection handle.
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:
- DTI session started by calling PvStart()
- Connection established by PvConnectServer() or if you are performing the operation on a local machine, P_LOCAL_DB_CONNECTION may be used as the connection handle.
- When you enable database security, you must specify Master as the database user name and choose a password. Security for the database is enforced based on the access rights defined for the database, and should match behavior seen in SQL or ODBC interfaces.
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:
- DTI session started by calling PvStart().
- Connection established by PvConnectServer() or if you are performing the operation on a local machine, P_LOCAL_DB_CONNECTION may be used as the connection handle.
- Database is secured
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:
- DTI session started by calling PvStart()
- Connection established by PvConnectServer() or if you are performing the operation on a local machine, P_LOCAL_DB_CONNECTION may be used as the connection handle.
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:
- DTI session started by calling PvStart().
- Connection established by PvConnectServer() or if you are performing the operation on a local machine, P_LOCAL_DB_CONNECTION may be used as the connection handle.
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.
|