Tuesday, November 25, 2008

SQL Gotcha: Beware the NULL

Today I ran into a little bit of SQL that, on first glance, didn't make a bunch of sense. Before I show you the SQL I'll give you a basic idea of the two tables being queried:


AREA



areaid | int NOT NULL
areaname | varchar2(100) NOT NULL



FACILITY



facilityid | int NOT NULL
facilityname | varchar2(100) NOT NULL
areaid | int NULL




There is actually a bit more to it but these columns are the important ones. The query that had been written was trying to find all areas that had no facilities within them:


SELECT ar.* FROM area ar WHERE ar.areaid NOT IN (SELECT f.areaid FROM facility f)


That query returned no rows at all. Meanwhile the following query returned one row:


SELECT ar.* FROM area ar WHERE NOT EXISTS (SELECT f.areaid FROM facility f.areaid = ar.areaid)


Honestly, I've given you a big hint to figuring this one out already since I titled this thing Beware the Null and I showed you which columns could be NULL and which couldn't. But here is the problem.

Any SQL comparision that involves a NULL will evaluate to FALSE

That means all of the following examples would return no rows:

SELECT * FROM area WHERE areaid NOT IN (1,2,NULL);

SELECT * FROM area WHERE areaid IN (1,2,NULL);

SELECT 1 as myRow FROM dual WHERE 1=null;

SELECT 1 as myRow FROM dual WHERE 1 != null;

SELECT 1 as myRow FROM dual WHERE null = null;


All of those return no rows because any comparison operator used with a null evaluates to false (IN, NOT IN, =, !=, etc).

So, how do I fix the NOT IN query to work the way I expected it to?


SELECT ar.* FROM area ar WHERE ar.areaid NOT IN (SELECT f.areaid FROM facility f WHERE f.areaid IS NOT NULL)

Friday, November 14, 2008

Glutton For Punishment

So, if you've been paying attention to my activity lately you'll know I spent a bunch of time getting CruiseControl to work and to successfully build a ColdFusion project. You might also know that not every project I do is in CF. Some are in .Net, some in Java, some (maybe soon) are in Ruby. What I really need is a single solution that I can use to do CI in all of those environments; plus I don't want to have to learn how to configure a different CI tool for each project.

Enter CruiseControl.rb. CruiseControl.rb is a ruby implementation of the CruiseControl service that will build pretty much any project whose build file can be called from the command line. I suppose it is possible that the other CruiseControl implementations can do that as well but I haven't seen any documentation on it. Thus I'm strongly considering redoing all my recent work but by using CruiseControl.rb.

This will leave me needing to learn 2 major things. First off how to get CruiseControl.rb setup in the first place and secondly how to craft a rake file. Rake is a ruby build file (sort of like make in the C world). Each project will get its own rake file which will, subsequently, make command line calls to the projects specific build tool (so Ant or Maven for my CF and Java projects, Nant or MSBuild for .Net) etc etc. As I did with the standard CruiseControl I'll try to document my efforts here so the process is painless for those who follow.

Stay Tuned!

Thursday, November 13, 2008

Google Video Chat First Impression

I tried out Google Video Chat today with a co-worker in the same office as me. It was rumored by some that the client would establish a direct connection (peer-to-peer) between the two chatting parties but I don't think one is. Instead I get the feeling all of the data is going to Google and then back to the other person in the chat which causes some noticeable lag times in rendering motion or changes in facial expression. While lag is fairly typical for most video chat solutions I've used in the past the amount I noticed in the Google client seemed excessive.

Audio transmission on the other hand seemed fine. My friend didn't have a webcam but did have a mic so he was able to send just voice to me and it appeared on my speakers with only a minimal delay; had we not been in the same room it wouldn't have been noticable. However, audio chat, without the video element, is fairly useless in general since I can just pick up the phone.

With that said I think the Google offering will only get better with time. Plus, if you are overseas and want to have some voice communication with a friend then using the audio-chat feature would be a good economical (free) choice.

Setup was a snap. I just had to install a browser plugin (works with pretty much every modern browser) and then restart my browsers. I didn't have to make any configuration changes on my machine or identify my USB webcam, the chat plugin found it and activated it without issue.

Performance problems alone might be enough to deter many from using the client but I think it is worth keeping an eye on to see where it goes from here. I wouldn't be surprised if an API comes out that lets other websites incorporate the Google Video Chat plugin in the future which would be a nice feature for many small business that couldn't afford to provide live video support via other means.

Monday, November 03, 2008

Ubuntu Auto Shutdown Due To High CPU Temp

I use a Dell XPS m170 laptop at work. I have it dual booting into either XP or Ubuntu 8.1 (Ibex); however, while in Ubuntu at times the CPU temp gets really hot and the system automatically shuts down. This would be fine if it were a rare event but it happens pretty frequently and it is entirely annoying. The syslog showed the following error:


ACPI: Critical trip point
Critical temperature reached (100 C), shutting down.


I know it is a safety feature, but really, I can't afford to keep having the system shutdown because a page on Firefox is intensive to load. My fans are working but for whatever reason my CPU temp exceeds the critical threshold of 99C. On some systems you can see what your threshold is within the BIOS and even edit it but not on this one. So what's a frustrated developer supposed to do? Well, it turns out you can tell you system to ignore the high temp threshold and to just keep on chugging along. NOTE: This isn't the best advice I ever gave, if you do this then fry your CPU don't come bitching to me.

First you need to add a setting to you're system by following these instructions:

{in a terminal enter:} gksudo gedit /etc/modprobe.d/options
{add this line to the end of the file} options thermal nocrt=1
{save and close the file}


Once you have this option set you need to reconfigure the kernel to pick up these changes, in a terminal window again enter the following:


sudo dpkg-reconfigure linux-image-$(uname -r)


This will update your kernel and then tell you to restart when it is done. Once you restart you can go back to a terminal window and type:

cat /proc/acpi/thermal_zone/*/*

{gives you a result similar to this}

<setting not supported>
<polling disabled>
state: ok
temperature: 52 C
critical (S5): 99 C <disabled>


Now your system won't restart when the critical heat point is passed. Again, don't blame me if you hurt your machine by doing this.