qb
qb copied to clipboard
SQL Server: Inserting Empty String in DateTime Column Becomes 1/1/1900
Imagine you want to save a struct like this to the database:
myFruit = {
"name": "Banana",
"color": "Yellow",
"eatenDate": ""
};
qb.from( "fruit" ).insert( myFruit );
One would think that when you query the fruit you just inserted, the eatenDate
value would be null. However, in MSSQL server if you insert an empty string (''), it will set the date to 1/1/1900.
Now, you could fix this by explicitly setting myFruit.eatenDate
to { value="", null=true }
. However, this extra step should be optional since most developers would expect QB to interpret an empty string as null when persisting the data to the database.