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–46<br />

If you use NO–ERROR to do your own error handling, you must account <strong>for</strong> the fact that a MS <strong>SQL</strong><br />

<strong>Server</strong> data source creates or updates a record later than an <strong>OpenEdge</strong> database does. For<br />

example, the following code does not trap data source errors, because the requests to per<strong>for</strong>m<br />

the operations have not yet been sent to the data source:<br />

CREATE customer NO-ERROR.<br />

ASSIGN customer.custnum = 45 NO-ERROR.<br />

ASSIGN customer.name = "Smith" NO-ERROR.<br />

The VALIDATE statement causes the <strong>Data</strong><strong>Server</strong> to send requests to your MS <strong>SQL</strong> <strong>Server</strong> data<br />

source, so incorporate it into your error-handling technique, as in the following example:<br />

DEFINE VAR jx AS INTEGER.<br />

DO TRANSACTION:<br />

CREATE customer NO-ERROR.<br />

ASSIGN customer.custnum = 45 NO-ERROR.<br />

VALIDATE customer.<br />

IF ERROR-STATUS:ERROR THEN DO:<br />

MESSAGE "error: number of messages = " ERROR-STATUS:NUM-MESSAGES.<br />

DO jx = 1 TO ERROR-STATUS:NUM-MESSAGES:<br />

MESSAGE "error" ERROR-STATUS:GET-NUMBER(j)<br />

ERROR-STATUS:GET-MESSAGE (jx).<br />

END.<br />

UNDO, LEAVE.<br />

END.<br />

ASSIGN customer.name = "Smith" NO-ERROR.<br />

VALIDATE customer.<br />

IF ERROR-STATUS:ERROR THEN . . .<br />

END.<br />

This code returns data-source errors after the VALIDATE statement.<br />

The<br />

<strong>Data</strong><strong>Server</strong><br />

prompts <strong>for</strong><br />

the customer<br />

number.<br />

Another difference in behavior occurs when two users simultaneously attempt to create records<br />

with duplicate <strong>OpenEdge</strong> keys. An <strong>OpenEdge</strong> database raises an error immediately, but the data<br />

source raises an error after the first transaction commits and only if the second transaction does<br />

not roll back. To avoid this difference, either change the scope of the transaction so that it<br />

completes more quickly or make the key nonunique and en<strong>for</strong>ce uniqueness at the application<br />

level. Another technique is to use a RELEASE or VALIDATE statement when you check <strong>for</strong> the<br />

key’s uniqueness.

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

Saved successfully!

Ooh no, something went wrong!