| « Can of RAID | It Doubles as an Oven! » |
Have you ever been faced with this scenario? You need to unscrew a Phillips head screw but you only have a similarly sized flat head screwdriver available.
I have and boy was it ever frustrating.
In the end, the screw head was a little chewed up, my wrist hurt from trying to contort my hand, my wife chided me for cursing in front of the kids (after all, I was only trying to replace the batteries in that friggin talking doll in the first place!!) - but hey - it worked!
Part of me clings onto the hope that the original author of the anonymously submitted bit of code below was in a similar situation. He or she didn't know that he had tools available to add a delay to some process. Perhaps the original dev was a loner, a rebel - writing things his way. ...but I have a strong suspicion that it's just a horrible, cruel prank being perpetrated by a rude jerk of a developer. Yep, I think that's it.
Function DelayProcess(nSeconds) dim sleep, connn Set connn = CreateObject("ADODB.Connection") connn.Open DSNPDF ' indicate a number of seconds, up to 59 sleep = nSeconds ' make sure timeout doesn't expire! connn.commandTimeout = sleep + 5 ' if you neede more than 59 seconds, you will need to adjust the SQL: sqlstr = "WAITFOR DELAY '00:00:" & right(clng(sleep),2) & "'" 'Response.Write(now & "<p>") connn.Execute sqlstr,,129 'Response.Write(now & "<p>") connn.close Set connn = Nothing End Function
|
Unscrewing a Philips screw with a flathead screwdriver is no problem.
Trying to unscrew a flathead screw with a Philips screwdriver - now I'd like to so somebody do THAT. |
|
The code is completely legit. We use similar thing to get current time: "select now()" - the thing is, users can change time on their machine. Even while application is running. By using "select now()" we have always correct, server time. Same way for pauses. Do not underestimate ingeniousness of your users.
|
|
Could be classic ASP where this is a viable solution.
Alternatives: 1. Busy-wait (increase server load) 2. Install & pay for a 3rd party control |
|
pfft. Amateurs.
|
Re: Square Peg Meets Round Hole
2012-08-23 12:33
•
by
haero
(unregistered)
|
MsBuild commandline version:
|
|
There's one thing in this story that just completely boggles my mind. What idiot decided that there should be a "WAITFOR" statement in SQL?
Given some of the problems with doing expressions in SQL, and then this, all I can say is: I really wish they would get people for SQL product designers and for the standards committee who are not BASIC programmers! |
Re: Square Peg Meets Round Hole
2012-08-23 21:30
•
by
Megamanic
(unregistered)
|
|
No it's not - You cannot hammer the database server in a timing loop like that without "consequences" - imaging 300 users all doing that. No "real" queries would stand a chance. This does not scale. Use Sleep(2000) or whatever your language provides.
|
| « Can of RAID | It Doubles as an Oven! » |