activerecord-sqlserver-adapter 4.2.18 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -223
- data/Gemfile +18 -17
- data/RAILS5-TODO.md +36 -0
- data/README.md +27 -8
- data/RUNNING_UNIT_TESTS.md +0 -17
- data/Rakefile +2 -7
- data/VERSION +1 -1
- data/activerecord-sqlserver-adapter.gemspec +1 -1
- data/appveyor.yml +0 -2
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +15 -8
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +45 -97
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +1 -2
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +31 -10
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +0 -18
- data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +16 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +101 -58
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +7 -7
- data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +20 -0
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +56 -32
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +1 -1
- data/lib/active_record/connection_adapters/sqlserver/type.rb +34 -32
- data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +4 -0
- data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +6 -0
- data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +3 -0
- data/lib/active_record/connection_adapters/sqlserver/type/char.rb +9 -20
- data/lib/active_record/connection_adapters/sqlserver/type/data.rb +30 -0
- data/lib/active_record/connection_adapters/sqlserver/type/date.rb +28 -4
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +28 -14
- data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +4 -16
- data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +9 -0
- data/lib/active_record/connection_adapters/sqlserver/type/float.rb +4 -0
- data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +3 -0
- data/lib/active_record/connection_adapters/sqlserver/type/money.rb +5 -1
- data/lib/active_record/connection_adapters/sqlserver/type/real.rb +4 -0
- data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +3 -1
- data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +5 -1
- data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +8 -1
- data/lib/active_record/connection_adapters/sqlserver/type/text.rb +4 -0
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +20 -8
- data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +25 -10
- data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +4 -0
- data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +3 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +6 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +4 -0
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +7 -1
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +5 -1
- data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +15 -2
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +7 -1
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +5 -1
- data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +7 -1
- data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +5 -1
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +10 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +71 -57
- data/lib/active_record/connection_adapters/sqlserver_column.rb +5 -30
- data/lib/active_record/sqlserver_base.rb +1 -5
- data/lib/arel/visitors/sqlserver.rb +11 -20
- data/test/bin/setup.sh +4 -6
- data/test/cases/adapter_test_sqlserver.rb +11 -20
- data/test/cases/coerced_tests.rb +233 -138
- data/test/cases/column_test_sqlserver.rb +244 -227
- data/test/cases/connection_test_sqlserver.rb +5 -76
- data/test/cases/fully_qualified_identifier_test_sqlserver.rb +7 -7
- data/test/cases/helper_sqlserver.rb +4 -15
- data/test/cases/pessimistic_locking_test_sqlserver.rb +1 -1
- data/test/cases/rake_test_sqlserver.rb +20 -14
- data/test/cases/schema_dumper_test_sqlserver.rb +94 -63
- data/test/cases/schema_test_sqlserver.rb +2 -2
- data/test/cases/showplan_test_sqlserver.rb +1 -1
- data/test/cases/specific_schema_test_sqlserver.rb +7 -14
- data/test/cases/transaction_test_sqlserver.rb +1 -1
- data/test/cases/uuid_test_sqlserver.rb +0 -1
- data/test/config.yml +0 -10
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +1 -1
- data/test/schema/sqlserver_specific_schema.rb +0 -16
- data/test/support/coerceable_test_sqlserver.rb +6 -2
- data/test/support/connection_reflection.rb +0 -4
- data/test/support/sql_counter_sqlserver.rb +17 -21
- metadata +9 -7
- data/lib/active_record/connection_adapters/sqlserver/core_ext/odbc.rb +0 -34
- data/lib/active_record/connection_adapters/sqlserver/schema_cache.rb +0 -114
@@ -36,14 +36,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
36
36
|
it 'bigint(8)' do
|
37
37
|
col = column('bigint')
|
38
38
|
col.sql_type.must_equal 'bigint(8)'
|
39
|
+
col.type.must_equal :bigint
|
39
40
|
col.null.must_equal true
|
40
41
|
col.default.must_equal 42
|
41
42
|
obj.bigint.must_equal 42
|
42
|
-
col.default_function.
|
43
|
-
type = col
|
43
|
+
col.default_function.must_be_nil
|
44
|
+
type = connection.lookup_cast_type_from_column(col)
|
44
45
|
type.must_be_instance_of Type::BigInteger
|
45
|
-
type.type.must_equal :bigint
|
46
|
-
type.must_be :number?
|
47
46
|
type.limit.must_equal 8
|
48
47
|
assert_obj_set_and_save :bigint, -9_223_372_036_854_775_808
|
49
48
|
assert_obj_set_and_save :bigint, 9_223_372_036_854_775_807
|
@@ -52,14 +51,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
52
51
|
it 'int(4)' do
|
53
52
|
col = column('int')
|
54
53
|
col.sql_type.must_equal 'int(4)'
|
54
|
+
col.type.must_equal :integer
|
55
55
|
col.null.must_equal true
|
56
56
|
col.default.must_equal 42
|
57
57
|
obj.int.must_equal 42
|
58
|
-
col.default_function.
|
59
|
-
type = col
|
58
|
+
col.default_function.must_be_nil
|
59
|
+
type = connection.lookup_cast_type_from_column(col)
|
60
60
|
type.must_be_instance_of Type::Integer
|
61
|
-
type.type.must_equal :integer
|
62
|
-
type.must_be :number?
|
63
61
|
type.limit.must_equal 4
|
64
62
|
assert_obj_set_and_save :int, -2_147_483_648
|
65
63
|
assert_obj_set_and_save :int, 2_147_483_647
|
@@ -68,14 +66,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
68
66
|
it 'smallint(2)' do
|
69
67
|
col = column('smallint')
|
70
68
|
col.sql_type.must_equal 'smallint(2)'
|
69
|
+
col.type.must_equal :integer
|
71
70
|
col.null.must_equal true
|
72
71
|
col.default.must_equal 42
|
73
72
|
obj.smallint.must_equal 42
|
74
|
-
col.default_function.
|
75
|
-
type = col
|
73
|
+
col.default_function.must_be_nil
|
74
|
+
type = connection.lookup_cast_type_from_column(col)
|
76
75
|
type.must_be_instance_of Type::SmallInteger
|
77
|
-
type.type.must_equal :integer
|
78
|
-
type.must_be :number?
|
79
76
|
type.limit.must_equal 2
|
80
77
|
assert_obj_set_and_save :smallint, -32_768
|
81
78
|
assert_obj_set_and_save :smallint, 32_767
|
@@ -84,14 +81,13 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
84
81
|
it 'tinyint(1)' do
|
85
82
|
col = column('tinyint')
|
86
83
|
col.sql_type.must_equal 'tinyint(1)'
|
84
|
+
col.type.must_equal :integer
|
87
85
|
col.null.must_equal true
|
88
86
|
col.default.must_equal 42
|
89
87
|
obj.tinyint.must_equal 42
|
90
|
-
col.default_function.
|
91
|
-
type = col
|
88
|
+
col.default_function.must_be_nil
|
89
|
+
type = connection.lookup_cast_type_from_column(col)
|
92
90
|
type.must_be_instance_of Type::TinyInteger
|
93
|
-
type.type.must_equal :integer
|
94
|
-
type.must_be :number?
|
95
91
|
type.limit.must_equal 1
|
96
92
|
assert_obj_set_and_save :tinyint, 0
|
97
93
|
assert_obj_set_and_save :tinyint, 255
|
@@ -100,15 +96,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
100
96
|
it 'bit' do
|
101
97
|
col = column('bit')
|
102
98
|
col.sql_type.must_equal 'bit'
|
99
|
+
col.type.must_equal :boolean
|
103
100
|
col.null.must_equal true
|
104
101
|
col.default.must_equal true
|
105
102
|
obj.bit.must_equal true
|
106
|
-
col.default_function.
|
107
|
-
type = col
|
103
|
+
col.default_function.must_be_nil
|
104
|
+
type = connection.lookup_cast_type_from_column(col)
|
108
105
|
type.must_be_instance_of Type::Boolean
|
109
|
-
type.
|
110
|
-
type.wont_be :number?
|
111
|
-
type.limit.must_equal nil
|
106
|
+
type.limit.must_be_nil
|
112
107
|
obj.bit = 0
|
113
108
|
obj.bit.must_equal false
|
114
109
|
obj.save!
|
@@ -122,15 +117,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
122
117
|
it 'decimal(9,2)' do
|
123
118
|
col = column('decimal_9_2')
|
124
119
|
col.sql_type.must_equal 'decimal(9,2)'
|
120
|
+
col.type.must_equal :decimal
|
125
121
|
col.null.must_equal true
|
126
122
|
col.default.must_equal BigDecimal('12345.01')
|
127
123
|
obj.decimal_9_2.must_equal BigDecimal('12345.01')
|
128
|
-
col.default_function.
|
129
|
-
type = col
|
124
|
+
col.default_function.must_be_nil
|
125
|
+
type = connection.lookup_cast_type_from_column(col)
|
130
126
|
type.must_be_instance_of Type::Decimal
|
131
|
-
type.
|
132
|
-
type.must_be :number?
|
133
|
-
type.limit.must_equal nil
|
127
|
+
type.limit.must_be_nil
|
134
128
|
type.precision.must_equal 9
|
135
129
|
type.scale.must_equal 2
|
136
130
|
obj.decimal_9_2 = '1234567.8901'
|
@@ -144,8 +138,8 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
144
138
|
col.sql_type.must_equal 'decimal(16,4)'
|
145
139
|
col.default.must_equal BigDecimal('1234567.89')
|
146
140
|
obj.decimal_16_4.must_equal BigDecimal('1234567.89')
|
147
|
-
col.default_function.
|
148
|
-
type = col
|
141
|
+
col.default_function.must_be_nil
|
142
|
+
type = connection.lookup_cast_type_from_column(col)
|
149
143
|
type.precision.must_equal 16
|
150
144
|
type.scale.must_equal 4
|
151
145
|
obj.decimal_16_4 = '1234567.8901001'
|
@@ -157,15 +151,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
157
151
|
it 'numeric(18,0)' do
|
158
152
|
col = column('numeric_18_0')
|
159
153
|
col.sql_type.must_equal 'numeric(18,0)'
|
154
|
+
col.type.must_equal :decimal
|
160
155
|
col.null.must_equal true
|
161
156
|
col.default.must_equal BigDecimal('191')
|
162
157
|
obj.numeric_18_0.must_equal BigDecimal('191')
|
163
|
-
col.default_function.
|
164
|
-
type = col
|
158
|
+
col.default_function.must_be_nil
|
159
|
+
type = connection.lookup_cast_type_from_column(col)
|
165
160
|
type.must_be_instance_of Type::Decimal
|
166
|
-
type.
|
167
|
-
type.must_be :number?
|
168
|
-
type.limit.must_equal nil
|
161
|
+
type.limit.must_be_nil
|
169
162
|
type.precision.must_equal 18
|
170
163
|
type.scale.must_equal 0
|
171
164
|
obj.numeric_18_0 = '192.1'
|
@@ -177,15 +170,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
177
170
|
it 'numeric(36,2)' do
|
178
171
|
col = column('numeric_36_2')
|
179
172
|
col.sql_type.must_equal 'numeric(36,2)'
|
173
|
+
col.type.must_equal :decimal
|
180
174
|
col.null.must_equal true
|
181
175
|
col.default.must_equal BigDecimal('12345678901234567890.01')
|
182
176
|
obj.numeric_36_2.must_equal BigDecimal('12345678901234567890.01')
|
183
|
-
col.default_function.
|
184
|
-
type = col
|
177
|
+
col.default_function.must_be_nil
|
178
|
+
type = connection.lookup_cast_type_from_column(col)
|
185
179
|
type.must_be_instance_of Type::Decimal
|
186
|
-
type.
|
187
|
-
type.must_be :number?
|
188
|
-
type.limit.must_equal nil
|
180
|
+
type.limit.must_be_nil
|
189
181
|
type.precision.must_equal 36
|
190
182
|
type.scale.must_equal 2
|
191
183
|
obj.numeric_36_2 = '192.123'
|
@@ -197,15 +189,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
197
189
|
it 'money' do
|
198
190
|
col = column('money')
|
199
191
|
col.sql_type.must_equal 'money'
|
192
|
+
col.type.must_equal :money
|
200
193
|
col.null.must_equal true
|
201
194
|
col.default.must_equal BigDecimal('4.20')
|
202
195
|
obj.money.must_equal BigDecimal('4.20')
|
203
|
-
col.default_function.
|
204
|
-
type = col
|
196
|
+
col.default_function.must_be_nil
|
197
|
+
type = connection.lookup_cast_type_from_column(col)
|
205
198
|
type.must_be_instance_of Type::Money
|
206
|
-
type.
|
207
|
-
type.must_be :number?
|
208
|
-
type.limit.must_equal nil
|
199
|
+
type.limit.must_be_nil
|
209
200
|
type.precision.must_equal 19
|
210
201
|
type.scale.must_equal 4
|
211
202
|
obj.money = '922337203685477.58061'
|
@@ -217,15 +208,14 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
217
208
|
it 'smallmoney' do
|
218
209
|
col = column('smallmoney')
|
219
210
|
col.sql_type.must_equal 'smallmoney'
|
211
|
+
col.type.must_equal :smallmoney
|
220
212
|
col.null.must_equal true
|
221
213
|
col.default.must_equal BigDecimal('4.20')
|
222
214
|
obj.smallmoney.must_equal BigDecimal('4.20')
|
223
|
-
col.default_function.
|
224
|
-
type = col
|
215
|
+
col.default_function.must_be_nil
|
216
|
+
type = connection.lookup_cast_type_from_column(col)
|
225
217
|
type.must_be_instance_of Type::SmallMoney
|
226
|
-
type.
|
227
|
-
type.must_be :number?
|
228
|
-
type.limit.must_equal nil
|
218
|
+
type.limit.must_be_nil
|
229
219
|
type.precision.must_equal 10
|
230
220
|
type.scale.must_equal 4
|
231
221
|
obj.smallmoney = '214748.36461'
|
@@ -241,17 +231,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
241
231
|
it 'float' do
|
242
232
|
col = column('float')
|
243
233
|
col.sql_type.must_equal 'float'
|
234
|
+
col.type.must_equal :float
|
244
235
|
col.null.must_equal true
|
245
236
|
col.default.must_equal 123.00000001
|
246
237
|
obj.float.must_equal 123.00000001
|
247
|
-
col.default_function.
|
248
|
-
type = col
|
238
|
+
col.default_function.must_be_nil
|
239
|
+
type = connection.lookup_cast_type_from_column(col)
|
249
240
|
type.must_be_instance_of Type::Float
|
250
|
-
type.
|
251
|
-
type.
|
252
|
-
type.
|
253
|
-
type.precision.must_equal nil
|
254
|
-
type.scale.must_equal nil
|
241
|
+
type.limit.must_be_nil
|
242
|
+
type.precision.must_be_nil
|
243
|
+
type.scale.must_be_nil
|
255
244
|
obj.float = '214748.36461'
|
256
245
|
obj.float.must_equal 214748.36461
|
257
246
|
obj.save!
|
@@ -261,17 +250,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
261
250
|
it 'real' do
|
262
251
|
col = column('real')
|
263
252
|
col.sql_type.must_equal 'real'
|
253
|
+
col.type.must_equal :real
|
264
254
|
col.null.must_equal true
|
265
255
|
col.default.must_be_close_to 123.45, 0.01
|
266
256
|
obj.real.must_be_close_to 123.45, 0.01
|
267
|
-
col.default_function.
|
268
|
-
type = col
|
257
|
+
col.default_function.must_be_nil
|
258
|
+
type = connection.lookup_cast_type_from_column(col)
|
269
259
|
type.must_be_instance_of Type::Real
|
270
|
-
type.
|
271
|
-
type.
|
272
|
-
type.
|
273
|
-
type.precision.must_equal nil
|
274
|
-
type.scale.must_equal nil
|
260
|
+
type.limit.must_be_nil
|
261
|
+
type.precision.must_be_nil
|
262
|
+
type.scale.must_be_nil
|
275
263
|
obj.real = '214748.36461'
|
276
264
|
obj.real.must_be_close_to 214748.36461, 0.01
|
277
265
|
obj.save!
|
@@ -283,22 +271,30 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
283
271
|
it 'date' do
|
284
272
|
col = column('date')
|
285
273
|
col.sql_type.must_equal 'date'
|
274
|
+
col.type.must_equal :date
|
286
275
|
col.null.must_equal true
|
287
276
|
col.default.must_equal connection_dblib_73? ? Date.civil(0001, 1, 1) : '0001-01-01'
|
288
277
|
obj.date.must_equal Date.civil(0001, 1, 1)
|
289
|
-
col.default_function.
|
290
|
-
type = col
|
278
|
+
col.default_function.must_be_nil
|
279
|
+
type = connection.lookup_cast_type_from_column(col)
|
291
280
|
type.must_be_instance_of Type::Date
|
292
|
-
type.
|
293
|
-
type.
|
294
|
-
type.
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
obj.
|
299
|
-
obj.date.must_equal Date.civil(0001,
|
281
|
+
type.limit.must_be_nil
|
282
|
+
type.precision.must_be_nil
|
283
|
+
type.scale.must_be_nil
|
284
|
+
# Can cast strings. SQL Server format.
|
285
|
+
obj.date = '04-01-0001'
|
286
|
+
obj.date.must_equal Date.civil(0001, 4, 1)
|
287
|
+
obj.save!
|
288
|
+
obj.date.must_equal Date.civil(0001, 4, 1)
|
289
|
+
obj.reload
|
290
|
+
obj.date.must_equal Date.civil(0001, 4, 1)
|
291
|
+
# Can cast strings. ISO format.
|
292
|
+
obj.date = '0001-04-01'
|
293
|
+
obj.date.must_equal Date.civil(0001, 4, 1)
|
300
294
|
obj.save!
|
301
|
-
obj.
|
295
|
+
obj.date.must_equal Date.civil(0001, 4, 1)
|
296
|
+
obj.reload
|
297
|
+
obj.date.must_equal Date.civil(0001, 4, 1)
|
302
298
|
# Can keep and return assigned date.
|
303
299
|
assert_obj_set_and_save :date, Date.civil(1972, 04, 14)
|
304
300
|
# Can accept and cast time objects.
|
@@ -311,109 +307,144 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
311
307
|
it 'datetime' do
|
312
308
|
col = column('datetime')
|
313
309
|
col.sql_type.must_equal 'datetime'
|
310
|
+
col.type.must_equal :datetime
|
314
311
|
col.null.must_equal true
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
312
|
+
time = Time.utc 1753, 01, 01, 00, 00, 00, 123000
|
313
|
+
col.default.must_equal time, "Microseconds were <#{col.default.usec}> vs <123000>"
|
314
|
+
obj.datetime.must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <123000>"
|
315
|
+
col.default_function.must_be_nil
|
316
|
+
type = connection.lookup_cast_type_from_column(col)
|
319
317
|
type.must_be_instance_of Type::DateTime
|
320
|
-
type.
|
321
|
-
type.
|
322
|
-
type.
|
323
|
-
|
324
|
-
|
318
|
+
type.limit.must_be_nil
|
319
|
+
type.precision.must_be_nil
|
320
|
+
type.scale.must_be_nil
|
321
|
+
obj.save!
|
322
|
+
obj.must_equal obj.class.where(datetime: time).first
|
325
323
|
# Can save to proper accuracy and return again.
|
326
|
-
|
327
|
-
obj.datetime
|
324
|
+
time = Time.utc 2010, 04, 01, 12, 34, 56, 3000
|
325
|
+
obj.datetime = time
|
326
|
+
obj.datetime.must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
328
327
|
obj.save!
|
329
|
-
obj.
|
328
|
+
obj.datetime.must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
329
|
+
obj.reload
|
330
|
+
obj.datetime.must_equal time, "Microseconds were <#{obj.datetime.usec}> vs <3000>"
|
331
|
+
obj.must_equal obj.class.where(datetime: time).first
|
330
332
|
# Will cast to true DB value on attribute write, save and return again.
|
331
|
-
|
332
|
-
|
333
|
+
time = Time.utc 2010, 04, 01, 12, 34, 56, 234567
|
334
|
+
time2 = Time.utc 2010, 04, 01, 12, 34, 56, 233000
|
335
|
+
obj.datetime = time
|
336
|
+
obj.datetime.must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
337
|
+
obj.save!
|
338
|
+
obj.datetime.must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
339
|
+
obj.reload
|
340
|
+
obj.datetime.must_equal time2, "Microseconds were <#{obj.datetime.usec}> vs <233000>"
|
341
|
+
obj.must_equal obj.class.where(datetime: time).first
|
342
|
+
obj.must_equal obj.class.where(datetime: time2).first
|
343
|
+
# Set and find nil.
|
344
|
+
obj.datetime = nil
|
345
|
+
obj.datetime.must_be_nil
|
333
346
|
obj.save!
|
334
|
-
obj.
|
347
|
+
obj.datetime.must_be_nil
|
348
|
+
obj.must_equal obj.class.where(datetime: nil).first
|
335
349
|
end
|
336
350
|
|
337
351
|
it 'datetime2' do
|
338
352
|
skip 'datetime2 not supported in this protocal version' unless connection_dblib_73?
|
339
353
|
col = column('datetime2_7')
|
340
354
|
col.sql_type.must_equal 'datetime2(7)'
|
355
|
+
col.type.must_equal :datetime
|
341
356
|
col.null.must_equal true
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
357
|
+
time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(999999900, 1000)
|
358
|
+
col.default.must_equal time, "Nanoseconds were <#{col.default.nsec}> vs <999999900>"
|
359
|
+
obj.datetime2_7.must_equal time, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <999999900>"
|
360
|
+
col.default_function.must_be_nil
|
361
|
+
type = connection.lookup_cast_type_from_column(col)
|
346
362
|
type.must_be_instance_of Type::DateTime2
|
347
|
-
type.
|
348
|
-
type.wont_be :number?
|
349
|
-
type.limit.must_equal nil
|
363
|
+
type.limit.must_be_nil
|
350
364
|
type.precision.must_equal 7
|
351
|
-
type.scale.
|
365
|
+
type.scale.must_be_nil
|
366
|
+
obj.save!
|
367
|
+
obj.must_equal obj.class.where(datetime2_7: time).first
|
352
368
|
# Can save 100 nanosecond precisoins and return again.
|
353
|
-
|
354
|
-
|
369
|
+
time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456755, 1000)
|
370
|
+
time2 = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456800, 1000)
|
371
|
+
obj.datetime2_7 = time
|
372
|
+
obj.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456800>"
|
355
373
|
obj.save!
|
356
|
-
obj.
|
374
|
+
obj.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456800>"
|
375
|
+
obj.reload
|
376
|
+
obj.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <123456800>"
|
377
|
+
obj.must_equal obj.class.where(datetime2_7: time).first
|
378
|
+
obj.must_equal obj.class.where(datetime2_7: time2).first
|
357
379
|
# Can save small fraction nanosecond precisoins and return again.
|
358
|
-
|
359
|
-
|
380
|
+
time = Time.utc 2008, 6, 21, 13, 30, 0, Rational(15020, 1000)
|
381
|
+
time2 = Time.utc 2008, 6, 21, 13, 30, 0, Rational(15000, 1000)
|
382
|
+
obj.datetime2_7 = time
|
383
|
+
obj.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <15000>"
|
360
384
|
obj.save!
|
361
|
-
obj.reload.datetime2_7.must_equal
|
362
|
-
|
385
|
+
obj.reload.datetime2_7.must_equal time2, "Nanoseconds were <#{obj.datetime2_7.nsec}> vs <15000>"
|
386
|
+
obj.must_equal obj.class.where(datetime2_7: time).first
|
387
|
+
obj.must_equal obj.class.where(datetime2_7: time2).first
|
388
|
+
# datetime2_3
|
363
389
|
time = Time.utc 9999, 12, 31, 23, 59, 59, Rational(123456789, 1000)
|
364
390
|
col = column('datetime2_3')
|
365
|
-
col.
|
391
|
+
connection.lookup_cast_type_from_column(col).precision.must_equal 3
|
366
392
|
obj.datetime2_3 = time
|
367
393
|
obj.datetime2_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
|
368
394
|
obj.save! ; obj.reload
|
369
395
|
obj.datetime2_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetime2_3.nsec}> vs <123000000>"
|
396
|
+
obj.must_equal obj.class.where(datetime2_3: time).first
|
397
|
+
# datetime2_1
|
370
398
|
col = column('datetime2_1')
|
371
|
-
col.
|
399
|
+
connection.lookup_cast_type_from_column(col).precision.must_equal 1
|
372
400
|
obj.datetime2_1 = time
|
373
401
|
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
374
402
|
obj.save! ; obj.reload
|
375
403
|
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
404
|
+
obj.must_equal obj.class.where(datetime2_1: time).first
|
405
|
+
# datetime2_0
|
376
406
|
col = column('datetime2_0')
|
377
|
-
col.
|
407
|
+
connection.lookup_cast_type_from_column(col).precision.must_equal 0
|
378
408
|
time = Time.utc 2016, 4, 19, 16, 45, 40, 771036
|
379
409
|
obj.datetime2_0 = time
|
380
410
|
obj.datetime2_0.must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
|
381
411
|
obj.save! ; obj.reload
|
382
412
|
obj.datetime2_0.must_equal time.change(nsec: 0), "Nanoseconds were <#{obj.datetime2_0.nsec}> vs <0>"
|
413
|
+
obj.must_equal obj.class.where(datetime2_0: time).first
|
383
414
|
end
|
384
415
|
|
385
416
|
it 'datetimeoffset' do
|
386
417
|
skip 'datetimeoffset not supported in this protocal version' unless connection_dblib_73?
|
387
418
|
col = column('datetimeoffset_7')
|
388
419
|
col.sql_type.must_equal 'datetimeoffset(7)'
|
420
|
+
col.type.must_equal :datetime
|
389
421
|
col.null.must_equal true
|
390
422
|
col.default.must_equal Time.new(1984, 01, 24, 04, 20, 00, -28800).change(nsec: 123456700), "Nanoseconds <#{col.default.nsec}> vs <123456700>"
|
391
423
|
obj.datetimeoffset_7.must_equal Time.new(1984, 01, 24, 04, 20, 00, -28800).change(nsec: 123456700), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <999999900>"
|
392
|
-
col.default_function.
|
393
|
-
type = col
|
424
|
+
col.default_function.must_be_nil
|
425
|
+
type = connection.lookup_cast_type_from_column(col)
|
394
426
|
type.must_be_instance_of Type::DateTimeOffset
|
395
|
-
type.
|
396
|
-
type.wont_be :number?
|
397
|
-
type.limit.must_equal nil
|
427
|
+
type.limit.must_be_nil
|
398
428
|
type.precision.must_equal 7
|
399
|
-
type.scale.
|
429
|
+
type.scale.must_be_nil
|
400
430
|
# Can save 100 nanosecond precisoins and return again.
|
401
|
-
obj.datetimeoffset_7 = Time.new(2010,
|
402
|
-
obj.datetimeoffset_7.must_equal Time.new(2010,
|
403
|
-
obj.save!
|
404
|
-
obj.datetimeoffset_7.must_equal Time.new(2010,
|
431
|
+
obj.datetimeoffset_7 = Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456755)
|
432
|
+
obj.datetimeoffset_7.must_equal Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
433
|
+
obj.save!
|
434
|
+
obj.datetimeoffset_7.must_equal Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
435
|
+
obj.reload
|
436
|
+
obj.datetimeoffset_7.must_equal Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
405
437
|
# With other precisions.
|
406
438
|
time = ActiveSupport::TimeZone['America/Los_Angeles'].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
|
407
439
|
col = column('datetimeoffset_3')
|
408
|
-
col.
|
440
|
+
connection.lookup_cast_type_from_column(col).precision.must_equal 3
|
409
441
|
obj.datetimeoffset_3 = time
|
410
442
|
obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
|
411
443
|
# TODO: FreeTDS date bug fixed: https://github.com/FreeTDS/freetds/issues/44
|
412
|
-
return
|
413
444
|
obj.save! ; obj.reload
|
414
445
|
obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
|
415
446
|
col = column('datetime2_1')
|
416
|
-
col.
|
447
|
+
connection.lookup_cast_type_from_column(col).precision.must_equal 1
|
417
448
|
obj.datetime2_1 = time
|
418
449
|
obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
|
419
450
|
obj.save! ; obj.reload
|
@@ -423,38 +454,38 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
423
454
|
it 'smalldatetime' do
|
424
455
|
col = column('smalldatetime')
|
425
456
|
col.sql_type.must_equal 'smalldatetime'
|
457
|
+
col.type.must_equal :smalldatetime
|
426
458
|
col.null.must_equal true
|
427
459
|
col.default.must_equal Time.utc(1901, 01, 01, 15, 45, 00, 000)
|
428
460
|
obj.smalldatetime.must_equal Time.utc(1901, 01, 01, 15, 45, 00, 000)
|
429
|
-
col.default_function.
|
430
|
-
type = col
|
461
|
+
col.default_function.must_be_nil
|
462
|
+
type = connection.lookup_cast_type_from_column(col)
|
431
463
|
type.must_be_instance_of Type::SmallDateTime
|
432
|
-
type.
|
433
|
-
type.
|
434
|
-
type.
|
435
|
-
type.precision.must_equal nil
|
436
|
-
type.scale.must_equal nil
|
464
|
+
type.limit.must_be_nil
|
465
|
+
type.precision.must_be_nil
|
466
|
+
type.scale.must_be_nil
|
437
467
|
# Will remove fractional seconds and return again.
|
438
468
|
obj.smalldatetime = Time.utc(2078, 06, 05, 4, 20, 00, 3000)
|
439
|
-
obj.smalldatetime.must_equal
|
469
|
+
obj.smalldatetime.must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.smalldatetime.usec}> vs <0>"
|
440
470
|
obj.save!
|
441
|
-
obj.
|
471
|
+
obj.smalldatetime.must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.reload.smalldatetime.usec}> vs <0>"
|
472
|
+
obj.reload
|
473
|
+
obj.smalldatetime.must_equal Time.utc(2078, 06, 05, 4, 20, 00, 0), "Microseconds were <#{obj.reload.smalldatetime.usec}> vs <0>"
|
442
474
|
end
|
443
475
|
|
444
476
|
it 'time(7)' do
|
445
477
|
skip 'time() not supported in this protocal version' unless connection_dblib_73?
|
446
478
|
col = column('time_7')
|
447
479
|
col.sql_type.must_equal 'time(7)'
|
480
|
+
col.type.must_equal :time
|
448
481
|
col.null.must_equal true
|
449
482
|
col.default.must_equal Time.utc(1900, 01, 01, 04, 20, 00, Rational(288321500, 1000)), "Nanoseconds were <#{col.default.nsec}> vs <288321500>"
|
450
|
-
col.default_function.
|
451
|
-
type = col
|
483
|
+
col.default_function.must_be_nil
|
484
|
+
type = connection.lookup_cast_type_from_column(col)
|
452
485
|
type.must_be_instance_of Type::Time
|
453
|
-
type.
|
454
|
-
type.wont_be :number?
|
455
|
-
type.limit.must_equal nil
|
486
|
+
type.limit.must_be_nil
|
456
487
|
type.precision.must_equal 7
|
457
|
-
type.scale.
|
488
|
+
type.scale.must_be_nil
|
458
489
|
# Time's #usec precision (low micro)
|
459
490
|
obj.time_7 = Time.utc(2000, 01, 01, 15, 45, 00, 300)
|
460
491
|
obj.time_7.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 300), "Microseconds were <#{obj.time_7.usec}> vs <0>"
|
@@ -478,16 +509,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
478
509
|
skip 'time() not supported in this protocal version' unless connection_dblib_73?
|
479
510
|
col = column('time_2')
|
480
511
|
col.sql_type.must_equal 'time(2)'
|
512
|
+
col.type.must_equal :time
|
481
513
|
col.null.must_equal true
|
482
|
-
col.default.
|
483
|
-
col.default_function.
|
484
|
-
type = col
|
514
|
+
col.default.must_be_nil
|
515
|
+
col.default_function.must_be_nil
|
516
|
+
type = connection.lookup_cast_type_from_column(col)
|
485
517
|
type.must_be_instance_of Type::Time
|
486
|
-
type.
|
487
|
-
type.wont_be :number?
|
488
|
-
type.limit.must_equal nil
|
518
|
+
type.limit.must_be_nil
|
489
519
|
type.precision.must_equal 2
|
490
|
-
type.scale.
|
520
|
+
type.scale.must_be_nil
|
491
521
|
# Always uses TinyTDS/Windows 2000-01-01 convention too.
|
492
522
|
obj.time_2 = Time.utc(2015, 01, 10, 15, 45, 00, 0)
|
493
523
|
obj.time_2.must_equal Time.utc(2000, 01, 01, 15, 45, 00, 0)
|
@@ -510,17 +540,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
510
540
|
it 'char(10)' do
|
511
541
|
col = column('char_10')
|
512
542
|
col.sql_type.must_equal 'char(10)'
|
543
|
+
col.type.must_equal :char
|
513
544
|
col.null.must_equal true
|
514
545
|
col.default.must_equal '1234567890'
|
515
546
|
obj.char_10.must_equal '1234567890'
|
516
|
-
col.default_function.
|
517
|
-
type = col
|
547
|
+
col.default_function.must_be_nil
|
548
|
+
type = connection.lookup_cast_type_from_column(col)
|
518
549
|
type.must_be_instance_of Type::Char
|
519
|
-
type.type.must_equal :char
|
520
|
-
type.wont_be :number?
|
521
550
|
type.limit.must_equal 10
|
522
|
-
type.precision.
|
523
|
-
type.scale.
|
551
|
+
type.precision.must_be_nil
|
552
|
+
type.scale.must_be_nil
|
524
553
|
# Basic set and save.
|
525
554
|
obj.char_10 = '012345'
|
526
555
|
obj.char_10.strip.must_equal '012345'
|
@@ -531,17 +560,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
531
560
|
it 'varchar(50)' do
|
532
561
|
col = column('varchar_50')
|
533
562
|
col.sql_type.must_equal 'varchar(50)'
|
563
|
+
col.type.must_equal :varchar
|
534
564
|
col.null.must_equal true
|
535
565
|
col.default.must_equal 'test varchar_50'
|
536
566
|
obj.varchar_50.must_equal 'test varchar_50'
|
537
|
-
col.default_function.
|
538
|
-
type = col
|
567
|
+
col.default_function.must_be_nil
|
568
|
+
type = connection.lookup_cast_type_from_column(col)
|
539
569
|
type.must_be_instance_of Type::Varchar
|
540
|
-
type.type.must_equal :varchar
|
541
|
-
type.wont_be :number?
|
542
570
|
type.limit.must_equal 50
|
543
|
-
type.precision.
|
544
|
-
type.scale.
|
571
|
+
type.precision.must_be_nil
|
572
|
+
type.scale.must_be_nil
|
545
573
|
# Basic set and save.
|
546
574
|
assert_obj_set_and_save :varchar_50, 'Hello World'
|
547
575
|
end
|
@@ -549,17 +577,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
549
577
|
it 'varchar(max)' do
|
550
578
|
col = column('varchar_max')
|
551
579
|
col.sql_type.must_equal 'varchar(max)'
|
580
|
+
col.type.must_equal :varchar_max
|
552
581
|
col.null.must_equal true
|
553
582
|
col.default.must_equal 'test varchar_max'
|
554
583
|
obj.varchar_max.must_equal 'test varchar_max'
|
555
|
-
col.default_function.
|
556
|
-
type = col
|
584
|
+
col.default_function.must_be_nil
|
585
|
+
type = connection.lookup_cast_type_from_column(col)
|
557
586
|
type.must_be_instance_of Type::VarcharMax
|
558
|
-
type.type.must_equal :varchar_max
|
559
|
-
type.wont_be :number?
|
560
587
|
type.limit.must_equal 2_147_483_647
|
561
|
-
type.precision.
|
562
|
-
type.scale.
|
588
|
+
type.precision.must_be_nil
|
589
|
+
type.scale.must_be_nil
|
563
590
|
# Basic set and save.
|
564
591
|
assert_obj_set_and_save :varchar_max, 'Hello World'
|
565
592
|
end
|
@@ -567,17 +594,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
567
594
|
it 'text' do
|
568
595
|
col = column('text')
|
569
596
|
col.sql_type.must_equal 'text'
|
597
|
+
col.type.must_equal :text_basic
|
570
598
|
col.null.must_equal true
|
571
599
|
col.default.must_equal 'test text'
|
572
600
|
obj.text.must_equal 'test text'
|
573
|
-
col.default_function.
|
574
|
-
type = col
|
601
|
+
col.default_function.must_be_nil
|
602
|
+
type = connection.lookup_cast_type_from_column(col)
|
575
603
|
type.must_be_instance_of Type::Text
|
576
|
-
type.type.must_equal :text_basic
|
577
|
-
type.wont_be :number?
|
578
604
|
type.limit.must_equal 2_147_483_647
|
579
|
-
type.precision.
|
580
|
-
type.scale.
|
605
|
+
type.precision.must_be_nil
|
606
|
+
type.scale.must_be_nil
|
581
607
|
# Basic set and save.
|
582
608
|
assert_obj_set_and_save :text, 'Hello World'
|
583
609
|
end
|
@@ -587,17 +613,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
587
613
|
it 'nchar(10)' do
|
588
614
|
col = column('nchar_10')
|
589
615
|
col.sql_type.must_equal 'nchar(10)'
|
616
|
+
col.type.must_equal :nchar
|
590
617
|
col.null.must_equal true
|
591
618
|
col.default.must_equal '12345678åå'
|
592
619
|
obj.nchar_10.must_equal '12345678åå'
|
593
|
-
col.default_function.
|
594
|
-
type = col
|
620
|
+
col.default_function.must_be_nil
|
621
|
+
type = connection.lookup_cast_type_from_column(col)
|
595
622
|
type.must_be_instance_of Type::UnicodeChar
|
596
|
-
type.type.must_equal :nchar
|
597
|
-
type.wont_be :number?
|
598
623
|
type.limit.must_equal 10
|
599
|
-
type.precision.
|
600
|
-
type.scale.
|
624
|
+
type.precision.must_be_nil
|
625
|
+
type.scale.must_be_nil
|
601
626
|
# Basic set and save.
|
602
627
|
obj.nchar_10 = "五六"
|
603
628
|
obj.nchar_10.strip.must_equal "五六"
|
@@ -608,17 +633,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
608
633
|
it 'nvarchar(50)' do
|
609
634
|
col = column('nvarchar_50')
|
610
635
|
col.sql_type.must_equal 'nvarchar(50)'
|
636
|
+
col.type.must_equal :string
|
611
637
|
col.null.must_equal true
|
612
638
|
col.default.must_equal 'test nvarchar_50 åå'
|
613
639
|
obj.nvarchar_50.must_equal 'test nvarchar_50 åå'
|
614
|
-
col.default_function.
|
615
|
-
type = col
|
640
|
+
col.default_function.must_be_nil
|
641
|
+
type = connection.lookup_cast_type_from_column(col)
|
616
642
|
type.must_be_instance_of Type::UnicodeVarchar
|
617
|
-
type.type.must_equal :string
|
618
|
-
type.wont_be :number?
|
619
643
|
type.limit.must_equal 50
|
620
|
-
type.precision.
|
621
|
-
type.scale.
|
644
|
+
type.precision.must_be_nil
|
645
|
+
type.scale.must_be_nil
|
622
646
|
# Basic set and save.
|
623
647
|
assert_obj_set_and_save :nvarchar_50, "一二34五六"
|
624
648
|
end
|
@@ -626,17 +650,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
626
650
|
it 'nvarchar(max)' do
|
627
651
|
col = column('nvarchar_max')
|
628
652
|
col.sql_type.must_equal 'nvarchar(max)'
|
653
|
+
col.type.must_equal :text
|
629
654
|
col.null.must_equal true
|
630
655
|
col.default.must_equal 'test nvarchar_max åå'
|
631
656
|
obj.nvarchar_max.must_equal 'test nvarchar_max åå'
|
632
|
-
col.default_function.
|
633
|
-
type = col
|
657
|
+
col.default_function.must_be_nil
|
658
|
+
type = connection.lookup_cast_type_from_column(col)
|
634
659
|
type.must_be_instance_of Type::UnicodeVarcharMax
|
635
|
-
type.type.must_equal :text
|
636
|
-
type.wont_be :number?
|
637
660
|
type.limit.must_equal 2_147_483_647
|
638
|
-
type.precision.
|
639
|
-
type.scale.
|
661
|
+
type.precision.must_be_nil
|
662
|
+
type.scale.must_be_nil
|
640
663
|
# Basic set and save.
|
641
664
|
assert_obj_set_and_save :nvarchar_max, "一二34五六"
|
642
665
|
end
|
@@ -644,17 +667,16 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
644
667
|
it 'ntext' do
|
645
668
|
col = column('ntext')
|
646
669
|
col.sql_type.must_equal 'ntext'
|
670
|
+
col.type.must_equal :ntext
|
647
671
|
col.null.must_equal true
|
648
672
|
col.default.must_equal 'test ntext åå'
|
649
673
|
obj.ntext.must_equal 'test ntext åå'
|
650
|
-
col.default_function.
|
651
|
-
type = col
|
674
|
+
col.default_function.must_be_nil
|
675
|
+
type = connection.lookup_cast_type_from_column(col)
|
652
676
|
type.must_be_instance_of Type::UnicodeText
|
653
|
-
type.type.must_equal :ntext
|
654
|
-
type.wont_be :number?
|
655
677
|
type.limit.must_equal 2_147_483_647
|
656
|
-
type.precision.
|
657
|
-
type.scale.
|
678
|
+
type.precision.must_be_nil
|
679
|
+
type.scale.must_be_nil
|
658
680
|
# Basic set and save.
|
659
681
|
assert_obj_set_and_save :ntext, "一二34五六"
|
660
682
|
end
|
@@ -667,16 +689,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
667
689
|
it 'binary(49)' do
|
668
690
|
col = column('binary_49')
|
669
691
|
col.sql_type.must_equal 'binary(49)'
|
692
|
+
col.type.must_equal :binary_basic
|
670
693
|
col.null.must_equal true
|
671
|
-
col.default.
|
672
|
-
col.default_function.
|
673
|
-
type = col
|
694
|
+
col.default.must_be_nil
|
695
|
+
col.default_function.must_be_nil
|
696
|
+
type = connection.lookup_cast_type_from_column(col)
|
674
697
|
type.must_be_instance_of Type::Binary
|
675
|
-
type.type.must_equal :binary_basic
|
676
|
-
type.wont_be :number?
|
677
698
|
type.limit.must_equal 49
|
678
|
-
type.precision.
|
679
|
-
type.scale.
|
699
|
+
type.precision.must_be_nil
|
700
|
+
type.scale.must_be_nil
|
680
701
|
# Basic set and save.
|
681
702
|
binary_data.encoding.must_equal Encoding::BINARY
|
682
703
|
binary_data.length.must_equal 49
|
@@ -689,16 +710,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
689
710
|
it 'varbinary(49)' do
|
690
711
|
col = column('varbinary_49')
|
691
712
|
col.sql_type.must_equal 'varbinary(49)'
|
713
|
+
col.type.must_equal :varbinary
|
692
714
|
col.null.must_equal true
|
693
|
-
col.default.
|
694
|
-
col.default_function.
|
695
|
-
type = col
|
715
|
+
col.default.must_be_nil
|
716
|
+
col.default_function.must_be_nil
|
717
|
+
type = connection.lookup_cast_type_from_column(col)
|
696
718
|
type.must_be_instance_of Type::Varbinary
|
697
|
-
type.type.must_equal :varbinary
|
698
|
-
type.wont_be :number?
|
699
719
|
type.limit.must_equal 49
|
700
|
-
type.precision.
|
701
|
-
type.scale.
|
720
|
+
type.precision.must_be_nil
|
721
|
+
type.scale.must_be_nil
|
702
722
|
# Basic set and save.
|
703
723
|
binary_data_20 = binary_data.to(20)
|
704
724
|
binary_data_20.encoding.must_equal Encoding::BINARY
|
@@ -711,16 +731,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
711
731
|
it 'varbinary(max)' do
|
712
732
|
col = column('varbinary_max')
|
713
733
|
col.sql_type.must_equal 'varbinary(max)'
|
734
|
+
col.type.must_equal :binary
|
714
735
|
col.null.must_equal true
|
715
|
-
col.default.
|
716
|
-
col.default_function.
|
717
|
-
type = col
|
736
|
+
col.default.must_be_nil
|
737
|
+
col.default_function.must_be_nil
|
738
|
+
type = connection.lookup_cast_type_from_column(col)
|
718
739
|
type.must_be_instance_of Type::VarbinaryMax
|
719
|
-
type.type.must_equal :binary
|
720
|
-
type.wont_be :number?
|
721
740
|
type.limit.must_equal 2_147_483_647
|
722
|
-
type.precision.
|
723
|
-
type.scale.
|
741
|
+
type.precision.must_be_nil
|
742
|
+
type.scale.must_be_nil
|
724
743
|
# Basic set and save.
|
725
744
|
binary_data.encoding.must_equal Encoding::BINARY
|
726
745
|
assert_obj_set_and_save :varbinary_max, binary_data
|
@@ -731,19 +750,18 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
731
750
|
it 'uniqueidentifier' do
|
732
751
|
col = column('uniqueidentifier')
|
733
752
|
col.sql_type.must_equal 'uniqueidentifier'
|
753
|
+
col.type.must_equal :uuid
|
734
754
|
col.null.must_equal true
|
735
|
-
col.default.
|
755
|
+
col.default.must_be_nil
|
736
756
|
col.default_function.must_equal 'newid()'
|
737
|
-
type = col
|
757
|
+
type = connection.lookup_cast_type_from_column(col)
|
738
758
|
type.must_be_instance_of Type::Uuid
|
739
|
-
type.
|
740
|
-
type.
|
741
|
-
type.
|
742
|
-
type.precision.must_equal nil
|
743
|
-
type.scale.must_equal nil
|
759
|
+
type.limit.must_be_nil
|
760
|
+
type.precision.must_be_nil
|
761
|
+
type.scale.must_be_nil
|
744
762
|
# Basic set and save.
|
745
763
|
obj.uniqueidentifier = "this will not qualify as valid"
|
746
|
-
obj.uniqueidentifier.
|
764
|
+
obj.uniqueidentifier.must_be_nil
|
747
765
|
obj.save! ; obj.reload
|
748
766
|
obj.uniqueidentifier.must_match Type::Uuid::ACCEPTABLE_UUID
|
749
767
|
obj.uniqueidentifier = "6F9619FF-8B86-D011-B42D-00C04FC964FF"
|
@@ -755,18 +773,17 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
755
773
|
it 'timestamp' do
|
756
774
|
col = column('timestamp')
|
757
775
|
col.sql_type.must_equal 'timestamp'
|
776
|
+
col.type.must_equal :ss_timestamp
|
758
777
|
col.null.must_equal true
|
759
|
-
col.default.
|
760
|
-
col.default_function.
|
761
|
-
type = col
|
778
|
+
col.default.must_be_nil
|
779
|
+
col.default_function.must_be_nil
|
780
|
+
type = connection.lookup_cast_type_from_column(col)
|
762
781
|
type.must_be_instance_of Type::Timestamp
|
763
|
-
type.
|
764
|
-
type.
|
765
|
-
type.
|
766
|
-
type.precision.must_equal nil
|
767
|
-
type.scale.must_equal nil
|
782
|
+
type.limit.must_be_nil
|
783
|
+
type.precision.must_be_nil
|
784
|
+
type.scale.must_be_nil
|
768
785
|
# Basic read.
|
769
|
-
obj.timestamp.
|
786
|
+
obj.timestamp.must_be_nil
|
770
787
|
obj.save! ; obj.reload
|
771
788
|
obj.timestamp.must_match %r|\000|
|
772
789
|
obj.timestamp
|