Appendix: WithDB Statements

WithDB is a type of compound statement used to wrap one or more expressions related to the modification of a data source, causing those expressions to be executed as part of a single explicit transaction. In any given WithDB statement during run-time, the first expression to connect to a data source - such as a WriteData expression - will initiate a transaction between the model and the target data source. This transaction will remain active until the last expression inside the WithDB statement has been executed.

The syntax of a WithDB statement is as follows:

WithDB
{
	SomeExpressionCode;
};

Despite occurring within a single transaction, each expression within the statement is independent. As a result, if one expression fails for some reason - for example, if it attempts to write invalid data to the target database - the next expression will be executed regardless. Although the failed expression did not write anything away, the rest of the transaction is unaffected.

The following diagram shows an example WithDB transaction that attempts to write three new values into a database. The second value is invalid, meaning the expression responsible for writing that value fails. Despite this, the first and third values are written away as normal, and by the end of the transaction the database has gained two new units of data:

A WithDB transaction completing successfully despite an error occurring in its second expression.