tag:blogger.com,1999:blog-38464324053432958442024-03-08T02:02:48.879-05:00Yet another [a-z]* blog2.0 and other fun stuffthebaldwinhttp://www.blogger.com/profile/10343240144653351448noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-3846432405343295844.post-66507800823315282252008-07-29T23:15:00.003-04:002008-07-29T23:52:02.355-04:00why are there empty strings in my not null column?So you're looking at your database and wondering wtf are those default values doing in there?<br /><blockquote><span style="font-size:78%;">mysql> create table foo(title char(10) not null);<br />Query OK, 0 rows affected (0.06 sec)<br /><br />mysql> insert into foo(title) values (NULL);<br />ERROR 1048 (23000): Column 'title' cannot be null</span></blockquote><br />that was expected...<br /><br /><blockquote><span style="font-size:78%;">mysql> insert into foo(title) values (NULL),("OH SNAP");<br />Query OK, 2 rows affected, 1 warning (0.00 sec)<br />Records: 2 Duplicates: 0 Warnings: 1<br /><br />mysql> show warnings;<br />+---------+------+-------------------------------+<br />| Level | Code | Message |<br />+---------+------+-------------------------------+<br />| Warning | 1048 | Column 'title' cannot be null |<br />+---------+------+-------------------------------+<br />1 row in set (0.00 sec)</span></blockquote>Hmm, not quite what I was expecting...error became a warning..<br /><br /><blockquote><span style="font-size:78%;">mysql> select * from foo;<br />+-----------+<br />| title <br />+-----------+<br />| asdf<br />|<br />| OH SNAP<br />+-----------+<br />3 rows in set (0.00 sec)</span></blockquote>we get the default empty string inserted for us...how nice<br /><br /><span style="font-size:78%;"></span><blockquote><span style="font-size:78%;">mysql> set sql_mode='TRADITIONAL';<br />Query OK, 0 rows affected (0.00 sec)<br /></span><span style="font-size:78%;">mysql> SELECT @@session.sql_mode;<br />+-------------------------------------------------------------------------------------------------------------------------------+<br />| @@session.sql_mode |<br />+-------------------------------------------------------------------------------------------------------------------------------+<br />| STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER |<br />+-------------------------------------------------------------------------------------------------------------------------------+<br />1 row in set (0.00 sec)<br /> <br />mysql> insert into foo(title) values (NULL),("asdf");<br />ERROR 1048 (23000): Column 'title' cannot be null</span></blockquote><span style="font-size:78%;"></span>woot, stricter now..<br /><br />Athebaldwinhttp://www.blogger.com/profile/10343240144653351448noreply@blogger.com0tag:blogger.com,1999:blog-3846432405343295844.post-61453831336201123762008-02-18T03:28:00.004-05:002008-02-18T13:01:00.916-05:00A Couple Of Quick Mongrel Tips<span style="font-weight: bold;"><span style="font-weight: bold;"><span style="font-weight: bold;"></span></span>timeout mongrel connections<br /><br /></span>There are two time based arguments for your pleasure:<br /><br /><blockquote>-o, --timeout X - Time to wait before killing a stalled thread<br />-t, --throttle X - Time to pause between accepting clients<br /></blockquote><br />Both conveniently begin with the letter 't'. Mistaking -t for the timeout can lead to some interesting behavior like for example causing your site to not accept new clients for a bit.<br /><br />If you're looking to timeout your connections after X amount of time you can use -o X, where X is the time to wait in seconds:<br /><br /><blockquote>mongrel_rails start -d -e production <span style="font-weight: bold;">-o 30</span> -p 5555 -P mongrel.pid</blockquote><br /><br /><span style="font-weight: bold;">stopping a mongrel<br /><br /></span>Mongrels dont always like to stop when you tell them to stop, they will just sit there happily forever not doing anything productive:<br /><br /><blockquote>% mongrel_rails stop -P mongrel.pid<br />Sending TERM to Mongrel at PID 25073...Done.<br />% ps aux | grep '25073'<br />25073 Feb17 5:51 mongrel_rails [5555/0/8288]: idle </blockquote>But I said stop! :(<br /><br />You can use --force to send a kill -9, but this isn't too graceful. You want to allow any queued clients to exit before doing this.<br /><br />To deal with this you can also provide a wait argument which attempt to do a graceful stop, but if after X amount of time it can't, it will bring out the BFG and kill -9 the process:<br /><br /><blockquote>mongrel_rails stop --force -w 30 -P mongrel.pid</blockquote><br /><br /><span style="font-weight: bold;">monitoring a mongrel<br /><br /></span>If you're planning to restart mongrel processes using <a href="http://god.rubyforge.org/">God </a>by checking the http status code, make sure you check for more than N consecutive failures as you can(and will) get random timeouts/refused connections.<br /><br /><blockquote>restart.condition(:http_response_code) do |c|<br />c.timeout = 15.seconds<br />c.code_is_not = 200<br /><span style="font-weight: bold;">c.times = [3, 3]</span><br />end</blockquote>This for example, will check for 3 consecutive http response failures before restarting.thebaldwinhttp://www.blogger.com/profile/10343240144653351448noreply@blogger.com0