Solved

"waitfor delay" not working as expected....

Posted on 2007-03-30
6
2,166 Views
Last Modified: 2012-05-05
On Sybase 11.9.2, running on AIX.
Here's what I'm experiencing, and I'm not sure why.  Placed the following in a stp:

print 'WE START.'
waitfor delay '00:02:00'
print 'WE END.'
return 0

When I execute this, I'm was expecting to see "WE START", then have a two minute pause, and then see "WE END"....but instead, the two minute pause appears to occur FIRST, and THEN I see "WE START" "WE END" print one after another with no delay in between....  Can someone expain why that is?   Is the print "WE START" actually running prior to the pause, but not actually printing until after?  If so, how can I make it work as I'm expecting?
0
Comment
Question by:derdle
  • 3
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18828247
the print does indeed happen correctly with 2 minutes intervals, you can check that by adding the current time to the prints.
however, the output is buffered, and only shown when the full batch is completed.

I know the same from SQL Server, you might try to use SELECT instead of PRINT.
0
 
LVL 19

Accepted Solution

by:
grant300 earned 500 total points
ID: 18831799
Use the command

SET FLUSHMESSAGE ON

This tells ASE to push messages out to the client as they occur instead of waiting for the buffer to fill.

Regards,
Bill
0
 

Author Comment

by:derdle
ID: 18868294
Bill-  Just the solution I was looking for!  That works, thanks!  Although it's interesting that you refer to this, and the solution relates to "waiting for the buffer to fill".  I say this because in reading the defined action of "waitfor delay" which indicates that it "suspends the session....and communications", I thought that maybe becuase I had the "print WE START" directly before the "waitfor delay", the waitfor was suspending the session (and thus the output) before the output from the print on the previous line had a chance to display.  ....which to me seemed almost impossible, given the fractional amount of time we talking about between the execution of the two line....BUT....when I tried the following, it did resolve the problem, and appears to support my thoughts, since all I am doing is adding a small amount of time between the print and the waitfor.  I did this, and this also worked (but is abviously much more painful than your correct solution).   ...but my question is, even though I am not printing anything while performing the pause loop below, is that adding something to the buffer than would make this solution valid as well....if indeed it is a matter of the buffer being full or not - (which again, I totally believe, as the  your solution works...and make more sense).

 print 'WE START.'
   select @next = 1
   while (@next < 15)
   begin
      select @next = @next + 1
   end
   waitfor delay '00:02:00'
print 'WE END.'
return 0

This works as I was describing as well, althoug obviously the wait is a tick longer than 2:00....but the print statement happens before the wait...where if I take that loop out, it does not.  

I'll be marking your answer as the solution....but thought I continue with this thought, since it puzzles me a bit.  =))  



0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 19

Expert Comment

by:grant300
ID: 18868534
Actually, what you are doing is stuffing a bunch of entries in the buffer; you just don't realize it.

SELECT statements, even if they don't return any results, do return a "rows affected" message.  You are using your loop to put 15 rows affected messages into the buffer which is, evidently, enough to get it to flush.

I am willing to bet that if you put a "SET NOCOUNT ON" statement at the beginning of your code, your trick no longer works.

Let us know what happens.

Regards,
Bill
0
 

Author Comment

by:derdle
ID: 18869503
Well, oddly enough, the addition of the SET NOCOUNT ON statement seems to have no affect on the process.  The trick does still work even with it included.  Any other thoughts on why that might be?  Now I'm sucked in and want to understand exactly what is happening here, and how this works...  =))
0
 
LVL 19

Expert Comment

by:grant300
ID: 18872648
The only way to know for sure is to delve into the internals of Sybase.  Since we don't have the source code, that is a bit tough.

I still suspect that the buffer is getting stuffed with the Rows Affected messages and that the SET NOCOUNT ON probably sets a flag in the Open Server that prevents them from being sent to the client, probably where the buffer is translated into TDS packets.  That way, there would be only one place in the entire code base where that function would have to operate.

Since your conjecture is that it is a delay prior to the waitfor that is causing/allowing the buffer to be flushed, substitute something that does not produce a bunch of messages.  With SET NOCOUNT ON, you could SELECT * INTO #TMP FROM master.dbo.sysobjects.  That is likely to take longer than a loop with 15 set statements.

Regards,
Bill
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to query constraints in Sybase 3 1,453
Sybase ASE BCP In With Table with No Identity Column 1 1,173
dbisql 5 550
Sysbase Central connection fails 3 39
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now