13.01.2013 Views

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Initial Programming Considerations<br />

2–40<br />

The records of a NO-LOCK query are pre-fetched, which means that changes to the result set after<br />

the query has been executed are unknown. Records modified in the database after the query is<br />

established will not be reflected in the result set. SHARE-LOCK and EXCLUSIVE-LOCK queries do<br />

not pre-fetch records, but do preselect record keys. The query behavior is that of a<br />

“keyset-driven” cursor. Since the record keys are stored at the time an ABL query is first<br />

executed, new records added to the database since the key list was established are not included<br />

in the query result set. However, records that have been deleted or modified in the database will<br />

be reflected in the query results as records are accessed by the application.<br />

Locking examples<br />

The following example illustrates how the end of a transaction affects <strong>OpenEdge</strong> and MS <strong>SQL</strong><br />

<strong>Server</strong> data source locks differently:<br />

DO TRANSACTION:<br />

FIND customer WHERE customer.custnum EQ 10.<br />

UPDATE customer.<br />

END.<br />

Note the following points:<br />

• When you access an <strong>OpenEdge</strong> database with this procedure, the customer record is<br />

share-locked when the first transaction ends.<br />

• When you access a MS <strong>SQL</strong> <strong>Server</strong> data source with the <strong>Data</strong><strong>Server</strong>, the customer record<br />

is released when the first transaction ends.<br />

This example illustrates how <strong>OpenEdge</strong> and MS <strong>SQL</strong> <strong>Server</strong> data source share locks differ in<br />

scope and duration:<br />

FIND customer WHERE customer.custnum EQ 10 SHARE-LOCK NO-WAIT NO-ERROR.<br />

IF AVAILABLE customer THEN DO:<br />

DISPLAY customer.<br />

PROMPT-FOR customer.<br />

tx:<br />

DO TRANSACTION ON ERROR UNDO tx, RETRY tx:<br />

FIND customer WHERE customer.custnum EQ 10<br />

EXCLUSIVE-LOCK NO-WAIT NO-ERROR.<br />

IF LOCKED customer THEN DO:<br />

MESSAGE "customer locked - retrying".<br />

UNDO tx, RETRY tx.<br />

END.<br />

ELSE<br />

ASSIGN customer.<br />

END.<br />

END.<br />

In this example, the first record is only share-locked within the MS <strong>SQL</strong> <strong>Server</strong> data source if<br />

the isolation level setting requires it. (Recall that a SHARE–LOCK specified in an ABL statement<br />

is ignored by the <strong>Data</strong><strong>Server</strong>.) As a result, if the isolation level is read uncommitted or read<br />

committed, the record might be updated by another client be<strong>for</strong>e the second FIND statement<br />

executes. This could cause the record that the second FIND statement fetches to be different from<br />

the record fetched by the first FIND statement. This procedure might cause updated in<strong>for</strong>mation

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!