Search

User Manual

GETTING STARTED


MODULES AND PLATFORM


APPENDIX


TUTORIALS & HELPFUL TRICKS


GLOSSARY


STRATEGIC PARTNER LINKS

Sepasoft - MES Modules
Cirrus Link - MQTT Modules

RESOURCES

Inductive University
Ignition Demo Project
Knowledge Base Articles
Forum
IA Support
SDK Documentation
SDK Examples

ALL USER MANUAL VERSIONS

Ignition 8.1
Ignition 7.9
Ignition 7.8

Deprecated Pages

Skip to end of metadata
Go to start of metadata

The following feature is new in Ignition version 8.0.3
Click here to check out the other new features
This function is used in Python Scripting.

Description

Begins a new database transaction using Named Queries. Database transactions are used to execute multiple queries in an atomic fashion. After executing queries, you must either commit the transaction to have your changes take effect, or rollback the transaction which will make all operations since the last commit not take place. The transaction is given a new unique string code, which is then returned. You can then use this code as the tx argument for other system.db.* function calls to execute various types of queries using this transaction.

An open transaction consumes one database connection until it is closed. Because leaving connections open indefinitely would exhaust the connection pool, each transaction is given a timeout. Each time the transaction is used, the timeout timer is reset. For example, if you make a transaction with a timeout of one minute, you must complete that transaction within a minute. If a transaction is detected to have timed out, it will be automatically closed and its transaction id will no longer be valid.

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax - Vision

system.db.beginNamedQueryTransaction( [database], [isolationLevel], [timeout])

  • Parameters

String database - The name of the database connection to create a transaction in. If omitted, uses the project's default connection. 

Integer/Constant isolationLevel - The transaction isolation level to use. Use one of the four constants: system.db.READ_COMMITTED, system.db.READ_UNCOMMITTED, system.db.REPEATABLE_READ, or system.db.SERIALIZABLE. If omitted, uses system.db.READ_COMMITTED

Long timeout timeout - The amount of time, in milliseconds, that this connection is allowed to remain open without being used. Timeout counter is reset any time a query or call is executed against the transaction, or when committed or rolled-back. If omitted, defaults to 30,000. 

  • Returns

String - The new transaction ID. You'll use this ID as the "tx" argument for all other calls to have them execute against this transaction.

  • Scope

Vision Client

Syntax - Perspective and Gateway

system.db.beginNamedQueryTransaction( project, database, [isolationLevel], [timeout])

  • Parameters

String project The name of the project that contains the named query.

String database - The name of the database connection to create a transaction in. 

Integer/Constant isolationLevel - The transaction isolation level to use. Use one of the four constants: system.db.READ_COMMITTED, system.db.READ_UNCOMMITTED, system.db.REPEATABLE_READ, or system.db.SERIALIZABLE. If omitted, uses system.db.READ_COMMITTED

Long timeout timeout - The amount of time, in milliseconds, that this connection is allowed to remain open without being used. Timeout counter is reset any time a query or call is executed against the transaction, or when committed or rolled-back. If omitted, defaults to 30,000. 

  • Returns

String - The new transaction ID. You'll use this ID as the "tx" argument for all other calls to have them execute against this transaction.

  • Scope

Gateway, Perspective Session

Isolation Level Values

The following table lists each value of the isolationLevel parameter and its associated level. Either the integer value or constant may be passed. Note that some JDBC drivers only support some levels, so the driver's documentation should be consulted. Isolation levels are well documented online, but the following link is a great starting point: Data Concurrency and Consistency

Isolation LevelInt ValueConstant
Read Uncommitted1system.db.READ_UNCOMMITTED
Read Committed2system.db.READ_COMMITTED
Repeatable Read4system.db.REPEATABLE_READ
Serializable8system.db.SERIALIZABLE
Code Examples
Code Snippet - Running Named Query Using Named Query Transactions
# This example would start a transaction and check a screen to see if the transaction should be completed or reversed (rolled back).
# The example assumes you have several components on screen and a Named query that takes in an ID and a string value.

# Get details from the screen: Numeric Text Field, Text Field, Checkbox
idEntry = event.source.parent.getComponent('ID Field').intValue
valueEntry = event.source.parent.getComponent('Value Field').text
shouldRollback = event.source.parent.getComponent('CheckBox').selected

# Begin the transaction
datasource = "MYSQL"
isolationLevel = system.db.READ_COMMITTED
timeout = 60000
txNumber = system.db.beginNamedQueryTransaction(datasource, isolationLevel, timeout)

# start by running a Named Query against the transaction
namedQueryPath = "InsertQueries/AddValues"
params = {"id":idEntry, "value":valueEntry}
system.db.runNamedQuery(namedQueryPath, params, txNumber)

# check the window to see if the user selected to cancel the transaction
if shouldRollback:
	# cancel the transaction
	system.db.rollbackTransaction(txNumber)
	print "Transaction rolled back"
else:
	# complete the transaction
	system.db.commitTransaction(txNumber)
	print "Transaction committed"

# Close the transaction now that we are done
system.db.closeTransaction(txNumber)
Keywords

system db beginNamedQueryTransaction, db.beginNamedQueryTransaction  

  • No labels