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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2: Initial Programming Considerations<br />

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

differ in 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<br />

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

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

uncommitted or read committed, the record might be updated by another client be<strong>for</strong>e<br />

the second FIND statement executes. This could cause the record that the second FIND<br />

statement fetches to be different from the record fetched by the first FIND statement.<br />

This procedure might cause updated in<strong>for</strong>mation to be lost because the procedure<br />

applies updates based on the first find of the record, and these updates will overwrite<br />

the values from the second find of the record.<br />

Using the <strong>Data</strong><strong>Server</strong> to access a MS <strong>SQL</strong> <strong>Server</strong> database ensures that locks are<br />

upgraded in the data source in the same way as in an <strong>OpenEdge</strong> database. For<br />

example, the following procedure causes the same behavior whether you access an<br />

<strong>OpenEdge</strong> database or a MS <strong>SQL</strong> <strong>Server</strong> data source:<br />

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

DISPLAY customer.<br />

PROMPT-FOR customer.<br />

DO TRANSACTION:<br />

ASSIGN customer.<br />

END.<br />

The record is share-locked when it is fetched. The <strong>Data</strong><strong>Server</strong> upgrades the share lock<br />

to an exclusive lock inside the transaction by locking the record, reading it, and<br />

checking whether the record has changed since it was first fetched. If it has changed,<br />

the lock upgrade fails and you receive an error message.<br />

You might have to wait to access a record under the following circumstances:<br />

• You try to update a record when another user is reading it (it is share-locked). This<br />

also depends on the isolation level.<br />

• You try to read or update a record when another user is updating it (it is<br />

exclusive-locked).<br />

98 <strong>OpenEdge</strong> <strong>Data</strong> <strong>Management</strong>: <strong>Data</strong><strong>Server</strong> <strong>for</strong> <strong>Microsoft</strong> <strong>SQL</strong> <strong>Server</strong>

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

Saved successfully!

Ooh no, something went wrong!