title: Sybase ASE for update cursor that crashes
body: <p>I just faced a strange behaviour of ASE (version 15.7 ESD 15.2) using a for update cursor.<br>
  Finally i found the root cause, but i thougth about posting it here because it can be usefull, and maybe someone faced it already.</p>
  
  <p>I wrote this simple "for update" cursor :  </p>
  
  <pre><code>DECLARE c_contactrule 
  CURSOR FOR
  SELECT a.id
  FROM FTContactRule a, Client b, ClientContact c
  WHERE /* join conditions */
  AND a.client_id IN ( bla bla bla )
  AND a.message_subtype_id ( bla bla bla )
  AND /* and so on */
  for update of a.preferred_medium_id
  go
  </code></pre>
  
  <p><em>(I summarized a bit the query for this post, to be more readable )</em></p>
  
  <p>Hereafter, of course, i read the cursor value until the end. </p>
  
  <pre><code>open c_contactrule
  fetch c_contactrule into @rule_to_update
  while @@sqlstatus = 0
  begin
       /* do something */
  end
  close c_contactrule
  deallocate c_contactrule
  go
  </code></pre>
  
  <p>I think you guessed that there are somewhere an <code>update preferred_medium_id where current of</code></p>
  
  <p>Currently, this query crashes in a very specific way : the message thrown is "ASE termintaed this process", and indeed, he killed my session!</p>
  
  <p>Investigating, i found that the bad line of code was the first <code>fetch into</code> statement.</p>