Coding Horrors: MySQL, Dates and Times
An excerpt from MySQL Reference Manual:
Illegal DATETIME, DATE, or TIMESTAMP values are converted to the “zero” value of the appropriate type (’0000-00-00 00:00:00′ or ‘0000-00-00′).
What the fuck. Really, come on. The purpose of a database is to store valid and integral data. Again. Valid. And. Integral. Data. It is valid, integral and meaningful that counts. Not just any rubbish. If I want rubbish, I can just read back random bytes from the harddisk. If someone tries to write crap into a database, which the database cannot handle, the database must refuse the operation, and give error.
Really, I wonder what the hell designers of MySQL were thinking when they implemented this specific feature. Pardon me, the word “feature” is not appropriate. The correct word would be “disaster”. It is a disaster indeed, because it silently causes data loss. One might argue that it is developers’ responsibility to validate their data, and make sure they provide the database with valid input. While this is definitely true, it is no excuse for the database to accept graciously any garbage, and on top of that convert it to something which has nothing to do with what it is supposed to be. That is a major fail in design, and major fail to achieve a primary goal.
The behavior above is true for MySQL versions from 4.1 to 6.0.
This little story only proves that MySQL is only good as a backend for small and simple websites. If you mean serious business, please reconsider. There are a bunch of free databases out there, all of them much, much better and more mature. Some of them even open source.
And yes, I know there is a general setting in MySQL 5.02 and greater to make it give errors. And yes, I don’t think it makes the fail lesser.