activerecord-sqlserver-adapter 2.3.7 → 3.2.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +385 -61
- data/MIT-LICENSE +1 -1
- data/VERSION +1 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +42 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/database_statements.rb +97 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +41 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain_subscriber.rb +26 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/odbc.rb +38 -0
- data/lib/active_record/connection_adapters/sqlserver/core_ext/relation.rb +19 -0
- data/lib/active_record/connection_adapters/sqlserver/database_limits.rb +49 -0
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +458 -0
- data/lib/active_record/connection_adapters/sqlserver/errors.rb +36 -0
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +113 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_cache.rb +85 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +376 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +69 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +25 -0
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +67 -0
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +32 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +344 -1055
- data/lib/arel/visitors/sqlserver.rb +389 -0
- metadata +60 -83
- data/README.rdoc +0 -190
- data/RUNNING_UNIT_TESTS +0 -65
- data/Rakefile +0 -41
- data/autotest/discover.rb +0 -4
- data/autotest/railssqlserver.rb +0 -16
- data/autotest/sqlserver.rb +0 -54
- data/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/active_record.rb +0 -151
- data/lib/active_record/connection_adapters/sqlserver_adapter/core_ext/odbc.rb +0 -40
- data/test/cases/aaaa_create_tables_test_sqlserver.rb +0 -19
- data/test/cases/adapter_test_sqlserver.rb +0 -756
- data/test/cases/attribute_methods_test_sqlserver.rb +0 -33
- data/test/cases/basics_test_sqlserver.rb +0 -21
- data/test/cases/calculations_test_sqlserver.rb +0 -20
- data/test/cases/column_test_sqlserver.rb +0 -285
- data/test/cases/connection_test_sqlserver.rb +0 -146
- data/test/cases/eager_association_test_sqlserver.rb +0 -42
- data/test/cases/execute_procedure_test_sqlserver.rb +0 -44
- data/test/cases/inheritance_test_sqlserver.rb +0 -28
- data/test/cases/method_scoping_test_sqlserver.rb +0 -28
- data/test/cases/migration_test_sqlserver.rb +0 -123
- data/test/cases/named_scope_test_sqlserver.rb +0 -21
- data/test/cases/offset_and_limit_test_sqlserver.rb +0 -108
- data/test/cases/pessimistic_locking_test_sqlserver.rb +0 -125
- data/test/cases/query_cache_test_sqlserver.rb +0 -24
- data/test/cases/schema_dumper_test_sqlserver.rb +0 -72
- data/test/cases/specific_schema_test_sqlserver.rb +0 -97
- data/test/cases/sqlserver_helper.rb +0 -127
- data/test/cases/table_name_test_sqlserver.rb +0 -38
- data/test/cases/transaction_test_sqlserver.rb +0 -93
- data/test/cases/unicode_test_sqlserver.rb +0 -50
- data/test/cases/validations_test_sqlserver.rb +0 -35
- data/test/connections/native_sqlserver/connection.rb +0 -25
- data/test/connections/native_sqlserver_odbc/connection.rb +0 -27
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +0 -11
- data/test/schema/sqlserver_specific_schema.rb +0 -94
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
require 'models/topic'
|
3
|
-
|
4
|
-
class AttributeMethodsTestSqlserver < ActiveRecord::TestCase
|
5
|
-
end
|
6
|
-
|
7
|
-
class AttributeMethodsTest < ActiveRecord::TestCase
|
8
|
-
|
9
|
-
COERCED_TESTS = [
|
10
|
-
:test_typecast_attribute_from_select_to_false,
|
11
|
-
:test_typecast_attribute_from_select_to_true
|
12
|
-
]
|
13
|
-
|
14
|
-
include SqlserverCoercedTest
|
15
|
-
|
16
|
-
fixtures :topics
|
17
|
-
|
18
|
-
|
19
|
-
def test_coerced_typecast_attribute_from_select_to_false
|
20
|
-
topic = Topic.create(:title => 'Budget')
|
21
|
-
topic = Topic.find(:first, :select => "topics.*, CASE WHEN 1=2 THEN 1 ELSE 0 END as is_test")
|
22
|
-
assert !topic.is_test?
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_coerced_typecast_attribute_from_select_to_true
|
26
|
-
topic = Topic.create(:title => 'Budget')
|
27
|
-
topic = Topic.find(:first, :select => "topics.*, CASE WHEN 2=2 THEN 1 ELSE 0 END as is_test")
|
28
|
-
assert topic.is_test?
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
require 'models/developer'
|
3
|
-
|
4
|
-
class BasicsTestSqlserver < ActiveRecord::TestCase
|
5
|
-
end
|
6
|
-
|
7
|
-
class BasicsTest < ActiveRecord::TestCase
|
8
|
-
|
9
|
-
COERCED_TESTS = [:test_read_attributes_before_type_cast_on_datetime]
|
10
|
-
|
11
|
-
include SqlserverCoercedTest
|
12
|
-
|
13
|
-
fixtures :developers
|
14
|
-
|
15
|
-
def test_coerced_test_read_attributes_before_type_cast_on_datetime
|
16
|
-
developer = Developer.find(:first)
|
17
|
-
assert_equal developer.created_at.to_s(:db)+'.000' , developer.attributes_before_type_cast["created_at"]
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
require 'models/company'
|
3
|
-
|
4
|
-
class CalculationsTestSqlserver < ActiveRecord::TestCase
|
5
|
-
end
|
6
|
-
|
7
|
-
class CalculationsTest < ActiveRecord::TestCase
|
8
|
-
|
9
|
-
COERCED_TESTS = [:test_should_sum_expression]
|
10
|
-
|
11
|
-
include SqlserverCoercedTest
|
12
|
-
|
13
|
-
fixtures :accounts
|
14
|
-
|
15
|
-
def test_coerced_test_should_sum_expression
|
16
|
-
assert_equal 636, Account.sum("2 * credit_limit")
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
end
|
@@ -1,285 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
require 'models/binary'
|
3
|
-
|
4
|
-
class SqlServerEdgeSchema < ActiveRecord::Base; end;
|
5
|
-
|
6
|
-
class ColumnTestSqlserver < ActiveRecord::TestCase
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@connection = ActiveRecord::Base.connection
|
10
|
-
@column_klass = ActiveRecord::ConnectionAdapters::SQLServerColumn
|
11
|
-
end
|
12
|
-
|
13
|
-
should 'return real_number as float' do
|
14
|
-
assert_equal :float, TableWithRealColumn.columns_hash["real_number"].type
|
15
|
-
end
|
16
|
-
|
17
|
-
should 'know its #table_name and #table_klass' do
|
18
|
-
Topic.columns.each do |column|
|
19
|
-
assert_equal 'topics', column.table_name, "This column #{column.inspect} did not know it's #table_name"
|
20
|
-
assert_equal Topic, column.table_klass, "This column #{column.inspect} did not know it's #table_klass"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
should 'return correct null, limit, and default for Topic' do
|
25
|
-
tch = Topic.columns_hash
|
26
|
-
assert_equal false, tch['id'].null
|
27
|
-
assert_equal true, tch['title'].null
|
28
|
-
assert_equal 255, tch['author_name'].limit
|
29
|
-
assert_equal true, tch['approved'].default
|
30
|
-
assert_equal 0, tch['replies_count'].default
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'For binary columns' do
|
34
|
-
|
35
|
-
setup do
|
36
|
-
@binary_string = "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000\000!\371\004\000\000\000\000\000,\000\000\000\000\001\000\001\000\000\002\002D\001\000;"
|
37
|
-
@saved_bdata = Binary.create!(:data => @binary_string)
|
38
|
-
end
|
39
|
-
|
40
|
-
should 'read and write binary data equally' do
|
41
|
-
assert_equal @binary_string, Binary.find(@saved_bdata).data
|
42
|
-
end
|
43
|
-
|
44
|
-
should 'have correct attributes' do
|
45
|
-
column = Binary.columns_hash['data']
|
46
|
-
assert_equal :binary, column.type
|
47
|
-
assert_equal @connection.native_binary_database_type, column.sql_type
|
48
|
-
assert_equal nil, column.limit
|
49
|
-
end
|
50
|
-
|
51
|
-
should 'quote data for sqlserver with literal 0x prefix' do
|
52
|
-
# See the output of the stored procedure: 'exec sp_datatype_info'
|
53
|
-
sqlserver_encoded_bdata = "0x47494638396101000100800000ffffff00000021f90400000000002c00000000010001000002024401003b"
|
54
|
-
assert_equal sqlserver_encoded_bdata, @column_klass.string_to_binary(@binary_string)
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'For string columns' do
|
60
|
-
|
61
|
-
setup do
|
62
|
-
@char = SqlServerString.columns_hash['char']
|
63
|
-
@char10 = SqlServerString.columns_hash['char_10']
|
64
|
-
@varcharmax = SqlServerString.columns_hash['varchar_max']
|
65
|
-
@varcharmax10 = SqlServerString.columns_hash['varchar_max_10']
|
66
|
-
end
|
67
|
-
|
68
|
-
should 'have correct simplified types' do
|
69
|
-
assert_equal :string, @char.type
|
70
|
-
assert_equal :string, @char10.type
|
71
|
-
if sqlserver_2005? || sqlserver_2008?
|
72
|
-
assert_equal :text, @varcharmax.type, @varcharmax.inspect
|
73
|
-
assert_equal :text, @varcharmax10.type, @varcharmax10.inspect
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
should 'have correct #sql_type per schema definition' do
|
78
|
-
assert_equal 'char(1)', @char.sql_type, 'Specifing a char type with no limit is 1 by SQL Server standards.'
|
79
|
-
assert_equal 'char(10)', @char10.sql_type, @char10.inspect
|
80
|
-
if sqlserver_2005? || sqlserver_2008?
|
81
|
-
assert_equal 'varchar(max)', @varcharmax.sql_type, 'A -1 limit should be converted to max (max) type.'
|
82
|
-
assert_equal 'varchar(max)', @varcharmax10.sql_type, 'A -1 limit should be converted to max (max) type.'
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
should 'have correct #limit per schema definition' do
|
87
|
-
assert_equal 1, @char.limit
|
88
|
-
assert_equal 10, @char10.limit
|
89
|
-
if sqlserver_2005? || sqlserver_2008?
|
90
|
-
assert_equal nil, @varcharmax.limit, 'Limits on max types are moot and we should let rails know that.'
|
91
|
-
assert_equal nil, @varcharmax10.limit, 'Limits on max types are moot and we should let rails know that.'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
context 'For all national/unicode columns' do
|
99
|
-
|
100
|
-
setup do
|
101
|
-
@nchar = SqlServerUnicode.columns_hash['nchar']
|
102
|
-
@nvarchar = SqlServerUnicode.columns_hash['nvarchar']
|
103
|
-
@ntext = SqlServerUnicode.columns_hash['ntext']
|
104
|
-
@ntext10 = SqlServerUnicode.columns_hash['ntext_10']
|
105
|
-
@nchar10 = SqlServerUnicode.columns_hash['nchar_10']
|
106
|
-
@nvarchar100 = SqlServerUnicode.columns_hash['nvarchar_100']
|
107
|
-
@nvarcharmax = SqlServerUnicode.columns_hash['nvarchar_max']
|
108
|
-
@nvarcharmax10 = SqlServerUnicode.columns_hash['nvarchar_max_10']
|
109
|
-
end
|
110
|
-
|
111
|
-
should 'all respond true to #is_utf8?' do
|
112
|
-
SqlServerUnicode.columns_hash.except('id').values.each do |column|
|
113
|
-
assert column.is_utf8?, "This column #{column.inspect} should have been a unicode column."
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
should 'have correct simplified types' do
|
118
|
-
assert_equal :string, @nchar.type
|
119
|
-
assert_equal :string, @nvarchar.type
|
120
|
-
assert_equal :text, @ntext.type
|
121
|
-
assert_equal :text, @ntext10.type
|
122
|
-
assert_equal :string, @nchar10.type
|
123
|
-
assert_equal :string, @nvarchar100.type
|
124
|
-
if sqlserver_2005? || sqlserver_2008?
|
125
|
-
assert_equal :text, @nvarcharmax.type, @nvarcharmax.inspect
|
126
|
-
assert_equal :text, @nvarcharmax10.type, @nvarcharmax10.inspect
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
should 'have correct #sql_type per schema definition' do
|
131
|
-
assert_equal 'nchar(1)', @nchar.sql_type, 'Specifing a nchar type with no limit is 1 by SQL Server standards.'
|
132
|
-
assert_equal 'nvarchar(255)', @nvarchar.sql_type, 'Default nvarchar limit is 255.'
|
133
|
-
assert_equal 'ntext', @ntext.sql_type, 'Nice and clean ntext, limit means nothing here.'
|
134
|
-
assert_equal 'ntext', @ntext10.sql_type, 'Even a next with a limit of 10 specified will mean nothing.'
|
135
|
-
assert_equal 'nchar(10)', @nchar10.sql_type, 'An nchar with a limit of 10 needs to have it show up here.'
|
136
|
-
assert_equal 'nvarchar(100)', @nvarchar100.sql_type, 'An nvarchar with a specified limit of 100 needs to show it.'
|
137
|
-
if sqlserver_2005? || sqlserver_2008?
|
138
|
-
assert_equal 'nvarchar(max)', @nvarcharmax.sql_type, 'A -1 limit should be converted to max (max) type.'
|
139
|
-
assert_equal 'nvarchar(max)', @nvarcharmax10.sql_type, 'A -1 limit should be converted to max (max) type.'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
should 'have correct #limit per schema definition' do
|
144
|
-
assert_equal 1, @nchar.limit
|
145
|
-
assert_equal 255, @nvarchar.limit
|
146
|
-
assert_equal nil, @ntext.limit, 'An ntext column limit is moot, it is a fixed variable length'
|
147
|
-
assert_equal 10, @nchar10.limit
|
148
|
-
assert_equal 100, @nvarchar100.limit
|
149
|
-
if sqlserver_2005? || sqlserver_2008?
|
150
|
-
assert_equal nil, @nvarcharmax.limit, 'Limits on max types are moot and we should let rails know that.'
|
151
|
-
assert_equal nil, @nvarcharmax10.limit, 'Limits on max types are moot and we should let rails know that.'
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'For datetime columns' do
|
158
|
-
|
159
|
-
setup do
|
160
|
-
@date = SqlServerChronic.columns_hash['date']
|
161
|
-
@time = SqlServerChronic.columns_hash['time']
|
162
|
-
@datetime = SqlServerChronic.columns_hash['datetime']
|
163
|
-
@smalldatetime = SqlServerChronic.columns_hash['smalldatetime']
|
164
|
-
end
|
165
|
-
|
166
|
-
should 'have correct simplified type for uncast datetime' do
|
167
|
-
assert_equal :datetime, @datetime.type
|
168
|
-
end
|
169
|
-
|
170
|
-
should 'use correct #sql_type for different sql server versions' do
|
171
|
-
assert_equal 'datetime', @datetime.sql_type
|
172
|
-
if sqlserver_2000? || sqlserver_2005?
|
173
|
-
assert_equal 'datetime', @date.sql_type
|
174
|
-
assert_equal 'datetime', @time.sql_type
|
175
|
-
else
|
176
|
-
assert_equal 'date', @date.sql_type
|
177
|
-
assert_equal 'time', @time.sql_type
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
should 'all be have nil #limit' do
|
182
|
-
assert_equal nil, @date.limit
|
183
|
-
assert_equal nil, @time.limit
|
184
|
-
assert_equal nil, @datetime.limit
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'For smalldatetime types' do
|
188
|
-
|
189
|
-
should 'have created that type using rails migrations' do
|
190
|
-
assert_equal 'smalldatetime', @smalldatetime.sql_type
|
191
|
-
end
|
192
|
-
|
193
|
-
should 'be able to insert column without truncation warnings or the like' do
|
194
|
-
SqlServerChronic.create! :smalldatetime => Time.now
|
195
|
-
end
|
196
|
-
|
197
|
-
should 'be able to update column without truncation warnings or the like' do
|
198
|
-
ssc = SqlServerChronic.create! :smalldatetime => 2.days.ago
|
199
|
-
ssc.update_attributes! :smalldatetime => Time.now
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'which have coerced types' do
|
205
|
-
|
206
|
-
setup do
|
207
|
-
christmas_08 = "2008-12-25".to_time
|
208
|
-
christmas_08_afternoon = "2008-12-25 12:00".to_time
|
209
|
-
@chronic_date = SqlServerChronic.create!(:date => christmas_08).reload
|
210
|
-
@chronic_time = SqlServerChronic.create!(:time => christmas_08_afternoon).reload
|
211
|
-
end
|
212
|
-
|
213
|
-
should 'have an inheritable attribute ' do
|
214
|
-
assert SqlServerChronic.coerced_sqlserver_date_columns.include?('date') unless sqlserver_2008?
|
215
|
-
end
|
216
|
-
|
217
|
-
should 'have column and objects cast to date' do
|
218
|
-
assert_equal :date, @date.type, "This column: \n#{@date.inspect}"
|
219
|
-
assert_instance_of Date, @chronic_date.date
|
220
|
-
end
|
221
|
-
|
222
|
-
should 'have column objects cast to time' do
|
223
|
-
assert_equal :time, @time.type, "This column: \n#{@time.inspect}"
|
224
|
-
assert_instance_of Time, @chronic_time.time
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
context 'For decimal and numeric columns' do
|
232
|
-
|
233
|
-
setup do
|
234
|
-
@bank_balance = NumericData.columns_hash['bank_balance']
|
235
|
-
@big_bank_balance = NumericData.columns_hash['big_bank_balance']
|
236
|
-
@world_population = NumericData.columns_hash['world_population']
|
237
|
-
@my_house_population = NumericData.columns_hash['my_house_population']
|
238
|
-
end
|
239
|
-
|
240
|
-
should 'have correct simplified types' do
|
241
|
-
assert_equal :decimal, @bank_balance.type
|
242
|
-
assert_equal :decimal, @big_bank_balance.type
|
243
|
-
assert_equal :integer, @world_population.type, 'Since #extract_scale == 0'
|
244
|
-
assert_equal :integer, @my_house_population.type, 'Since #extract_scale == 0'
|
245
|
-
end
|
246
|
-
|
247
|
-
should 'have correct #sql_type' do
|
248
|
-
assert_equal 'decimal(10,2)', @bank_balance.sql_type
|
249
|
-
assert_equal 'decimal(15,2)', @big_bank_balance.sql_type
|
250
|
-
assert_equal 'decimal(10,0)', @world_population.sql_type
|
251
|
-
assert_equal 'decimal(2,0)', @my_house_population.sql_type
|
252
|
-
end
|
253
|
-
|
254
|
-
should 'have correct #limit' do
|
255
|
-
assert_equal nil, @bank_balance.limit
|
256
|
-
assert_equal nil, @big_bank_balance.limit
|
257
|
-
assert_equal nil, @world_population.limit
|
258
|
-
assert_equal nil, @my_house_population.limit
|
259
|
-
end
|
260
|
-
|
261
|
-
should 'return correct precisions and scales' do
|
262
|
-
assert_equal [10,2], [@bank_balance.precision, @bank_balance.scale]
|
263
|
-
assert_equal [15,2], [@big_bank_balance.precision, @big_bank_balance.scale]
|
264
|
-
assert_equal [10,0], [@world_population.precision, @world_population.scale]
|
265
|
-
assert_equal [2,0], [@my_house_population.precision, @my_house_population.scale]
|
266
|
-
end
|
267
|
-
|
268
|
-
end
|
269
|
-
|
270
|
-
context 'For tinyint columns' do
|
271
|
-
|
272
|
-
setup do
|
273
|
-
@tinyint = SqlServerEdgeSchema.columns_hash['tinyint']
|
274
|
-
end
|
275
|
-
|
276
|
-
should 'be all it should be' do
|
277
|
-
assert_equal :integer, @tinyint.type
|
278
|
-
assert_nil @tinyint.scale
|
279
|
-
assert_equal 'tinyint(1)', @tinyint.sql_type
|
280
|
-
end
|
281
|
-
|
282
|
-
end
|
283
|
-
|
284
|
-
|
285
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
require 'models/reply'
|
3
|
-
|
4
|
-
class ConnectionTestSqlserver < ActiveRecord::TestCase
|
5
|
-
|
6
|
-
self.use_transactional_fixtures = false
|
7
|
-
|
8
|
-
fixtures :topics, :accounts
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@connection = ActiveRecord::Base.connection
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
should 'return finished ODBC statment handle from #execute without block' do
|
16
|
-
assert_all_statements_used_are_closed do
|
17
|
-
@connection.execute('SELECT * FROM [topics]')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
should 'finish ODBC statment handle from #execute with block' do
|
22
|
-
assert_all_statements_used_are_closed do
|
23
|
-
@connection.execute('SELECT * FROM [topics]') { }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'finish connection from #raw_select' do
|
28
|
-
assert_all_statements_used_are_closed do
|
29
|
-
@connection.send(:raw_select,'SELECT * FROM [topics]')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
should 'affect rows' do
|
34
|
-
topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } }
|
35
|
-
updated = Topic.update(topic_data.keys, topic_data.values)
|
36
|
-
assert_equal 2, updated.size
|
37
|
-
assert_equal "1 updated", Topic.find(1).content
|
38
|
-
assert_equal "2 updated", Topic.find(2).content
|
39
|
-
assert_equal 2, Topic.delete([1, 2])
|
40
|
-
end
|
41
|
-
|
42
|
-
should 'execute without block closes statement' do
|
43
|
-
assert_all_statements_used_are_closed do
|
44
|
-
@connection.execute("SELECT 1")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
should 'execute with block closes statement' do
|
49
|
-
assert_all_statements_used_are_closed do
|
50
|
-
@connection.execute("SELECT 1") do |sth|
|
51
|
-
assert !sth.finished?, "Statement should still be alive within block"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
should 'insert with identity closes statement' do
|
57
|
-
assert_all_statements_used_are_closed do
|
58
|
-
@connection.insert("INSERT INTO accounts ([id], [firm_id],[credit_limit]) values (999, 1, 50)")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
should 'insert without identity closes statement' do
|
63
|
-
assert_all_statements_used_are_closed do
|
64
|
-
@connection.insert("INSERT INTO accounts ([firm_id],[credit_limit]) values (1, 50)")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
should 'active closes statement' do
|
69
|
-
assert_all_statements_used_are_closed do
|
70
|
-
@connection.active?
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
should 'allow usage of :database connection option to remove setting from dsn' do
|
75
|
-
assert_equal 'activerecord_unittest', @connection.current_database
|
76
|
-
begin
|
77
|
-
@connection.use_database('activerecord_unittest2')
|
78
|
-
assert_equal 'activerecord_unittest2', @connection.current_database
|
79
|
-
ensure
|
80
|
-
@connection.use_database
|
81
|
-
assert_equal 'activerecord_unittest', @connection.current_database, 'Would default back to connection options'
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'Connection management' do
|
86
|
-
|
87
|
-
setup do
|
88
|
-
assert @connection.active?
|
89
|
-
end
|
90
|
-
|
91
|
-
should 'be able to disconnect and reconnect at will' do
|
92
|
-
@connection.disconnect!
|
93
|
-
assert !@connection.active?
|
94
|
-
@connection.reconnect!
|
95
|
-
assert @connection.active?
|
96
|
-
end
|
97
|
-
|
98
|
-
should 'auto reconnect when setting is on' do
|
99
|
-
with_auto_connect(true) do
|
100
|
-
@connection.disconnect!
|
101
|
-
assert_nothing_raised() { Topic.count }
|
102
|
-
assert @connection.active?
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
should 'not auto reconnect when setting is off' do
|
107
|
-
with_auto_connect(false) do
|
108
|
-
@connection.disconnect!
|
109
|
-
assert_raise(ActiveRecord::StatementInvalid) { Topic.count }
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
private
|
118
|
-
|
119
|
-
def assert_all_statements_used_are_closed(&block)
|
120
|
-
existing_handles = []
|
121
|
-
ObjectSpace.each_object(ODBC::Statement) {|handle| existing_handles << handle}
|
122
|
-
GC.disable
|
123
|
-
yield
|
124
|
-
used_handles = []
|
125
|
-
ObjectSpace.each_object(ODBC::Statement) {|handle| used_handles << handle unless existing_handles.include? handle}
|
126
|
-
assert_block "No statements were used within given block" do
|
127
|
-
used_handles.size > 0
|
128
|
-
end
|
129
|
-
ObjectSpace.each_object(ODBC::Statement) do |handle|
|
130
|
-
assert_block "Statement should have been closed within given block" do
|
131
|
-
handle.finished?
|
132
|
-
end
|
133
|
-
end
|
134
|
-
ensure
|
135
|
-
GC.enable
|
136
|
-
end
|
137
|
-
|
138
|
-
def with_auto_connect(boolean)
|
139
|
-
existing = ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect
|
140
|
-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect = boolean
|
141
|
-
yield
|
142
|
-
ensure
|
143
|
-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.auto_connect = existing
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
require 'models/post'
|
3
|
-
require 'models/author'
|
4
|
-
require 'models/comment'
|
5
|
-
|
6
|
-
class EagerAssociationTestSqlserver < ActiveRecord::TestCase
|
7
|
-
end
|
8
|
-
|
9
|
-
class EagerAssociationTest < ActiveRecord::TestCase
|
10
|
-
|
11
|
-
COERCED_TESTS = [
|
12
|
-
:test_count_with_include,
|
13
|
-
:test_eager_with_has_many_and_limit_and_high_offset_and_multiple_array_conditions,
|
14
|
-
:test_eager_with_has_many_and_limit_and_high_offset_and_multiple_hash_conditions
|
15
|
-
]
|
16
|
-
|
17
|
-
include SqlserverCoercedTest
|
18
|
-
|
19
|
-
fixtures :authors, :posts, :comments
|
20
|
-
|
21
|
-
def test_coerced_test_count_with_include
|
22
|
-
assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "len(comments.body) > 15")
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_coerced_eager_with_has_many_and_limit_and_high_offset_and_multiple_array_conditions
|
26
|
-
assert_queries(2) do
|
27
|
-
posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10,
|
28
|
-
:conditions => [ "authors.name = ? and comments.body = ?", 'David', 'go crazy' ])
|
29
|
-
assert_equal 0, posts.size
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_coerced_eager_with_has_many_and_limit_and_high_offset_and_multiple_hash_conditions
|
34
|
-
assert_queries(2) do
|
35
|
-
posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10,
|
36
|
-
:conditions => { 'authors.name' => 'David', 'comments.body' => 'go crazy' })
|
37
|
-
assert_equal 0, posts.size
|
38
|
-
end
|
39
|
-
end unless active_record_2_point_2?
|
40
|
-
|
41
|
-
|
42
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
|
3
|
-
class ExecuteProcedureTestSqlserver < ActiveRecord::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@klass = ActiveRecord::Base
|
7
|
-
end
|
8
|
-
|
9
|
-
should 'execute a simple procedure' do
|
10
|
-
tables = @klass.execute_procedure :sp_tables
|
11
|
-
assert_instance_of Array, tables
|
12
|
-
assert_instance_of HashWithIndifferentAccess, tables.first
|
13
|
-
end
|
14
|
-
|
15
|
-
should 'take parameter arguments' do
|
16
|
-
tables = @klass.execute_procedure :sp_tables, 'sql_server_chronics'
|
17
|
-
table_info = tables.first
|
18
|
-
assert_equal 1, tables.size
|
19
|
-
assert_equal (ENV['ARUNIT_DB_NAME'] || 'activerecord_unittest'), table_info[:TABLE_QUALIFIER], "Table Info: #{table_info.inspect}"
|
20
|
-
assert_equal 'TABLE', table_info[:TABLE_TYPE], "Table Info: #{table_info.inspect}"
|
21
|
-
end
|
22
|
-
|
23
|
-
should 'quote bind vars correctly' do
|
24
|
-
assert_sql(/EXEC sp_tables '%sql_server%', NULL, NULL, NULL, 1/) do
|
25
|
-
@klass.execute_procedure :sp_tables, '%sql_server%', nil, nil, nil, true
|
26
|
-
end if sqlserver_2005? || sqlserver_2008?
|
27
|
-
assert_sql(/EXEC sp_tables '%sql_server%', NULL, NULL, NULL/) do
|
28
|
-
@klass.execute_procedure :sp_tables, '%sql_server%', nil, nil, nil
|
29
|
-
end if sqlserver_2000?
|
30
|
-
end
|
31
|
-
|
32
|
-
should 'allow multiple result sets to be returned' do
|
33
|
-
results1, results2 = @klass.execute_procedure('sp_helpconstraint','accounts')
|
34
|
-
assert_instance_of Array, results1
|
35
|
-
assert_instance_of HashWithIndifferentAccess, results1.first
|
36
|
-
assert results1.first['Object Name']
|
37
|
-
assert_instance_of Array, results2
|
38
|
-
assert_instance_of HashWithIndifferentAccess, results2.first
|
39
|
-
assert results2.first['constraint_name']
|
40
|
-
assert results2.first['constraint_type']
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
require 'models/company'
|
3
|
-
|
4
|
-
class InheritanceTestSqlserver < ActiveRecord::TestCase
|
5
|
-
end
|
6
|
-
|
7
|
-
class InheritanceTest < ActiveRecord::TestCase
|
8
|
-
|
9
|
-
COERCED_TESTS = [
|
10
|
-
:test_eager_load_belongs_to_primary_key_quoting,
|
11
|
-
:test_a_bad_type_column
|
12
|
-
]
|
13
|
-
|
14
|
-
include SqlserverCoercedTest
|
15
|
-
|
16
|
-
def test_coerced_test_eager_load_belongs_to_primary_key_quoting
|
17
|
-
assert_sql(/\(\[companies\].\[id\] = 1\)/) do
|
18
|
-
Account.find(1, :include => :firm)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_coerced_test_a_bad_type_column
|
23
|
-
Company.connection.insert "INSERT INTO [companies] ([id], #{QUOTED_TYPE}, [name]) VALUES(100, 'bad_class!', 'Not happening')"
|
24
|
-
assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'cases/sqlserver_helper'
|
2
|
-
require 'models/developer'
|
3
|
-
|
4
|
-
class MethodScopingTestSqlServer < ActiveRecord::TestCase
|
5
|
-
end
|
6
|
-
|
7
|
-
class NestedScopingTest < ActiveRecord::TestCase
|
8
|
-
|
9
|
-
COERCED_TESTS = [:test_merged_scoped_find]
|
10
|
-
|
11
|
-
include SqlserverCoercedTest
|
12
|
-
|
13
|
-
fixtures :developers
|
14
|
-
|
15
|
-
def test_coerced_test_merged_scoped_find
|
16
|
-
poor_jamis = developers(:poor_jamis)
|
17
|
-
Developer.with_scope(:find => { :conditions => "salary < 100000" }) do
|
18
|
-
Developer.with_scope(:find => { :offset => 1, :order => 'id asc' }) do
|
19
|
-
assert_sql /ORDER BY id ASC/ do
|
20
|
-
assert_equal(poor_jamis, Developer.find(:first, :order => 'id asc'))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
|