BPS Script API  2.24.4
bps::Datastore Class Reference

The datastore class is used to access the BPS databases. More...

Public Member Functions

void checkin ()
 Check in the user by creating a record in table t_actors. More...
 
void checkout ()
 Check out the user by dropping the record in table t_actors. More...
 
void commit ()
 Commit an open transaction. More...
 
void connect ()
 Connect to database server using the current settings in the properties username, password, driver, database, host and port.
 
void disconnect ()
 Disconnect from database server if currently connected.
 
void dropConnection (Number aScopes=bps::Settings::LocalUserScope)
 Drop connection. More...
 
Number fieldLength (String aTable, String aColumn)
 Get the maximum length of a certain field in the default schema. More...
 
Boolean hasDivisionAccess (Number aDivisionKey)
 Checks if the current user is authorized for the division. More...
 
Boolean hasPermission (String aPermission)
 Checks if the current user is authorized for the named permission. More...
 
Boolean hasZoneAccess (Number aZoneKey)
 Checks if the current user is authorized for the zone. More...
 
Boolean indexExists (String aName, String aSchema="")
 Check if a certain index exists. More...
 
String indexTablespace ()
 Get the tablespace name used for indexes. More...
 
Boolean isCheckedIn ()
 Test if similar actor already checked in. More...
 
Boolean loadConnection (Number aScopes=bps::Settings::LocalScopes)
 Load connection settings. More...
 
Number nextIdent (String aSeqenceName)
 Get the next sequence value. More...
 
Number nextKey (String aName)
 Get the next unused key for a table. More...
 
void purgeActors ()
 Purge actors which are no longer connected. More...
 
String quote (String aText)
 Quote a literal text in single quotes to include it in a sql statement. More...
 
void renameConnection (QString aConnection, Number aScopes=bps::Settings::LocalUserScope)
 Rename the connection. More...
 
bps::Access reportAccess (Number aReportKey)
 Check access to a certain report. More...
 
void rollback ()
 Roll back an open transaction. More...
 
void saveConnection (Number aScopes=bps::Settings::LocalUserScope)
 Save the connection settings. More...
 
Boolean sequenceExists (String aName, String aSchema="")
 Check if a certain sequence exists. More...
 
Boolean tableExists (String aName, String aSchema="")
 Check if a certain table exists. More...
 
String tableTablespace ()
 Get the tablespace name used for tables. More...
 
void touchActor ()
 Update the actors timestamp. More...
 
void transaction ()
 Begin a new transaction. More...
 
Boolean viewExists (String aName, String aSchema="")
 Check if a certain view exists. More...
 

Properties

Number actorKey
 Returns the actor's identifier (the primary key c_key in the t_actors table). More...
 
Boolean connected
 Current connection status. More...
 
String connection
 Name of the current connection. More...
 
Array connections
 A list of all connections that have been declared in the BPS configuration program. More...
 
Date currentTimestamp
 The current timestamp from the datastore.
 
String database
 Database name for PostgreSQL, or TNS service name or SID for Oracle. More...
 
String driver
 The database driver name as BPSPG for PostgreSQL, or BPSORA for Oracle.
 
String host
 Either the database servers host name, or it's numeric IP address. More...
 
Boolean inTransaction
 True when the connection is currently in an uncommitted transaction. More...
 
Boolean oracle
 Current driver is Oracle (BPSORA). More...
 
Boolean owner
 True when current user is the BPS schema owner. More...
 
String password
 The database user's password. More...
 
Number port
 Get host IP port number. More...
 
Boolean postgres
 Current driver is PostgreSQL (BPSPG). More...
 
Array roles
 All database roles. More...
 
String schema
 The BPS schema name. More...
 
Number sessionId
 Returns the session ID (the database internal identifier of the current session). More...
 
Array tablespaces
 All tablespace names. More...
 
Array tnsnames
 List of all Oracle TNS names. More...
 
Number userid
 The userid, or -1 if not available. More...
 
Number userKey
 Returns the user's identifier (the primary key c_key in the t_users table). More...
 
String username
 The database user's name. More...
 
Array users
 All database user names. More...
 

Detailed Description

The datastore class is used to access the BPS databases.

It supports connections to PostgreSQL and to Oracle and encapsulates a Qt database connection, adding generic methods for both database types supported by BPS.

Member Function Documentation

◆ checkin()

void bps::Datastore::checkin ( )

Check in the user by creating a record in table t_actors.

Checking in is required for active users, because all permanent locks will be referencing the entry in t_actors. In case the current connection was already checked in, it will be checked out before attempting to do the new check in.

Exceptions
Errorthrown when not connected, no valid userid or general sql error.

◆ checkout()

void bps::Datastore::checkout ( )

Check out the user by dropping the record in table t_actors.

Exceptions
Errorthrown when not connected or general sql error.

◆ commit()

void bps::Datastore::commit ( )

Commit an open transaction.

Exceptions
Errorthrown when not connected or commit fails.

◆ dropConnection()

void bps::Datastore::dropConnection ( Number  aScopes = bps::Settings::LocalUserScope)

Drop connection.

The database properties are removed from the settings.

Parameters
[in]aScopesScopes at which the settings are removed. Valid scopes include BpsSettings::LocalUserSettings, BpsSettings::LocalSystemSettings and BpsSettings::LocalInstallSettings.
See also
saveConnection()

◆ fieldLength()

Number bps::Datastore::fieldLength ( String  aTable,
String  aColumn 
)

Get the maximum length of a certain field in the default schema.

Parameters
[in]aTableName of the table.
[in]aColumnName of the column.
Returns
The length, or -1 when column or its field length is unknown.

◆ hasDivisionAccess()

Boolean bps::Datastore::hasDivisionAccess ( Number  aDivisionKey)

Checks if the current user is authorized for the division.

Note
When owner is true, hasDivisionAccess() returns always true.
Parameters
[in]aDivisionKeyThe key within table t_divisions.
Returns
True if the division access is granted.

◆ hasPermission()

Boolean bps::Datastore::hasPermission ( String  aPermission)

Checks if the current user is authorized for the named permission.

Note
Permissions that were already queried before in the current session are cached in the datastore object for maximum speed. Therefore permission changes may not affect existing sessions witch queried them before the change.
When isOwner() is true, hasPermission() returns always true.
Parameters
[in]aPermissionThe permission name, for example settings.view
Returns
True if the permission is granted.

◆ hasZoneAccess()

Boolean bps::Datastore::hasZoneAccess ( Number  aZoneKey)

Checks if the current user is authorized for the zone.

Note
When isOwner() is true, hasZoneAccess() returns always true.
Parameters
[in]aZoneKeyThe key within table t_zones.
Returns
True if the zone access is granted.

◆ indexExists()

Boolean bps::Datastore::indexExists ( String  aName,
String  aSchema = "" 
)

Check if a certain index exists.

Parameters
[in]aNameName of the index.
[in]aSchemaSchema name. Default schema is used when omitted.
Exceptions
Errorthrown when the query fails.
Returns
True if the index exists, false otherwise.

◆ indexTablespace()

String bps::Datastore::indexTablespace ( )

Get the tablespace name used for indexes.

Note that this is only working for a existing BPS schema because it queries table t_users to get the information.

Returns
Name of the tablespace for BPS indexes.

◆ isCheckedIn()

Boolean bps::Datastore::isCheckedIn ( )

Test if similar actor already checked in.

Call this before checkin() to find out if a similar actor already exists.

Exceptions
BpsExceptionWhen not connected, no valid userid or general sql error.
Returns
True if a actor already exists that would get thrown out by a subsequent checkin() call.

◆ loadConnection()

Boolean bps::Datastore::loadConnection ( Number  aScopes = bps::Settings::LocalScopes)

Load connection settings.

When loading a connection that has been previously saved, the properties for node, schema, database, driver, host and port are searched and loaded from the locations defined in aScopes.

Parameters
[in]aScopesScopes at which the settings are searched. Valid scopes include BpsSettings::LocalUserSettings, BpsSettings::LocalSystemSettings and BpsSettings::LocalInstallSettings.
Returns
True if the connection settings were found and loaded.

◆ nextIdent()

Number bps::Datastore::nextIdent ( String  aSeqenceName)

Get the next sequence value.

Parameters
[in]aSeqenceNameThe name of the sequence.
Returns
Next identifier.

◆ nextKey()

Number bps::Datastore::nextKey ( String  aName)

Get the next unused key for a table.

Parameters
[in]aNameThe base name of the sequence and table, where the prefix s_ and t_ is added. Example: aName = users, sequence = s_users and table = t_users.
Returns
Next key as QVariant.

◆ purgeActors()

void bps::Datastore::purgeActors ( )

Purge actors which are no longer connected.

Such records can be present in case of crashed sessions. Removing them will release all permanent locks that still may be held.

Exceptions
Errorthrown when not connected or general sql error.

◆ quote()

String bps::Datastore::quote ( String  aText)

Quote a literal text in single quotes to include it in a sql statement.

Takes care of any single quotes within the literal.

Parameters
[in]aTextLiteral text to be quoted.
Returns
Quoted literal text.

◆ renameConnection()

void bps::Datastore::renameConnection ( QString  aConnection,
Number  aScopes = bps::Settings::LocalUserScope 
)

Rename the connection.

Parameters
[in]aConnectionNew name of the connection.
[in]aScopesScopes at which the settings are renamed. Valid scopes include BpsSettings::LocalUserSettings, BpsSettings::LocalSystemSettings and BpsSettings::LocalInstallSettings.

◆ reportAccess()

bps::Access bps::Datastore::reportAccess ( Number  aReportKey)

Check access to a certain report.

The connection must be established and checked in.

Parameters
aReportKeyThe key within table t_reports.
Returns
Access for current user.

◆ rollback()

void bps::Datastore::rollback ( )

Roll back an open transaction.

Exceptions
Errorthrown when not connected or rollback fails.

◆ saveConnection()

void bps::Datastore::saveConnection ( Number  aScopes = bps::Settings::LocalUserScope)

Save the connection settings.

The database properties are saved for subsequent availability by setConnection().

Parameters
[in]aScopesScopes at which the settings are saved. Valid scopes include BpsSettings::LocalUserSettings, BpsSettings::LocalSystemSettings and BpsSettings::LocalInstallSettings.
See also
dropConnection()

◆ sequenceExists()

Boolean bps::Datastore::sequenceExists ( String  aName,
String  aSchema = "" 
)

Check if a certain sequence exists.

Parameters
[in]aNameName of the sequence.
[in]aSchemaSchema name. Default schema is used when omitted.
Exceptions
Errorthrown when the query fails.
Returns
True if the sequence exists, false otherwise.

◆ tableExists()

Boolean bps::Datastore::tableExists ( String  aName,
String  aSchema = "" 
)

Check if a certain table exists.

Parameters
[in]aNameName of the table.
[in]aSchemaSchema name. Default schema is used when omitted.
Exceptions
Errorthrown when the query fails.
Returns
True if the table exists, false otherwise.

◆ tableTablespace()

String bps::Datastore::tableTablespace ( )

Get the tablespace name used for tables.

Note that this is only working for a existing BPS schema because it queries table t_users to get the information.

Returns
Name of the tablespace for BPS tables.

◆ touchActor()

void bps::Datastore::touchActor ( )

Update the actors timestamp.

Will usually be called by license check routines.

Exceptions
Errorthrown when not connected, actor token lost or invalid, or general sql error.

◆ transaction()

void bps::Datastore::transaction ( )

Begin a new transaction.

The transaction will be closed either by a call to commit, or a call to rollback.

Exceptions
Errorthrown when not connected or transaction cannot be started.

◆ viewExists()

Boolean bps::Datastore::viewExists ( String  aName,
String  aSchema = "" 
)

Check if a certain view exists.

Parameters
[in]aNameName of the view.
[in]aSchemaSchema name. Default schema is used when omitted.
Exceptions
Errorthrown when the query fails.
Returns
True if the view exists, false otherwise.

Property Documentation

◆ actorKey

Number bps::Datastore::actorKey
read

Returns the actor's identifier (the primary key c_key in the t_actors table).

A valid actorKey is only returned when checked in, otherwise Undefined is returned.

◆ connected

Boolean bps::Datastore::connected
read

Current connection status.

 

◆ connection

String bps::Datastore::connection
readwrite

Name of the current connection.

The database connection name is used to identify a certain connection within the application.

◆ connections

Array bps::Datastore::connections
read

A list of all connections that have been declared in the BPS configuration program.

Note
This property is static, e.g. must be accessed as bps.Datastore.connections instead of dbobj.connections

◆ database

String bps::Datastore::database
readwrite

Database name for PostgreSQL, or TNS service name or SID for Oracle.

Note
For Oracle the database name either refers to the TNS name or to the SID. In case a non-empty host name is given, the database is assumed to be the SID, when the host name is empty it is treated as the TNS name.

◆ host

String bps::Datastore::host
readwrite

Either the database servers host name, or it's numeric IP address.

Note
For Oracle, when using a TNS service name the host name must stay empty. If a host name or IP is set for Oracle, then a ad-hoc connection will be made using host name and port, and using the database property as SID.

◆ inTransaction

Boolean bps::Datastore::inTransaction
read

True when the connection is currently in an uncommitted transaction.

 

◆ oracle

Boolean bps::Datastore::oracle
read

Current driver is Oracle (BPSORA).

 

◆ owner

Boolean bps::Datastore::owner
read

True when current user is the BPS schema owner.

 

◆ password

String bps::Datastore::password
readwrite

The database user's password.

 

◆ port

Number bps::Datastore::port
readwrite

Get host IP port number.

The default is -1 which will assume 5432 for PostgreSQL and 1531 for Oracle (in case not using TNS).

◆ postgres

Boolean bps::Datastore::postgres
read

Current driver is PostgreSQL (BPSPG).

 

◆ roles

Array bps::Datastore::roles
read

All database roles.

Only available when connected as user with sufficient privileges (for example DBA or Superuser) to query the respective objects, otherwise nothing may be returned or an Error thrown.

◆ schema

String bps::Datastore::schema
readwrite

The BPS schema name.

 

◆ sessionId

Number bps::Datastore::sessionId
read

Returns the session ID (the database internal identifier of the current session).

A valid session ID is only returned when connected, otherwise Undefined is returned.

◆ tablespaces

Array bps::Datastore::tablespaces
read

All tablespace names.

Only available when connected as user with sufficient privileges (for example DBA or Superuser) to query the respective objects, otherwise nothing may be returned or an Error thrown.

◆ tnsnames

Array bps::Datastore::tnsnames
read

List of all Oracle TNS names.

Note
This property is static, e.g. must be accessed as bps.Datastore.tnsnames instead of dbobj.tnsnames
Because Oracle has never provided an API or discloses any information how the TNS names can be found, you cannot rely that all TNS names are found by this function. So you should allow your software to also use TNS names not returned in this list.

◆ userid

Number bps::Datastore::userid
read

The userid, or -1 if not available.

A valid userid is only present when the username is made up by {schema {userid}. The userid of the BPS owner is 0.

◆ userKey

Number bps::Datastore::userKey
read

Returns the user's identifier (the primary key c_key in the t_users table).

A valid userKey is only returned when checked in, otherwise Undefined is returned.

◆ username

String bps::Datastore::username
readwrite

The database user's name.

 

◆ users

Array bps::Datastore::users
read

All database user names.

Only available when connected as user with sufficient privileges (for example DBA or Superuser) to query the respective objects, otherwise nothing may be returned or an Error thrown.


The documentation for this class was generated from the following file: