-
-
Notifications
You must be signed in to change notification settings - Fork 2
incendium.db.DisposableConnection
César Román edited this page Oct 26, 2020
·
13 revisions
A disposable connection enables a database connection in Ignition and disables it once the operation is completed to release resources.
DisposableConnection(db[, retries])
Args:
- db (str): The name of the database connection in Ignition.
- retries (int): The number of additional times to retry enabling the connection. Optional.
Returns:
- DisposableConnection: A DisposableConnection instance.
DisposableConnection is intended when a Database connection must be disabled immediately after usage.
Passing parameters.
# Imports.
import traceback
import incendium.db
from incendium import (constants, util)
from incendium.db import DisposableConnection
from incendium.exceptions import ApplicationError
from java.lang import Exception as JException
def some_function():
try:
with DisposableConnection('Some Connection', retries=10) as conn:
params = {'param1': [system.db.INTEGER, 1]}
incendium.db.execute_non_query('[schema].[procedure]', conn.db, params)
except IOError as e:
message = constants.UNEXPECTED_ERROR.format(
util.get_function_name(),
'\n'.join(traceback.format_exc().splitlines()))
raise ApplicationError(message, e)
except JException as e:
message = constants.UNEXPECTED_ERROR_CAUSED_BY.format(
util.get_function_name(),
'\n'.join(traceback.format_exc().splitlines()), e.cause)
raise ApplicationError(message, e, e.cause)