Working with active connections
The following examples show ways that you can work with an active database connection:
•Return the name of the connected database
•Find out of a specific table name exists in the connected database
•Return the active connection with a specific alias
SQLite notes:
•If you have not set up the SQLite SAMPLE database used by the following examples, please follow the instructions for Running examples with SQLite before continuing. •In the example code throughout this book, replace #AbtIbmCliDatabaseManager with #AbtSQLiteDatabaseManager before executing the code. There are some code snippets that will not work with SQLite , and some that will need to be altered slightly in order to work as SQLite may not support the function, or the interface for the function has not been implemented yet.. These will be noted.
"Connect to a database. Return the name of the database."
| conSpec |
conSpec := AbtDatabaseConnectionSpec
forDbmClass: #AbtIbmCliDatabaseManager
databaseName: 'SAMPLE'.
(conSpec connect) dataSourceName.
=======================================================================
"Connect to a database. Ask if the database contains
a given table name."
| conSpec |
conSpec := AbtDatabaseConnectionSpec
forDbmClass: #AbtIbmCliDatabaseManager
databaseName: 'SAMPLE'.
(conSpec connect) tableOrViewExistsNamed: 'ORG'.
"SQLite version:
Connect to a database. Ask if the database contains
a given table name."
| conSpec |
conSpec := AbtDatabaseConnectionSpec
forDbmClass: #AbtSQLiteDatabaseManager
databaseName: 'SAMPLE'.
(conSpec connect) allUserTableNames includes: 'ORG'.
=======================================================================
"If there is only one active connection, return the
connection. If there is no active connection, return
nil. If there is more than one active connection,
return the first one that was activated."
AbtDbmSystem activeDatabaseConnection.
=======================================================================
"Connect to a database with the alias SampleConSpec.
Return the active database connection with the
given alias."
| conSpec logonSpec |
conSpec := AbtDatabaseConnectionSpec
forDbmClass: #AbtIbmCliDatabaseManager
databaseName: 'SAMPLE'.
logonSpec := AbtDatabaseLogonSpec
id: 'userid'
password: 'password'
server: nil.
conSpec connectUsingAlias: 'SampleConSpec'
logonSpec: logonSpec.
AbtDbmSystem activeDatabaseConnectionWithAlias: 'SampleConSpec'.
Last modified date: 10/03/2020