Thursday, 11 September 2008

One I learnt the hard way ...

Don't use a 32-bit int to represent a phone number.

When I first started writing code for telecommunications applications, I used int all over the place in my TSQL. I soon clicked that this was not such a good idea (prior to any chaos being caused), and went around swapping out my ints for varchars. Unfortunately I didn't get them all ...

In NZ, the longest mobile phone numbers we have had for quite some time have been 10 digits, starting with 02 - so like 0275555555 would have been a long-ish one. As I have noted due to recent 'issues' arising with one of my real-time systems, we have recently moved (in NZ) to include 11 digit mobile numbers. Which pushes my dodgy code into exception (largest signed 32-bit int being 2147483647).

Great, so that kept me very busy for a couple of hours yesterday, extracting the remaining phone number ints out of my TSQL. Sometimes we learn lessons the hard way I guess ;-)

No comments:

Post a Comment