False reporting of NULL
s as zeroes
To make matters worse, Firebird lies to you when you retrieve data from the table.With isql
and many other clients, “SELECT * FROM ADVENTURES
” will return this dataset:
Name | Bought | Price | ID |
---|---|---|---|
Maniac Mansion |
12-Jun-1995 |
$ 49,-- |
0 |
Zak McKracken |
9-Oct-1995 |
$ 54,95 |
0 |
Of course this will make most people think “OK, cool: Firebird used a default value of 0 for the new fields — nothing to worry about”.But you can verify that the ID fields are really NULL
with these queries:
-
SELECT * FROM ADVENTURES WHERE ID = 0
(returns empty set) -
SELECT * FROM ADVENTURES WHERE ID IS NULL
(returns set shown above, with false 0’s) -
SELECT * FROM ADVENTURES WHERE ID IS NOT NULL
(returns empty set)
Another type of query hinting that something fishy is going on is the following:
-
SELECT NAME, ID, ID+3 FROM ADVENTURES
Such a query will return 0 in the “ID+3” column.With a true 0 ID it should have been 3.The correct result would be NULL
, of course!
If the added NOT NULL
column is of type (VAR)CHAR
instead of INT
, you will see phoney emptystrings (''
).With a DATE
column, phoney “zero dates” of 17 November 1858 (epoch of the Modified Julian Day).In all cases, the true state of the data is NULL
.