tags:

views:

977

answers:

4

What's the best way to do the semantic equivalent of the traditional sleep() system call from within an Informix SPL routine? In other words, simply "pause" for N seconds (or milliseconds or whatever, but seconds are fine). I'm looking for a solution that does not involve linking some new (perhaps written by me) C code or other library into the Informix server. This has to be something I can do purely from SPL. A solution for IDS 10 or 11 would be fine.

@RET - The "obvious" answer wasn't obvious to me! I didn't know about the SYSTEM command. Thank you! (And yes, I'm the guy you think I am.)

A: 

I assume that you want this "pause" for debugging purposes, otherwise think about it, you'll always have some better tasks to do for your server than sleep ...

A suggestion: Maybe you could get CURRENT, add it a few seconds ( let mytimestamp ) then in a while loop select CURRENT while CURRENT <= mytimestamp . I've no informix setup around my desk to try it, so you'll have to figure the correct syntax. Again, do not put such a hack on a production server. You've been warned :D

PW
CURRENT does not change while the top-level SQL statement runs. There is a DBINFO() that does - and there's info in sysmaster that does.
Jonathan Leffler
A: 
John Siracusa
A: 

Then you'll have to warp CURRENT in another function that you'll call from the first (but this is a hack on the previous hack ...).

PW
+1  A: 

There must be some good reason you're not wanting the obvious answer: SYSTEM "sleep 5". If all you're wanting is for the SPL to pause while you check various values etc, here are a couple of thoughts (all of which are utter hacks, of course):

  1. Make the TRACE FILE a named pipe (assuming Unix back-end), so it blocks until you choose to read from it, or
  2. Create another table that your SPL polls for a particular entry from a WHILE loop, and insert said row from elsewhere (horribly inefficient)
  3. Make SET LOCK MODE your friend: execute "SET LOCK MODE TO WAIT n" and deliberately requery a table you're already holding a cursor open on. You'll need to wrap this in an EXCEPTION handler, of course.

Hope that is some help (and if you're the same JS of Ars and Rose::DB fame, it's the least I could do ;-)

RET