Coupon Code: santa14
Hurry up, offer expires soon!
Blog

The Wonderful Way-Back Machine in MySQL

You can do things backwards in MySQL. You can receive a result before sending the query.

1) Pop quiz: What will you do if your client pops up a message like this:

+————+
| sleep(-25) |
+————+
| 0 |
+————+

2) Hint: read MySQL documentation

3) Answer: wait exactly 25 seconds (within the accuracy of a microsecond) and execute “select sleep(-25);”. (now .. if an alias is used for the result it gets a little difficult to know for how long you should wait :-) )

Obviously the argument gets truncated to “0″ when it is outside valid range. But MySQL docs does not tell what the valid range for the argument to SLEEP() is and no error or warning is returned if truncation happens. It is reported here.

This is of course not extemely important. ┬áBut not quite irrelevant or stupid either. Automated test programs may open multiple connections and set some in sleep state for some time. The argument to SLEEP() may be computated or fetched from a table. It would be nice to have at least a warning if a SLEEP() argument was sent, that makes no sense at all – as it is then likely a user/client/application error.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>