The built-in functions in the CAPI package allow you to connect to generic SQL databases and perform general SQL statement operations. The CAPI package also manages the allocation of Livelink login objects and provides a number of convenience functions for use with any Livelink database.
The major functionalities offered in the CAPI Package are the following:
Example:
CAPILOG logFile CAPIERR errHandler CAPICONNECT connection Dynamic execResult RecArray records Record rec Dynamic transResult // Allocate a log and error object logFile = CAPI.AllocLog( 'c:\capi.log' ) errHandler = CAPI.AllocErr() // connect to the database connection = CAPI.AllocConnect( \ CAPI.CT_ORACLE,\ 'ORAHOST',\ '',\ 'orauser',\ 'orauserpwd',\ logFile, \ errHandler, \ 0 ) if ( IsError( connection ) ) echo( 'There was an error connecting' ) DumpErrorStack( errHandler ) else // Fetch all the records from myTable execResult = CAPI.Exec( connection, 'select * from myTable' ) if ( IsError( execResult ) ) echo( 'The select statement failed' ) DumpErrorStack( errHandler ) else if ( IsError( CAPI.StartTransaction( connection ) ) ) echo( 'The transaction could not be started' ) DumpErrorStack( errHandler ) else // Initialize the transaction result to COMMIT transResult = CAPI.COMMIT records = execResult // Loop through all the records, updating each one for rec in records echo( rec.myField ) // Update a record, using a parameterized statement execResult = CAPI.Exec(\ connection,\ "update myTable set myField=myField+1 where myField=:A1",\ rec.myField ) if ( IsError( execResult ) ) echo( 'An error occurred while updating the records' ) DumpErrorStack( errHandler ) transResult = CAPI.ROLLBACK break end end CAPI.EndTransaction( connection, transResult ) end end end function void DumpErrorStack( CAPIERR errLog ) Integer i Error code String errMsg String detail String msg Integer numErrors = CAPI.NumErrs( errLog ) if numErrors > 0 echo( " ----> Error stack" ) for i = 1 to numErrors code = CAPI.GetErrAt( errLog, i ) errMsg = Error.ErrorToString( code ) detail = CAPI.GetDetailAt( errLog, i ) msg = Str.ValueToString( code ) echo( " ----> ", i, ")", " ", msg, ":", code, ":", detail ) end end CAPI.ClearErr( errLog ) end
Integer COMMIT
Commits database changes when passed to CAPI.EndTransaction().
CT_DBLIBInteger CT_DBLIB
Specifies MSSQL as the database type when calling CAPI.AllocConnect() to create a CAPI connection.
CT_ODBCInteger CT_ODBC
Specifies ODBC as the database type when calling CAPI.AllocConnect() to create a CAPI connection.
CT_ORACLEInteger CT_ORACLE
Specifies Oracle as the database type when calling CAPI.AllocConnect() to create a CAPI connection.
ERR_CLEARInteger ERR_CLEAR
A flag used by CAPI.ErrOption() to set a given CAPIERR such that it discards accumulated errors when CAPI.ClearErr() is called on it.
ERR_KEEPInteger ERR_KEEP
A flag used by CAPI.ErrOption() to set a given CAPIERR such that it retains accumulated errors when CAPI.ClearErr() is called on it.
LOG_APPENDInteger CAPI_LOG_APPEND
A flag used by CAPI.AllocLog() to set the open mode for the log file.
LOG_TRUNCATEInteger CAPI_LOG_TRUNCATE
A flag used by CAPI.AllocLog() to set the open mode for the log file.
PROXY_NONEInteger CAPI_PROXY_NONE
A flag used in CAPI.RightsList() to retrieve the regular rights of the current user.
PROXY_WAPIInteger CAPI_PROXY_WAPI
A flag used in CAPI.RightsList() to retrieve the proxy rights for WAPI of the current user.
ROLLBACKError ROLLBACK
Rolls back a database transaction when passed to CAPI.EndTransaction().
AllocConnectCAPICONNECT AllocConnect( Integer type, String server, String database, String user, String password, CAPILOG log, CAPIERR err, Integer ctflags )
Allocates a CAPICONNECT object to the specified server and database. The type parameter must contain either CAPI.CT_CTLIB, CAPI.CT_MSDBLIB or CAPI.CT_ORACLE.
type | - | The type of connection to be established. |
server | - | The name of the server to connect to. |
database | - | The name of the database to be used. This parameter is left blank for Oracle. |
user | - | The database user name. |
password | - | The database user password. |
log | - | An optional log object, returned by CAPI.AllocLog(), that will associate a log file with the connection. |
err | - | An optional error object, returned by CAPI.AllocErr(), that will associate an error object with the connection. |
ctflags | - | Connection flags for internal use, set to zero. |
CAPIERR AllocErr()
Allocates a CAPIERR object for use when allocating a database connection with CAPI.AllocConnect().
CAPILOG AllocLog( String logFilePath, Integer openModeFlag )
Allocates a CAPILOG object for use when allocating a database connection with CAPI.AllocConnect().
logFilePath | - | The path to the log file created for this log object. |
openModeFlag | - | Optional param either CAPI.LOG_APPEND or default CAPI.LOG_TRUNCATE. |
CAPILOG AttachLog( String loggerName, [String logFilePath = '', Integer openModeFlag = CAPI.LOG_TRUNCATE] )
Attaches to or Allocates a CAPILOG object for use when allocating a database connection with CAPI, or for general logging functionality.
loggerName | - | The name of this logger (will be prefixed with Logging.CS_LOGGER_NAME_PREFIX, which is "com.opentext.contentserver.capi") |
logFilePath | - | Optionally, the path to the log file created for this log object if direct file output is desired. |
openModeFlag | - | Optional param either CAPI.LOG_APPEND or default CAPI.LOG_TRUNCATE. |
CAPILOGIN AllocLogin( CAPICONNECT connection, String username, String password, [String spaceName = ''] )
Allocates a CAPILOGIN object for the specified username and password.
connection | - | The database connection, returned by CAPI.AllocConnect(), which points to the Livelink database. |
username | - | The username of the Livelink user to be logged in. |
password | - | The password for the specified Livelink user. |
spaceName | - | The space or domain which the user belongs to. The default is an empty string for standard space or domain. |
Integer CheckRight( CAPILOGIN login, Integer rightID )
Determines if a user has a certain right in their rights list. An ID in a rights list corresponds to a particular group. For example, a group named "Collaborative Computing" may have the ID 3892. If the user is a member of this group or has been granted rights by this group, the ID 3892 will be found on the user's rights list.
login | - | The CAPILOGIN object for the user whose rights are being checked. |
rightID | - | The ID of the right that is being tested against the users rights list. |
Integer ClearErr( CAPIERR err )
Clears the current error stack for the specified CAPIERR object, unless the CAPI.ERR_KEEP flag has been set on the CAPIERR with CAPI.ErrOption(), in which case errors will be retained despite the clear call (default behavior may be restored by calling CAPI.ErrOption() with the CAPI.ERR_CLEAR flag). When an error occurs for a given database connection, the error is placed on the error stack. This function allows all accumulated errors to be removed from that stack.
err | - | The CAPIERR object |
Assoc ConnectionAttr( CAPICONNECT connection )
Returns attribute information for the specified database connection.
connection | - | The connection for which information should be returned. |
ConnectionType | - | The type of connection (CT_ORACLE, CT_CTLIB, CT_MSDBLIB) |
DatabaseType | - | An internal constant identifying type of database |
DatabaseServer | - | The name of the server for this connection |
DatabaseName | - | The name of the database for this connection |
DatabaseUser | - | The database user for this connection |
DatabasePWD | - | The password for the database connection |
DatabaseAppl | - | The internal application name this connection is using |
DatabaseHost | - | The host name for the client connection |
Flags | - | Internal flags |
Depth | - | The current transaction depth (0-n) |
MaxLength | - | The maximum length of a character field for the database |
MaxLongLength | - | The maximum length of a long data type for the database |
SubQueriesCanAccessBlobs | - | TRUE if this database supports sub queries that access blob in a table, otherwise FALSE |
CanInsertSelectWithSameTable | - | TRUE if this database supports inserts statements that use a select on the same table, otherwise FALSE |
CanProcessTree | - | TRUE if this database can perform hierarchical joins in a select statement, otherwise FALSE |
CanExecuteN | - | TRUE if this database can execute a statement multiple times with different parameters, otherwise FALSE |
IsCaseSensitive | - | TRUE if this database is case sensitive, otherwise FALSE |
SupportIdentity | - | TRUE if this database supports identity columns, otherwise FALSE |
IsValid | - | TRUE if the connection is still valid, otherwise FALSE. |
RecArray ConnectionInfo( [CAPICONNECT connect] )
Returns information about one or all of the currently active connections. If no connection is specified, information about all open connections is returned.
connect | - | An optional parameter specifying the connection for which information is desired. |
CONNECT | - | The CAPICONNECT object itself |
SQL | - | A reference to the internal SQL object |
CTYPE | - | The connection type |
CFLAGS | - | Internal flags |
SERVER | - | The server name for this connection |
DBNAME | - | The database name for this connection |
USER | - | The database user for this connection |
PASSWORD | - | The password for the database connection |
REFCNT | - | The current refcount for this CAPICONNECT object |
Dynamic ContextData( Dynamic value, [Dynamic valueIn] )
Gets or sets application specific information from a CAPICONNECT or one of its children. All objects which are derived from a CAPICONNECT object (CAPILOGIN, DAPISESSION, UAPISESSION, etc) can hold application specific information. If the optional second parameter is passed, the context data for the specified object will be set.
value | - | The Object which is having its context data either set or fetched. |
valueIn | - | An optional parameter which, when present, sets the value of the context data besides returning it. |
Integer Disconnect( CAPICONNECT connection )
Disconnects the CAPICONNECT from its database. Note, this does not deallocate the CAPICONNECT, the CAPICONNECT will only be deallocated when it goes out of scope. When a CAPICONNECT goes out of scope, it is automatically disconnected from its database.
connection | - | The connection object that is being disconnected from its database. |
Integer EndTransaction( Dynamic connectionOrLogin, Dynamic commitOrRollback )
Ends the current database transaction on the specified database connection.
Note that CAPI keeps a running tally of the number of times that CAPI.StartTransaction() has been called since the last CAPI.EndTransaction(). In order for a commit to actually take place, the number of StartTransactions for a given operation must be balanced by an equal number of EndTransactions and all EndTransactions must pass CAPI.COMMIT. This structure allows multiple levels of an application to all call StartTransaction and EndTransaction while still allowing the highest level of the code to maintain ultimate controls over the transaction. If, at any level, CAPI.ROLLBACK is passed, the entire transaction will be rolled back at that point.
connectionOrLogin | - | A CAPICONNECT or CAPILOGIN object |
commitOrRollback | - | CAPI.COMMIT for a commit, CAPI.ROLLBACK to rollback a transaction. |
Integer ErrOption( CAPIERR err, Integer flag )
Sets the flag controlling clear behavior within a CAPIERR given either the flag CAPI.ERR_CLEAR, to clear errors, or CAPI.ERR_KEEP to keep errors when CAPI.ClearErr() is called upon the CAPIERR.
err | - | A CAPIERR. |
flag | - | Specifies what to do with the errors within the CAPIERR, either CAPI.ERR_CLEAR to clear them or CAPI.ERR_KEEP to retain them upon clear. |
Dynamic Exec( CAPICONNECT connection, String statement, [Dynamic sub<n>] )
Executes a given SQL statement.
Parameterized statements where each parameter is denoted by :A<n> may be used for increased performance. When a parameterized statement is used, the values for the SQL statement parameters are passed as optional arguments to the builtin function. Alternatively, a single List may be passed as the third argument, in which case the elements of the list are used as the values for the parameters in the statement. Any number of parameters may be specified in the statement. If specifying a List as the third argument, no more than three arguments should be passed to the Exec builtin function.
connection | - | The CAPICONNECT object. |
statement | - | The SQL statement to be executed. |
arg3-n | - | Any parameter values required by the statement. The values to be used for SQL statment parameters may be passed as either a single List argument, or as a variable number of arguments, as with Str.Format(). If passing a List of parameter values, no more than three arguments should be passed to the Exec builtin function. |
Here are two short examples:
// Return all values in myTable Dynamic result = CAPI.Exec( connect, "select * from myTable" ) // Insert the value 1 into myTable Dynamic result = CAPI.Exec( connect, "insert into myTable values ( :A1 )", 1 )
Dynamic ExecN( CAPICONNECT connection, String statement, RecArray values )
Executes a given SQL statement once for each row in the RecArray.
This function is most useful for efficiently executing the same parameterized statement multiple times with different values. For example, a parameterized insert or update statement may be executed 20 times with different values for its parameters based on the 20 rows in the passed in RecArray.
connection | - | The CAPICONNECT object. |
statement | - | The SQL statement to be executed. |
values | - | A RecArray for containing the substitution values for the parameters in the statement. |
Dynamic ExecSP( CAPICONNECT connection, String statement, [Dynamic sub<n>] )
Executes a given SQL statement which will execute a stored procedure.
Parameterized statements where each parameter is denoted by :A<n> may be used for increased performance. When a parameterized statement is used, the value for the parameters are passed as optional parameters. Any number of parameters may be specified in the statement.
connection | - | The CAPICONNECT object. |
statement | - | The SQL statement to be executed. |
arg3-n | - | Any parameter values required by the statement. |
Here is a short examples:
// Who is logged onto the DBMS Dynamic result = CAPI.ExecSP( connect, "sp_who" )
String GetDetailAt( CAPIERR err, Integer index )
Retrieves the detail information associated with a specified error.
This function is often used in looping constructs to examine all errors currently stored in a specified error object. Use CAPI.NumErrs() to retrieve the total number of errors stored in the error object.
err | - | The CAPIERR object. |
index | - | The index location of the desired error in the error stack. |
Error GetErrAt( CAPIERR err, Integer index )
Retrieves the identified error from the specified error object.
This is often used in looping constructs to examine all errors currently stored in a specified error object. Use CAPI.NumErrs() to retrieve the total number of errors stored in the error object.
err | - | The CAPIERR object. |
index | - | The index location of the desired error in the error stack. |
Integer IniDelete( CAPILOGIN login, [String section], [String keyword] )
Deletes information from the KIni table.
If the optional section parameter if not passed, all rows in the KIni table will be deleted. If the optional keyword parameter is not passed, all values in the specified section will be deleted.
login | - | The CAPILOGIN object. |
section | - | An optional string specifying the section to affect in the KIni table. |
keyword | - | An optional string specifying the keyword to delete from the specified section. |
Dynamic IniGet( CAPILOGIN login, String section, String keyword, [Dynamic dftValue] )
Retrieves the value associated with the specified section and keyword from the KIni table.
login | - | The CAPILOGIN object. |
section | - | The section in the KIni table where the keyword is located. |
keyword | - | The keyword for the value to be returned |
dftValue | - | A default value to be returned if the specified section and keyword pair cannot be found. |
RecArray IniList( CAPILOGIN login, [String section], [String keyword] )
Returns all keyword values in the specified section of the KIni table.
If the optional section parameter is not passed, all the data from the KIni table will be returned.
If the optional keyword parameter is not passed, all the data from the section in the KIni table will be returned.
login | - | The CAPILOGIN object. |
section | - | An optional parameter specifying the section to be listed from the KIni table. |
keyword | - | An optional parameter specifying the keyword to be listed in the section from the KIni table. |
Integer IniPut( CAPILOGIN login, String section, String keyword, [Dynamic value] )
Allows values to be added into the KIni table or to overwrite existing information.
If the value parameter is not passed, the section/keyword value will be set to NULL in the database.
login | - | The CAPILOGIN object. |
section | - | The section where the value will be inserted. |
keyword | - | The keyword for the value. |
value | - | An optional value to be inserted for the section and keyword. |
Boolean IsValid( CAPICONNECT connection )
Checks to ensure a previously established database connection is still valid.
This is very useful for determining cases where the database connection has unexpectedly dropped due to network or database server problems.
connection | - | The CAPICONNECT object. |
Dynamic Log( CAPILOG log, String message )
Writes the specified INFO message to the connection log file. This is an alias of LogInfo
log | - | The CAPILOG object. |
message | - | The message to be written to the log file. |
Dynamic LogError( CAPILOG log, String message )
Writes the specified ERROR message to the connection log file.
log | - | The CAPILOG object. |
message | - | The error message to be written to the log file. |
Dynamic LogInfo( CAPILOG log, String message )
Writes the specified INFO message to the connection log file.
log | - | The CAPILOG object. |
message | - | The info message to be written to the log file. |
Dynamic LogWarn( CAPILOG log, String message )
Writes the specified WARN message to the connection log file.
log | - | The CAPILOG object. |
message | - | The warning message to be written to the log file. |
RecArray LoginInfo( [CAPILOGIN login] )
Returns information about one or all of the currently active logins. If no login is specified, information about all current logins is returned
login | - | An optional parameter specifying the login for which information is desired. |
LOGIN | - | The CAPILOGIN object itself |
CONNECT | - | The CAPICONNECT that this login was allocated from. |
USERNAME | - | The Livelink user |
USERPWD | - | The password for the Livelink user |
USERID | - | The unique ID for this user |
GROUPID | - | The default group for this user |
PRIVS | - | The privileges for this user |
REFCNT | - | The current refcount for this CAPILOGIN object |
Date Now( CAPICONNECT connect )
Returns the current date and time for the database server specified by the CAPICONNECT.
connect | - | The CAPICONNECT object indicating the database server for which the current date and time is returned. |
Integer NumErrs( CAPIERR error )
Determines the number of errors stored in the specified error object.
error | - | The CAPIERR object for which the number of errors is returned. |
Dynamic Parent( Dynamic value )
Retrieves the parent object for the specified object. For example, CAPILOGIN objects will return their associated CAPICONNECT object. DAPISESSION objects, UAPISESSION objects and WAPISESSION objects will return their associated CAPILOGIN object.
value | - | The object for which the parent object is desired. |
CAPILOGIN | - | A CAPICONNECT object |
DAPISESSION | - | A CAPILOGIN object |
UAPISESSION | - | A CAPILOGIN object |
WAPISESSION | - | A CAPILOGIN object |
DAPINODE | - | A DAPISESSION object |
DAPIVERSION | - | A DAPINODE object |
Integer RestartTransaction( Dynamic connectOrLogin, Dynamic status )
Restarts a database transaction that was previously started by CAPI.StartTransaction(), preserving the current transaction depth.
connectOrLogin | - | The CAPICONNECT or CAPILOGIN owning the transaction. |
status | - | A constant indicating what action to perform on the specified transaction. Acceptable values are CAPI.COMMIT and CAPI.ROLLBACK. |
RecArray RightsList( CAPILOGIN login, [Integer proxyType] )
Returns a RecArray containing the ID numbers of all groups and projects of which the specified user is a member.
login | - | The CAPILOGIN object for the user. |
proxyType | - | The proxy type. The default is CAPI.PROXY_NONE. |
Name | - | The name of the right. |
Type | - | The type of the right. |
Description | - | A description of the right. |
Assoc RightsSet( CAPILOGIN login )
Returns an assoc with keys containing the rights ID of the current user.
login | - | The CAPILOGIN object for the user. |
String RightsString( CAPILOGIN login, String columnName )
Returns a string containing all the right ids for the specified user formatted for use in an SQL statement's "where" clause. The column name in the second parameter will be used to format the "where" clause.
login | - | The CAPILOGIN object for the specified user. |
columnName | - | The column name to use when formatting the string. |
Integer StartTransaction( Dynamic connectOrLogin, [Integer numberOfIds] )
Begins a new database transaction on the specified CAPICONNECT or CAPILOGIN. If a CAPILOGIN is specified, the connection used to allocate the login will be used in the transaction. The optional second parameter is useful for specifying the number of unique database ids this transaction will use. If the number of unique ids in a given user's cache is exhausted during the transaction, locking problems on the KID table may result.
Transactions created via the CAPI interface are reference counted. This means that the initial call to StartTransaction will actually begin the transaction and subsequent calls to StartTransaction, made before an EndTransaction, will simply increment a count. This way, multiple levels of an application can implement transaction control without having to be aware of the controlling code.
connectOrLogin | - | The CAPICONNECT or CAPILOGIN to be used for the transaction. |
numberOfIds | - | The number of unique ids to reserve for this transaction. |
Here is an example:
Integer status status = CAPI.StartTransaction( myConnect ) // A transaction starts. Refcount=1 ... MyFunction( myConnect ) // Call a subroutine ... CAPI.EndTransaction( myConnect, CAPI.COMMIT ) // The transaction is actually committed Function MyFunction( CAPICONNECT connect ) Integer status status = CAPI.StartTransaction( connect ) // Transaction refcount goes to 2 ... CAPI.EndTransaction( myConnect, CAPI.COMMIT ) // The refcount drops back to 1 end
Integer TransactionDepth( Dynamic connectOrLogin )
Determines the current transaction depth or the current refCount for the specified connection or login. If a login is specified, the connection that is associated with the login will be used.
connectOrLogin | - | The CAPICONNECT or CAPILOGIN to be used for the transaction |
Integer UniqueID( Dynamic connectOrLogin, Integer unused, [Integer numIds] )
Generates a new, unique ID from the internal Livelink ID cache. Each unique ID that is generated will be unique across the entire Livelink database. If the optional numIds parameter is used, the first id that was allocated will be returned but, the next n ids will be in consecutive order.
connectOrLogin | - | The CAPICONNECT or CAPILOGIN to be used for the transaction. |
unused | - | This parameter is no longer used. It should be 0. |
numIds | - | The number of unique ids to be allocated. |
Integer UpdateRights( CAPILOGIN login )
Updates the rights list that is cached by the specified login. This call is useful for making sure that the rights list inside of a specified login remains in sync with the actual data in the Livelink database.
login | - | The CAPILOGIN which is to be refreshed. |
Integer UserID( CAPILOGIN login, [Integer userId] )
Returns the specified user's ID or allows an administrator to log-in as a particular user. If the optional userId is specified and the login is the Administrator's login, the Administrator login will be changed to represent a login for the specified user Id.
login | - | The CAPILOGIN for the user to be examined. |
userId | - | The user ID that the Administrator requests to login as. |
Boolean UseRightsString( CAPILOGIN login )
Returns TRUE if the rights string query with multiple in clauses can be used for this current user.
login | - | The CAPILOGIN for the user to be examined. |
RecArray UserInfo( CAPILOGIN login )
Returns information about the current user for the specified CAPILOGIN object.
login | - | The CAPILOGIN for the user to be examined. |
ID | - | Integer | - | The user ID |
OWNERID | - | Integer | - | The user ID of the user who created the group |
TYPE | - | Integer | - | The user's class membership type |
NAME | - | String | - | The name of the group of which the user is a member |
USERDATA | - | Dynamic | - | The user's information |
USERPWD | - | Dynamic | - | The user's password in encrypted format |
GROUPID | - | Integer | - | The user's group ID |
USERPRIVILEGES | - | Integer | - | The user's privileges |
LASTNAME | - | String | - | The user's last name |
MIDDLENAME | - | String | - | The user's middle name |
FIRSTNAME | - | String | - | The user's first name |
MAILADDRESS | - | String | - | The user's e-mail address |
GROUPOWNERID | - | Integer | - | The user ID of the user who created the user's group |
GROUPTYPE | - | Integer | - | The class membership type of the user's group |
GROUPNAME | - | String | - | The name of the user's group |
GROUPUSERDATA | - | Dynamic | - | The group information for the user's group |