Saturday, May 1, 2010

Char is not equal to String

Duh! Everybody knows that.

There was bug and it was caused by the above char not equal string(varchar2) logic. Why it is still happening since everybody knows that?

The variable constants was a string 'Employee' and the database field value that suppose to match this constant also show 'Employee'. However, the process logic if-condition has failed. Everybody was scratching head until spaces are found  ('Employee    ') in the database field value.

Ironic isn't it? Looks the same, feels the same but the program has failed because of spaces.

This lesson has brought us to identifiy the when to use the char and string (varchar2). Obviously, the table field shound't be stored as char if it's going to be checked every where in the progarm. As we know, some developer are not going to trim the value before writing the if-condition check.That will cause a lot of maintenance work to replace everyone of the them, where the field is used.

In short, identify the field behaviour and use to the correct data type. Use the wrong type and bugs will be crawling all over the place.