beautypg.com

A transaction – HEIDENHAIN TNC 320 (77185x-01) User Manual

Page 302

background image

Programming: Q Parameters

9.9

Accessing tables with SQL commands

9

302

TNC 320 | User's Manual

HEIDENHAIN Conversational Programming | 3/2014

A transaction

In principle, a transaction consists of the following actions:

Address the table (file), select rows and transfer them to the

result set.
Read rows from the result set, change rows or insert new rows.
Conclude transaction: If changes/insertions were made, the

rows from the result set are placed in the table (file).

Other actions are also necessary so that table entries can be edited

in an NC program and to ensure that other changes are not made

to copies of the same table rows at the same time. This results in

the following

transaction sequence

:

1 A Q parameter is specified for each column to be edited. The Q

parameter is assigned to a column—it is "bound" (

SQL BIND...

2 Address the table (file), select rows and transfer them to the

result set. In addition, you define which columns are transferred
to the result set (

SQL SELECT...). You can lock the selected

rows. Other processes can then read these rows, but cannot

change the table entries. You should always lock the selected
rows when you are going to make changes (

SQL SELECT ...

FOR UPDATE).

3 Read rows from the result set, modify and/or add new rows:

– Adopt one row of the result set into the Q parameters of
your NC program (

SQL FETCH...) – Prepare changes in the

Q parameters and transfer to a row in the result set (

SQL

UPDATE...) – Prepare new table row in the Q parameters and
transfer as a new row to the result set (

SQL INSERT...)

4 Conclude transaction: – If changes/insertions were made, the

data from the result set is placed in the table (file). The data is

now saved in the file. Any locks are canceled, and the result set
is released (

SQL COMMIT...). – If table entries were

not

changed

or inserted (only read access), any locks are canceled and the
result set is released (

SQL ROLLBACK... WITHOUT INDEX).

Multiple transactions can be edited at the same time.

You must conclude a transaction, even if it consists

solely of read accesses. Only this guarantees

that changes/insertions are not lost, that locks are

canceled, and that result sets are released.