RecordLockingConflict class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (edits, tags and links)
Line 1: Line 1:
<!-- RecordLockingConflict class -->
<!-- RecordLockingConflict class -->
The <code>RecordLockingConflict</code> exception class catches
The <var>RecordLockingConflict</var> exception class catches record locking conflict errors thrown by file object operations; that is from methods in the <var>[[File_classes|file classes]]</var> (<var>[[Record_class|Record]]</var>, <var>[[Recordset_class|Recordset]]</var>, <var>[[SortedRecordset_class|SortedRecordset]]</var>, and <var>[[RecordsetCursor_class|RecordsetCursor]]</var>).
record locking conflict errors thrown by file object operations, that is. from
methods in the file classes (Record, Recordset, SortedRecordset, RecordsetCursor).
   
   
An exception is thrown only if there is a Catcher for the exception.
An exception is thrown only if there is a Catcher for the exception.
   
   
There is no distinction between
There is no distinction between a Find conflict and a record locking conflict. For example, you can use the following:
a Find conflict and a record locking conflict.
For example, you can use the following:
   
   
<p class="code"> try
<p class="code"> [[try]]
     fd to %foo
     fd to %foo
       ...
       ...
     end find
     end find
  catch recordLockingConflict
  [[catch]] recordLockingConflict
     ...
     ...
  end try
  end try
Line 20: Line 16:
   
   
And you can also use:
And you can also use:
<p class="code"> try
<p class="code"> [[try]]
     %rec = new(%recnum, exclusive)
     %rec = [[New_(Record_constructor)|new]](%recnum, exclusive)
     for record %rec
     for record %rec
         ...
         ...
     end for
     end for
  catch recordLockingConflict
  [[catch]] recordLockingConflict
     ...
     ...
  end try
  end try
</p>
</p>
   
   
You can even catch record locking conflicts caused by LoopLockStrength promotions
You can even [[catch]] record locking conflicts caused by <var>[[LoopLockStrength_(Record_property)|LoopLockStrength]]</var> promotions during a loop:
during a loop:
<p class="code"> %rec = new(%recnum, none, loopLockStrength=share)
<p class="code"> %rec = new(%recnum, none, loopLockStrength=share)
   ...
   ...
  try for record %rec
  [[try]] for record %rec
     ...
     ...
     end for
     end for
  catch recordLockingConflict
  [[catch]] recordLockingConflict
     ...
     ...
  end try
  end try
Line 45: Line 40:
<p class="code"> %curser = new(%recset, loopLockStrength=none)
<p class="code"> %curser = new(%recset, loopLockStrength=none)
   ...
   ...
  try
  [[try]]
     for record at cursor %curser
     for record at cursor %curser
       ...
       ...
     end for
     end for
  catch recordLockingConflict
  [[catch]] recordLockingConflict
     ..
     ..
  end try
  end try
Line 59: Line 54:
  end find
  end find
   ...
   ...
  try for each record in %recset
  [[try]] for each record in %recset
       ...
       ...
     end for
     end for
  catch recordLockingConflict
  [[catch]] recordLockingConflict
     ...
     ...
  end try
  end try
</p>
</p>
   
   
In the latter example, note that any iteration of the For loop can throw
In the latter example, note that any iteration of the For loop can <var>throw</var> an exception, and there is no way of picking up where you left off (at the next record, say) if you get a <var>RecordLockingConflict</var> exception in such a case. So, unless you always want to lose the whole loop on a record locking conflict, such a case is almost always better structured with a cursor on the recordset and with <var>Try</var> around the <var>For Record At Cursor</var> loop:
an exception, and there is no way of picking up where you left off
(at the next record, say) if you get a RecordLockingConflict exception in
such a case.
So, unless you always want to lose the whole loop
on a record locking conflict, such a case is almost always better structured
with a cursor on the recordset and with Try around the For Record At Cursor loop:
<p class="code"> fdwol to %recset = new(loopLockStrength=exclusive)
<p class="code"> fdwol to %recset = new(loopLockStrength=exclusive)
     ...
     ...
Line 80: Line 69:
  %curser = new(%recset, loopLockStrength=exclusive)
  %curser = new(%recset, loopLockStrength=exclusive)
  repeat while %curser:state eq hasRecord
  repeat while %curser:state eq hasRecord
     try for record at cursor %curser
     [[try]] for record at cursor %curser
       ...
       ...
     end for
     end for
     catch recordLockingConflict
     [[catch]] recordLockingConflict
       ...
       ...
     end try
     end try
     %curser:next
     %curser:[[next]]
  end repeat
  end repeat
</p>
</p>
   
   
Note that the For statement can be on the same line as the Try,
<b><i>Note:</i></b> that the For statement can be on the same line as the <var>Try</var>, or it can be inside the <var>Try</var> block.
or it can be inside the Try block.
   
   
The methods in this class are listed at "[[List of RecordLockingConflict methods]]".
The methods in this class are listed at "[[List of RecordLockingConflict methods]]".
[[Category:System exception classes]]
[[Category:System exception classes]]

Revision as of 07:33, 22 April 2011

The RecordLockingConflict exception class catches record locking conflict errors thrown by file object operations; that is from methods in the file classes (Record, Recordset, SortedRecordset, and RecordsetCursor).

An exception is thrown only if there is a Catcher for the exception.

There is no distinction between a Find conflict and a record locking conflict. For example, you can use the following:

try fd to %foo ... end find catch recordLockingConflict ... end try

And you can also use:

try %rec = new(%recnum, exclusive) for record %rec ... end for catch recordLockingConflict ... end try

You can even catch record locking conflicts caused by LoopLockStrength promotions during a loop:

%rec = new(%recnum, none, loopLockStrength=share) ... try for record %rec ... end for catch recordLockingConflict ... end try

Or as in the following:

%curser = new(%recset, loopLockStrength=none) ... try for record at cursor %curser ... end for catch recordLockingConflict .. end try

Or as in this example:

fdwol to %recset = new(loopLockStrength=exclusive) ... end find ... try for each record in %recset ... end for catch recordLockingConflict ... end try

In the latter example, note that any iteration of the For loop can throw an exception, and there is no way of picking up where you left off (at the next record, say) if you get a RecordLockingConflict exception in such a case. So, unless you always want to lose the whole loop on a record locking conflict, such a case is almost always better structured with a cursor on the recordset and with Try around the For Record At Cursor loop:

fdwol to %recset = new(loopLockStrength=exclusive) ... end find ... %curser = new(%recset, loopLockStrength=exclusive) repeat while %curser:state eq hasRecord try for record at cursor %curser ... end for catch recordLockingConflict ... end try %curser:next end repeat

Note: that the For statement can be on the same line as the Try, or it can be inside the Try block.

The methods in this class are listed at "List of RecordLockingConflict methods".