Skip to content

Commit 5a0ceff

Browse files
author
Lalitha
committed
Fix date comparison failures by having sqlserver default date set to 1900-01-01
- SQLserver uses 1900-01-01 as default date instead of current date - Reference: https://docs.microsoft.com/en-us/sql/relational-databases/native-client-odbc-date-time/datetime-data-type-conversions-from-sql-to-c?view=sql-server-2017
1 parent 7f1fda5 commit 5a0ceff

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

test/cases/column_test_sqlserver.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,28 +273,28 @@ def assert_obj_set_and_save(attribute, value)
273273
col.sql_type.must_equal 'date'
274274
col.type.must_equal :date
275275
col.null.must_equal true
276-
col.default.must_equal connection_dblib_73? ? Date.civil(0001, 1, 1) : '0001-01-01'
277-
obj.date.must_equal Date.civil(0001, 1, 1)
276+
col.default.must_equal Date.civil(1900, 1, 1)
277+
obj.date.must_equal Date.civil(1900, 1, 1)
278278
col.default_function.must_be_nil
279279
type = connection.lookup_cast_type_from_column(col)
280280
type.must_be_instance_of Type::Date
281281
type.limit.must_be_nil
282282
type.precision.must_be_nil
283283
type.scale.must_be_nil
284284
# Can cast strings. SQL Server format.
285-
obj.date = '04-01-0001'
286-
obj.date.must_equal Date.civil(0001, 4, 1)
285+
obj.date = '04-01-1900'
286+
obj.date.must_equal Date.civil(1900, 4, 1)
287287
obj.save!
288-
obj.date.must_equal Date.civil(0001, 4, 1)
288+
obj.date.must_equal Date.civil(1900, 4, 1)
289289
obj.reload
290-
obj.date.must_equal Date.civil(0001, 4, 1)
290+
obj.date.must_equal Date.civil(1900, 4, 1)
291291
# Can cast strings. ISO format.
292-
obj.date = '0001-04-01'
293-
obj.date.must_equal Date.civil(0001, 4, 1)
292+
obj.date = '1900-04-01'
293+
obj.date.must_equal Date.civil(1900, 4, 1)
294294
obj.save!
295-
obj.date.must_equal Date.civil(0001, 4, 1)
295+
obj.date.must_equal Date.civil(1900, 4, 1)
296296
obj.reload
297-
obj.date.must_equal Date.civil(0001, 4, 1)
297+
obj.date.must_equal Date.civil(1900, 4, 1)
298298
# Can keep and return assigned date.
299299
assert_obj_set_and_save :date, Date.civil(1972, 04, 14)
300300
# Can accept and cast time objects.

test/cases/schema_dumper_test_sqlserver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
2323
assert_line :float, type: 'float', limit: nil, precision: nil, scale: nil, default: 123.00000001
2424
assert_line :real, type: 'real', limit: nil, precision: nil, scale: nil, default: 123.45
2525
# Date and Time
26-
assert_line :date, type: 'date', limit: nil, precision: nil, scale: nil, default: "01-01-0001"
26+
assert_line :date, type: 'date', limit: nil, precision: nil, scale: nil, default: "01-01-1900"
2727
assert_line :datetime, type: 'datetime', limit: nil, precision: nil, scale: nil, default: "01-01-1753 00:00:00.123"
2828
if connection_dblib_73?
2929
assert_line :datetime2_7, type: 'datetime', limit: nil, precision: 7, scale: nil, default: "12-31-9999 23:59:59.9999999"

test/schema/datatypes/2012.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ CREATE TABLE [sst_datatypes] (
2323
[float] [float] NULL DEFAULT 123.00000001,
2424
[real] [real] NULL DEFAULT 123.45,
2525
-- Date and Time
26-
[date] [date] NULL DEFAULT '0001-01-01',
26+
[date] [date] NULL DEFAULT '1900-01-01',
2727
[datetime] [datetime] NULL DEFAULT '1753-01-01T00:00:00.123',
2828
[datetime2_7] [datetime2](7) NULL DEFAULT '9999-12-31 23:59:59.9999999',
2929
[datetime2_3] [datetime2](3) NULL,

0 commit comments

Comments
 (0)