tiny_tds 3.2.0-x86_64-linux-gnu

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +20 -0
  3. data/.gitattributes +1 -0
  4. data/.github/workflows/ci.yml +590 -0
  5. data/.gitignore +22 -0
  6. data/.rubocop.yml +31 -0
  7. data/CHANGELOG.md +305 -0
  8. data/CODE_OF_CONDUCT.md +31 -0
  9. data/Gemfile +2 -0
  10. data/ISSUE_TEMPLATE.md +38 -0
  11. data/MIT-LICENSE +23 -0
  12. data/README.md +493 -0
  13. data/Rakefile +67 -0
  14. data/VERSION +1 -0
  15. data/bin/defncopy-ttds +3 -0
  16. data/bin/tsql-ttds +3 -0
  17. data/docker-compose.yml +34 -0
  18. data/exe/.keep +0 -0
  19. data/ext/tiny_tds/client.c +492 -0
  20. data/ext/tiny_tds/client.h +53 -0
  21. data/ext/tiny_tds/extconf.rb +190 -0
  22. data/ext/tiny_tds/extconsts.rb +8 -0
  23. data/ext/tiny_tds/result.c +626 -0
  24. data/ext/tiny_tds/result.h +32 -0
  25. data/ext/tiny_tds/tiny_tds_ext.c +15 -0
  26. data/ext/tiny_tds/tiny_tds_ext.h +17 -0
  27. data/lib/tiny_tds/2.7/tiny_tds.so +0 -0
  28. data/lib/tiny_tds/3.0/tiny_tds.so +0 -0
  29. data/lib/tiny_tds/3.1/tiny_tds.so +0 -0
  30. data/lib/tiny_tds/3.2/tiny_tds.so +0 -0
  31. data/lib/tiny_tds/3.3/tiny_tds.so +0 -0
  32. data/lib/tiny_tds/3.4/tiny_tds.so +0 -0
  33. data/lib/tiny_tds/bin.rb +90 -0
  34. data/lib/tiny_tds/client.rb +132 -0
  35. data/lib/tiny_tds/error.rb +12 -0
  36. data/lib/tiny_tds/gem.rb +23 -0
  37. data/lib/tiny_tds/result.rb +5 -0
  38. data/lib/tiny_tds/version.rb +3 -0
  39. data/lib/tiny_tds.rb +42 -0
  40. data/patches/freetds/1.00.27/0001-mingw_missing_inet_pton.diff +34 -0
  41. data/patches/freetds/1.00.27/0002-Don-t-use-MSYS2-file-libws2_32.diff +28 -0
  42. data/patches/libiconv/1.14/1-avoid-gets-error.patch +17 -0
  43. data/ports/x86_64-linux-gnu/bin/defncopy +0 -0
  44. data/ports/x86_64-linux-gnu/bin/tsql +0 -0
  45. data/ports/x86_64-linux-gnu/lib/libsybdb.so.5 +0 -0
  46. data/setup_cimgruby_dev.sh +25 -0
  47. data/start_dev.sh +21 -0
  48. data/tasks/native_gem.rake +16 -0
  49. data/tasks/package.rake +6 -0
  50. data/tasks/ports.rake +24 -0
  51. data/tasks/test.rake +7 -0
  52. data/test/bin/install-freetds.sh +18 -0
  53. data/test/bin/install-mssql.ps1 +42 -0
  54. data/test/bin/install-mssqltools.sh +9 -0
  55. data/test/bin/install-openssl.sh +18 -0
  56. data/test/bin/restore-from-native-gem.ps1 +10 -0
  57. data/test/bin/setup_tinytds_db.sh +7 -0
  58. data/test/bin/setup_volume_permissions.sh +10 -0
  59. data/test/client_test.rb +266 -0
  60. data/test/gem_test.rb +100 -0
  61. data/test/result_test.rb +708 -0
  62. data/test/schema/1px.gif +0 -0
  63. data/test/schema/sqlserver_2017.sql +140 -0
  64. data/test/schema/sqlserver_azure.sql +140 -0
  65. data/test/schema_test.rb +417 -0
  66. data/test/sql/db-create.sql +18 -0
  67. data/test/sql/db-login.sql +38 -0
  68. data/test/test_helper.rb +244 -0
  69. data/test/thread_test.rb +89 -0
  70. data/tiny_tds.gemspec +31 -0
  71. metadata +259 -0
@@ -0,0 +1,417 @@
1
+ require "test_helper"
2
+
3
+ class SchemaTest < TinyTds::TestCase
4
+ describe "Casting SQL Server schema" do
5
+ before do
6
+ @@current_schema_loaded ||= load_current_schema
7
+ @client = new_connection
8
+ @gif1px = File.read("test/schema/1px.gif", mode: "rb:BINARY")
9
+ end
10
+
11
+ it "casts bigint" do
12
+ assert_equal(-9223372036854775807, find_value(11, :bigint))
13
+ assert_equal 9223372036854775806, find_value(12, :bigint)
14
+ end
15
+
16
+ it "casts binary" do
17
+ value = find_value(21, :binary_50)
18
+ assert_equal @gif1px + "\000", value
19
+ assert_binary_encoding(value)
20
+ end
21
+
22
+ it "casts bit" do
23
+ assert_equal true, find_value(31, :bit)
24
+ assert_equal false, find_value(32, :bit)
25
+ assert_nil find_value(21, :bit)
26
+ end
27
+
28
+ it "casts char" do
29
+ partial_char = "12345678 "
30
+ assert_equal "1234567890", find_value(41, :char_10)
31
+ assert_equal partial_char, find_value(42, :char_10)
32
+ assert_utf8_encoding find_value(42, :char_10)
33
+ end
34
+
35
+ it "casts datetime" do
36
+ # 1753-01-01T00:00:00.000
37
+ v = find_value 61, :datetime
38
+ assert_instance_of Time, v, "not in range of Time class"
39
+ assert_equal 1753, v.year
40
+ assert_equal 0o1, v.month
41
+ assert_equal 0o1, v.day
42
+ assert_equal 0, v.hour
43
+ assert_equal 0, v.min
44
+ assert_equal 0, v.sec
45
+ assert_equal 0, v.usec
46
+ # 9999-12-31T23:59:59.997
47
+ v = find_value 62, :datetime
48
+ assert_instance_of Time, v, "not in range of Time class"
49
+ assert_equal 9999, v.year
50
+ assert_equal 12, v.month
51
+ assert_equal 31, v.day
52
+ assert_equal 23, v.hour
53
+ assert_equal 59, v.min
54
+ assert_equal 59, v.sec
55
+ assert_equal 997000, v.usec
56
+ assert_equal utc_offset, find_value(62, :datetime, timezone: :local).utc_offset
57
+ assert_equal 0, find_value(62, :datetime, timezone: :utc).utc_offset
58
+ # 2010-01-01T12:34:56.123
59
+ v = find_value 63, :datetime
60
+ assert_instance_of Time, v, "in range of Time class"
61
+ assert_equal 2010, v.year
62
+ assert_equal 0o1, v.month
63
+ assert_equal 0o1, v.day
64
+ assert_equal 12, v.hour
65
+ assert_equal 34, v.min
66
+ assert_equal 56, v.sec
67
+ assert_equal 123000, v.usec
68
+ assert_equal utc_offset, find_value(63, :datetime, timezone: :local).utc_offset
69
+ assert_equal 0, find_value(63, :datetime, timezone: :utc).utc_offset
70
+ end
71
+
72
+ it "casts decimal" do
73
+ assert_instance_of BigDecimal, find_value(91, :decimal_9_2)
74
+ assert_equal BigDecimal("12345.01"), find_value(91, :decimal_9_2)
75
+ assert_equal BigDecimal("1234567.89"), find_value(92, :decimal_9_2)
76
+ assert_equal BigDecimal("0.0"), find_value(93, :decimal_16_4)
77
+ assert_equal BigDecimal("123456789012.3456"), find_value(94, :decimal_16_4)
78
+ end
79
+
80
+ it "casts float" do
81
+ assert_equal 123.00000001, find_value(101, :float)
82
+ assert_equal 0.0, find_value(102, :float)
83
+ assert_equal find_value(102, :float).object_id, find_value(102, :float).object_id, "use global zero float"
84
+ assert_equal 123.45, find_value(103, :float)
85
+ end
86
+
87
+ it "casts image" do
88
+ value = find_value(141, :image)
89
+ assert_equal @gif1px, value
90
+ assert_binary_encoding(value)
91
+ end
92
+
93
+ it "casts int" do
94
+ assert_equal(-2147483647, find_value(151, :int))
95
+ assert_equal 2147483646, find_value(152, :int)
96
+ end
97
+
98
+ it "casts money" do
99
+ assert_instance_of BigDecimal, find_value(161, :money)
100
+ assert_equal BigDecimal("4.20"), find_value(161, :money)
101
+ assert_equal BigDecimal("922337203685477.5806"), find_value(163, :money)
102
+ assert_equal BigDecimal("-922337203685477.5807"), find_value(162, :money)
103
+ end
104
+
105
+ it "casts nchar" do
106
+ assert_equal "1234567890", find_value(171, :nchar_10)
107
+ assert_equal "123456åå ", find_value(172, :nchar_10)
108
+ assert_equal "abc123 ", find_value(173, :nchar_10)
109
+ end
110
+
111
+ it "casts ntext" do
112
+ assert_equal "test ntext", find_value(181, :ntext)
113
+ assert_equal "test ntext åå", find_value(182, :ntext)
114
+ assert_utf8_encoding find_value(182, :ntext)
115
+ # If this test fails, try setting the "text size" in your freetds.conf. See: http://www.freetds.org/faq.html#textdata
116
+ large_value = "x" * 5000
117
+ large_value_id = @client.execute("INSERT INTO [datatypes] ([ntext]) VALUES (N'#{large_value}')").insert
118
+ assert_equal large_value, find_value(large_value_id, :ntext)
119
+ end
120
+
121
+ it "casts numeric" do
122
+ assert_instance_of BigDecimal, find_value(191, :numeric_18_0)
123
+ assert_equal BigDecimal("191"), find_value(191, :numeric_18_0)
124
+ assert_equal BigDecimal("123456789012345678"), find_value(192, :numeric_18_0)
125
+ assert_equal BigDecimal("12345678901234567890.01"), find_value(193, :numeric_36_2)
126
+ assert_equal BigDecimal("123.46"), find_value(194, :numeric_36_2)
127
+ end
128
+
129
+ it "casts nvarchar" do
130
+ assert_equal "test nvarchar_50", find_value(201, :nvarchar_50)
131
+ assert_equal "test nvarchar_50 åå", find_value(202, :nvarchar_50)
132
+ assert_utf8_encoding find_value(202, :nvarchar_50)
133
+ end
134
+
135
+ it "casts real" do
136
+ assert_in_delta 123.45, find_value(221, :real), 0.01
137
+ assert_equal 0.0, find_value(222, :real)
138
+ assert_equal find_value(222, :real).object_id, find_value(222, :real).object_id, "use global zero float"
139
+ assert_in_delta 0.00001, find_value(223, :real), 0.000001
140
+ end
141
+
142
+ it "casts smalldatetime" do
143
+ # 1901-01-01 15:45:00
144
+ v = find_value 231, :smalldatetime
145
+ assert_instance_of Time, v
146
+ assert_equal 1901, v.year
147
+ assert_equal 0o1, v.month
148
+ assert_equal 0o1, v.day
149
+ assert_equal 15, v.hour
150
+ assert_equal 45, v.min
151
+ assert_equal 0o0, v.sec
152
+ assert_equal Time.local(1901).utc_offset, find_value(231, :smalldatetime, timezone: :local).utc_offset
153
+ assert_equal 0, find_value(231, :smalldatetime, timezone: :utc).utc_offset
154
+ # 2078-06-05 04:20:00
155
+ v = find_value 232, :smalldatetime
156
+ assert_instance_of Time, v
157
+ assert_equal 2078, v.year
158
+ assert_equal 0o6, v.month
159
+ assert_equal 0o5, v.day
160
+ assert_equal 0o4, v.hour
161
+ assert_equal 20, v.min
162
+ assert_equal 0o0, v.sec
163
+ assert_equal Time.local(2078, 6).utc_offset, find_value(232, :smalldatetime, timezone: :local).utc_offset
164
+ assert_equal 0, find_value(232, :smalldatetime, timezone: :utc).utc_offset
165
+ end
166
+
167
+ it "casts smallint" do
168
+ assert_equal(-32767, find_value(241, :smallint))
169
+ assert_equal 32766, find_value(242, :smallint)
170
+ end
171
+
172
+ it "casts smallmoney" do
173
+ assert_instance_of BigDecimal, find_value(251, :smallmoney)
174
+ assert_equal BigDecimal("4.20"), find_value(251, :smallmoney)
175
+ assert_equal BigDecimal("-214748.3647"), find_value(252, :smallmoney)
176
+ assert_equal BigDecimal("214748.3646"), find_value(253, :smallmoney)
177
+ end
178
+
179
+ it "casts text" do
180
+ assert_equal "test text", find_value(271, :text)
181
+ assert_utf8_encoding find_value(271, :text)
182
+ end
183
+
184
+ it "casts tinyint" do
185
+ assert_equal 0, find_value(301, :tinyint)
186
+ assert_equal 255, find_value(302, :tinyint)
187
+ end
188
+
189
+ it "casts uniqueidentifier" do
190
+ assert_match %r|\w{8}-\w{4}-\w{4}-\w{4}-\w{12}|, find_value(311, :uniqueidentifier)
191
+ assert_utf8_encoding find_value(311, :uniqueidentifier)
192
+ end
193
+
194
+ it "casts varbinary" do
195
+ value = find_value(321, :varbinary_50)
196
+ assert_equal @gif1px, value
197
+ assert_binary_encoding(value)
198
+ end
199
+
200
+ it "casts varchar" do
201
+ assert_equal "test varchar_50", find_value(341, :varchar_50)
202
+ assert_utf8_encoding find_value(341, :varchar_50)
203
+ end
204
+
205
+ it "casts nvarchar(max)" do
206
+ assert_equal "test nvarchar_max", find_value(211, :nvarchar_max)
207
+ assert_equal "test nvarchar_max åå", find_value(212, :nvarchar_max)
208
+ assert_utf8_encoding find_value(212, :nvarchar_max)
209
+ end
210
+
211
+ it "casts varbinary(max)" do
212
+ value = find_value(331, :varbinary_max)
213
+ assert_equal @gif1px, value
214
+ assert_binary_encoding(value)
215
+ end
216
+
217
+ it "casts varchar(max)" do
218
+ value = find_value(351, :varchar_max)
219
+ assert_equal "test varchar_max", value
220
+ assert_utf8_encoding(value)
221
+ end
222
+
223
+ it "casts xml" do
224
+ value = find_value(361, :xml)
225
+ assert_equal "<foo><bar>batz</bar></foo>", value
226
+ assert_utf8_encoding(value)
227
+ end
228
+
229
+ it "casts date" do
230
+ # 0001-01-01
231
+ v = find_value 51, :date
232
+ if @client.tds_73?
233
+ assert_instance_of Date, v
234
+ assert_equal 1, v.year, "Year"
235
+ assert_equal 1, v.month, "Month"
236
+ assert_equal 1, v.day, "Day"
237
+ else
238
+ assert_equal "0001-01-01", v
239
+ end
240
+ # 9999-12-31
241
+ v = find_value 52, :date
242
+ if @client.tds_73?
243
+ assert_instance_of Date, v
244
+ assert_equal 9999, v.year, "Year"
245
+ assert_equal 12, v.month, "Month"
246
+ assert_equal 31, v.day, "Day"
247
+ else
248
+ assert_equal "9999-12-31", v
249
+ end
250
+ end
251
+
252
+ it "casts time" do
253
+ # 15:45:00.709714966
254
+ v = find_value 281, :time_2
255
+ if @client.tds_73?
256
+ assert_instance_of Time, v
257
+ assert_equal 1900, v.year, "Year"
258
+ assert_equal 1, v.month, "Month"
259
+ assert_equal 1, v.day, "Day"
260
+ assert_equal 15, v.hour, "Hour"
261
+ assert_equal 45, v.min, "Minute"
262
+ assert_equal 0, v.sec, "Second"
263
+ assert_equal 710000, v.usec, "Microseconds"
264
+ assert_equal 710000000, v.nsec, "Nanoseconds"
265
+ else
266
+ assert_equal "15:45:00.71", v
267
+ end
268
+ # 04:20:00.288321545
269
+ v = find_value 282, :time_2
270
+ if @client.tds_73?
271
+ assert_instance_of Time, v
272
+ assert_equal 1900, v.year, "Year"
273
+ assert_equal 1, v.month, "Month"
274
+ assert_equal 1, v.day, "Day"
275
+ assert_equal 4, v.hour, "Hour"
276
+ assert_equal 20, v.min, "Minute"
277
+ assert_equal 0, v.sec, "Second"
278
+ assert_equal 290000, v.usec, "Microseconds"
279
+ assert_equal 290000000, v.nsec, "Nanoseconds"
280
+ else
281
+ assert_equal "04:20:00.29", v
282
+ end
283
+ # 15:45:00.709714966
284
+ v = find_value 283, :time_7
285
+ if @client.tds_73?
286
+ assert_instance_of Time, v
287
+ assert_equal 1900, v.year, "Year"
288
+ assert_equal 1, v.month, "Month"
289
+ assert_equal 1, v.day, "Day"
290
+ assert_equal 15, v.hour, "Hour"
291
+ assert_equal 45, v.min, "Minute"
292
+ assert_equal 0, v.sec, "Second"
293
+ assert_equal 709715, v.usec, "Microseconds"
294
+ assert_equal 709715000, v.nsec, "Nanoseconds"
295
+ else
296
+ assert_equal "15:45:00.7097150", v
297
+ end
298
+ # 04:20:00.288321545
299
+ v = find_value 284, :time_7
300
+ if @client.tds_73?
301
+ assert_instance_of Time, v
302
+ assert_equal 1900, v.year, "Year"
303
+ assert_equal 1, v.month, "Month"
304
+ assert_equal 1, v.day, "Day"
305
+ assert_equal 4, v.hour, "Hour"
306
+ assert_equal 20, v.min, "Minute"
307
+ assert_equal 0, v.sec, "Second"
308
+ assert_equal 288321, v.usec, "Microseconds"
309
+ assert_equal 288321500, v.nsec, "Nanoseconds"
310
+ else
311
+ assert_equal "04:20:00.2883215", v
312
+ end
313
+ end
314
+
315
+ it "casts datetime2" do
316
+ # 0001-01-01 00:00:00.0000000
317
+ v = find_value 71, :datetime2_7
318
+ if @client.tds_73?
319
+ assert_instance_of Time, v
320
+ assert_equal 1, v.year, "Year"
321
+ assert_equal 1, v.month, "Month"
322
+ assert_equal 1, v.day, "Day"
323
+ assert_equal 0, v.hour, "Hour"
324
+ assert_equal 0, v.min, "Minute"
325
+ assert_equal 0, v.sec, "Second"
326
+ assert_equal 0, v.usec, "Microseconds"
327
+ assert_equal 0, v.nsec, "Nanoseconds"
328
+ else
329
+ assert_equal "0001-01-01 00:00:00.0000000", v
330
+ end
331
+ # 1984-01-24 04:20:00.0000000
332
+ v = find_value 72, :datetime2_7
333
+ if @client.tds_73?
334
+ assert_instance_of Time, v
335
+ assert_equal 1984, v.year, "Year"
336
+ assert_equal 1, v.month, "Month"
337
+ assert_equal 24, v.day, "Day"
338
+ assert_equal 4, v.hour, "Hour"
339
+ assert_equal 20, v.min, "Minute"
340
+ assert_equal 0, v.sec, "Second"
341
+ assert_equal 0, v.usec, "Microseconds"
342
+ assert_equal 0, v.nsec, "Nanoseconds"
343
+ else
344
+ assert_equal "1984-01-24 04:20:00.0000000", v
345
+ end
346
+ # 9999-12-31 23:59:59.9999999
347
+ v = find_value 73, :datetime2_7
348
+ if @client.tds_73?
349
+ assert_instance_of Time, v
350
+ assert_equal 9999, v.year, "Year"
351
+ assert_equal 12, v.month, "Month"
352
+ assert_equal 31, v.day, "Day"
353
+ assert_equal 23, v.hour, "Hour"
354
+ assert_equal 59, v.min, "Minute"
355
+ assert_equal 59, v.sec, "Second"
356
+ assert_equal 999999, v.usec, "Microseconds"
357
+ assert_equal 999999900, v.nsec, "Nanoseconds"
358
+ else
359
+ assert_equal "9999-12-31 23:59:59.9999999", v
360
+ end
361
+ # 9999-12-31 23:59:59.123456789
362
+ v = find_value 74, :datetime2_2
363
+ if @client.tds_73?
364
+ assert_instance_of Time, v
365
+ assert_equal 9999, v.year, "Year"
366
+ assert_equal 12, v.month, "Month"
367
+ assert_equal 31, v.day, "Day"
368
+ assert_equal 23, v.hour, "Hour"
369
+ assert_equal 59, v.min, "Minute"
370
+ assert_equal 59, v.sec, "Second"
371
+ assert_equal 120000, v.usec, "Microseconds"
372
+ assert_equal 120000000, v.nsec, "Nanoseconds"
373
+ else
374
+ assert_equal "9999-12-31 23:59:59.12", v
375
+ end
376
+ end
377
+
378
+ it "casts datetimeoffset" do
379
+ # 1984-01-24T04:20:00.1234567-08:00
380
+ v = find_value 84, :datetimeoffset_7
381
+ if @client.tds_73?
382
+ assertions = lambda {
383
+ assert_instance_of Time, v
384
+ assert_equal 1984, v.year, "Year"
385
+ assert_equal 1, v.month, "Month"
386
+ assert_equal 24, v.day, "Day"
387
+ assert_equal 4, v.hour, "Hour"
388
+ assert_equal 20, v.min, "Minute"
389
+ assert_equal 59, v.sec, "Second"
390
+ assert_equal 123456, v.usec, "Microseconds"
391
+ assert_equal 123456700, v.nsec, "Nanoseconds"
392
+ assert_equal(-28800, v.utc_offset, "Offset")
393
+ }
394
+ assertions.call
395
+ v = find_value 84, :datetimeoffset_7, timezone: :local
396
+ assertions.call # Ignores timezone query option.
397
+ else
398
+ assert_equal "1984-01-24 04:20:59.1234567 -08:00", v
399
+ end
400
+ end
401
+
402
+ # it 'casts geography' do
403
+ # value = find_value 111, :geography
404
+ # assert_equal '', value
405
+ # end
406
+ #
407
+ # it 'casts geometry' do
408
+ # value = find_value 121, :geometry
409
+ # assert_equal '', value
410
+ # end
411
+ #
412
+ # it 'casts hierarchyid' do
413
+ # value = find_value 131, :hierarchyid
414
+ # assert_equal '', value
415
+ # end
416
+ end
417
+ end
@@ -0,0 +1,18 @@
1
+ :ON ERROR EXIT
2
+
3
+ PRINT 'RUNNING DB-CREATE.SQL, CREATING TINYTDS TEST DATABASE';
4
+ IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'tinytdstest')
5
+ BEGIN
6
+ CREATE DATABASE [tinytdstest];
7
+ END
8
+ GO
9
+
10
+ IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name LIKE 'tinytdstest')
11
+ BEGIN
12
+ PRINT 'TINY TDS TEST DB SUCCESSFULY CREATED';
13
+ END
14
+ ELSE
15
+ BEGIN
16
+ THROW 51000, 'TINY TDS TEST DB CREATION FAILED', 1;
17
+ END
18
+ GO
@@ -0,0 +1,38 @@
1
+ :ON ERROR EXIT
2
+
3
+ PRINT 'RUNNING DB-LOGIN.SQL';
4
+
5
+ PRINT 'CREATING TINYTDS TEST LOGIN';
6
+ IF NOT EXISTS (select name from sys.server_principals where name like 'tinytds')
7
+ BEGIN
8
+ CREATE LOGIN [tinytds] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [tinytdstest];
9
+ END
10
+ GO
11
+
12
+ IF EXISTS (select name from sys.server_principals where name like 'tinytds')
13
+ BEGIN
14
+ PRINT 'TINY TDS TEST LOGIN SUCCESSFULY CREATED';
15
+ END
16
+ ELSE
17
+ BEGIN
18
+ THROW 51000, 'TINY TDS TEST LOGIN CREATION FAILED', 1;
19
+ END
20
+ GO
21
+
22
+ USE [tinytdstest];
23
+ IF NOT EXISTS (select name from sys.database_principals where name LIKE 'tinytds')
24
+ BEGIN
25
+ CREATE USER [tinytds] FOR LOGIN [tinytds];
26
+ EXEC sp_addrolemember N'db_owner', N'tinytds';
27
+ END
28
+ GO
29
+
30
+ IF EXISTS (select name from sys.database_principals where name LIKE 'tinytds')
31
+ BEGIN
32
+ PRINT 'TINY TDS TEST USER SUCCESSFULY CREATED';
33
+ END
34
+ ELSE
35
+ BEGIN
36
+ THROW 51000, 'TINY TDS TEST USER CREATION FAILED', 1;
37
+ END
38
+ GO