mysql2 0.3.20 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,83 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mysql2::Error do
6
- let(:client) { Mysql2::Client.new(DatabaseCredentials['root']) }
7
-
8
- let :error do
9
- begin
10
- client.query("HAHAHA")
11
- rescue Mysql2::Error => e
12
- error = e
13
- ensure
14
- client.close
15
- end
16
-
17
- error
18
- end
19
-
20
- it "responds to error_number and sql_state, with aliases" do
21
- error.should respond_to(:error_number)
22
- error.should respond_to(:sql_state)
23
-
24
- # Mysql gem compatibility
25
- error.should respond_to(:errno)
26
- error.should respond_to(:error)
27
- end
28
-
29
- if "".respond_to? :encoding
30
- let :error do
31
- client = Mysql2::Client.new(DatabaseCredentials['root'])
32
- begin
33
- client.query("\xE9\x80\xA0\xE5\xAD\x97")
34
- rescue Mysql2::Error => e
35
- error = e
36
- ensure
37
- client.close
38
- end
39
-
40
- error
41
- end
42
-
43
- let :bad_err do
44
- client = Mysql2::Client.new(DatabaseCredentials['root'])
45
- begin
46
- client.query("\xE5\xC6\x7D\x1F")
47
- rescue Mysql2::Error => e
48
- error = e
49
- ensure
50
- client.close
51
- end
52
-
53
- error
54
- end
55
-
56
- it "returns error messages as UTF-8 by default" do
57
- with_internal_encoding nil do
58
- error.message.encoding.should eql(Encoding::UTF_8)
59
- error.message.valid_encoding?
60
-
61
- bad_err.message.encoding.should eql(Encoding::UTF_8)
62
- bad_err.message.valid_encoding?
63
-
64
- bad_err.message.should include("??}\u001F")
65
- end
66
- end
67
-
68
- it "returns sql state as ASCII" do
69
- error.sql_state.encoding.should eql(Encoding::US_ASCII)
70
- error.sql_state.valid_encoding?
71
- end
72
-
73
- it "returns error messages and sql state in Encoding.default_internal if set" do
74
- with_internal_encoding 'UTF-16LE' do
75
- error.message.encoding.should eql(Encoding.default_internal)
76
- error.message.valid_encoding?
77
-
78
- bad_err.message.encoding.should eql(Encoding.default_internal)
79
- bad_err.message.valid_encoding?
80
- end
81
- end
82
- end
83
- end
@@ -1,514 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- describe Mysql2::Result do
5
- before(:each) do
6
- @result = @client.query "SELECT 1"
7
- end
8
-
9
- it "should raise a TypeError exception when it doesn't wrap a result set" do
10
- r = Mysql2::Result.new
11
- expect { r.count }.to raise_error(TypeError)
12
- expect { r.fields }.to raise_error(TypeError)
13
- expect { r.size }.to raise_error(TypeError)
14
- expect { r.each }.to raise_error(TypeError)
15
- end
16
-
17
- it "should have included Enumerable" do
18
- Mysql2::Result.ancestors.include?(Enumerable).should be_true
19
- end
20
-
21
- it "should respond to #each" do
22
- @result.should respond_to(:each)
23
- end
24
-
25
- it "should raise a Mysql2::Error exception upon a bad query" do
26
- lambda {
27
- @client.query "bad sql"
28
- }.should raise_error(Mysql2::Error)
29
-
30
- lambda {
31
- @client.query "SELECT 1"
32
- }.should_not raise_error(Mysql2::Error)
33
- end
34
-
35
- it "should respond to #count, which is aliased as #size" do
36
- r = @client.query "SELECT 1"
37
- r.should respond_to :count
38
- r.should respond_to :size
39
- end
40
-
41
- it "should be able to return the number of rows in the result set" do
42
- r = @client.query "SELECT 1"
43
- r.count.should eql(1)
44
- r.size.should eql(1)
45
- end
46
-
47
- context "metadata queries" do
48
- it "should show tables" do
49
- @result = @client.query "SHOW TABLES"
50
- end
51
- end
52
-
53
- context "#each" do
54
- it "should yield rows as hash's" do
55
- @result.each do |row|
56
- row.class.should eql(Hash)
57
- end
58
- end
59
-
60
- it "should yield rows as hash's with symbol keys if :symbolize_keys was set to true" do
61
- @result.each(:symbolize_keys => true) do |row|
62
- row.keys.first.class.should eql(Symbol)
63
- end
64
- end
65
-
66
- it "should be able to return results as an array" do
67
- @result.each(:as => :array) do |row|
68
- row.class.should eql(Array)
69
- end
70
- end
71
-
72
- it "should cache previously yielded results by default" do
73
- @result.first.object_id.should eql(@result.first.object_id)
74
- end
75
-
76
- it "should not cache previously yielded results if cache_rows is disabled" do
77
- result = @client.query "SELECT 1", :cache_rows => false
78
- result.first.object_id.should_not eql(result.first.object_id)
79
- end
80
-
81
- it "should yield different value for #first if streaming" do
82
- result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
83
- result.first.should_not eql(result.first)
84
- end
85
-
86
- it "should yield the same value for #first if streaming is disabled" do
87
- result = @client.query "SELECT 1 UNION SELECT 2", :stream => false
88
- result.first.should eql(result.first)
89
- end
90
-
91
- it "should throw an exception if we try to iterate twice when streaming is enabled" do
92
- result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
93
-
94
- expect {
95
- result.each.to_a
96
- result.each.to_a
97
- }.to raise_exception(Mysql2::Error)
98
- end
99
- end
100
-
101
- context "#fields" do
102
- before(:each) do
103
- @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1")
104
- end
105
-
106
- it "method should exist" do
107
- @test_result.should respond_to(:fields)
108
- end
109
-
110
- it "should return an array of field names in proper order" do
111
- result = @client.query "SELECT 'a', 'b', 'c'"
112
- result.fields.should eql(['a', 'b', 'c'])
113
- end
114
- end
115
-
116
- context "streaming" do
117
- it "should maintain a count while streaming" do
118
- result = @client.query('SELECT 1', :stream => true, :cache_rows => false)
119
- result.count.should eql(0)
120
- result.each.to_a
121
- result.count.should eql(1)
122
- end
123
-
124
- it "should retain the count when mixing first and each" do
125
- result = @client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false)
126
- result.count.should eql(0)
127
- result.first
128
- result.count.should eql(1)
129
- result.each.to_a
130
- result.count.should eql(2)
131
- end
132
-
133
- it "should not yield nil at the end of streaming" do
134
- result = @client.query('SELECT * FROM mysql2_test', :stream => true, :cache_rows => false)
135
- result.each { |r| r.should_not be_nil}
136
- end
137
-
138
- it "#count should be zero for rows after streaming when there were no results" do
139
- result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false)
140
- result.count.should eql(0)
141
- result.each.to_a
142
- result.count.should eql(0)
143
- end
144
-
145
- it "should raise an exception if streaming ended due to a timeout" do
146
- # Create an extra client instance, since we're going to time it out
147
- client = Mysql2::Client.new DatabaseCredentials['root']
148
- client.query "CREATE TEMPORARY TABLE streamingTest (val BINARY(255)) ENGINE=MEMORY"
149
-
150
- # Insert enough records to force the result set into multiple reads
151
- # (the BINARY type is used simply because it forces full width results)
152
- 10000.times do |i|
153
- client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')"
154
- end
155
-
156
- client.query "SET net_write_timeout = 1"
157
- res = client.query "SELECT * FROM streamingTest", :stream => true, :cache_rows => false
158
-
159
- lambda {
160
- res.each_with_index do |row, i|
161
- # Exhaust the first result packet then trigger a timeout
162
- sleep 2 if i > 0 && i % 1000 == 0
163
- end
164
- }.should raise_error(Mysql2::Error, /Lost connection/)
165
- end
166
- end
167
-
168
- context "row data type mapping" do
169
- before(:each) do
170
- @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
171
- end
172
-
173
- it "should return nil values for NULL and strings for everything else when :cast is false" do
174
- result = @client.query('SELECT null_test, tiny_int_test, bool_cast_test, int_test, date_test, enum_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast => false).first
175
- result["null_test"].should be_nil
176
- result["tiny_int_test"].should eql("1")
177
- result["bool_cast_test"].should eql("1")
178
- result["int_test"].should eql("10")
179
- result["date_test"].should eql("2010-04-04")
180
- result["enum_test"].should eql("val1")
181
- end
182
-
183
- it "should return nil for a NULL value" do
184
- @test_result['null_test'].class.should eql(NilClass)
185
- @test_result['null_test'].should eql(nil)
186
- end
187
-
188
- it "should return String for a BIT(64) value" do
189
- @test_result['bit_test'].class.should eql(String)
190
- @test_result['bit_test'].should eql("\000\000\000\000\000\000\000\005")
191
- end
192
-
193
- it "should return String for a BIT(1) value" do
194
- @test_result['single_bit_test'].class.should eql(String)
195
- @test_result['single_bit_test'].should eql("\001")
196
- end
197
-
198
- it "should return Fixnum for a TINYINT value" do
199
- [Fixnum, Bignum].should include(@test_result['tiny_int_test'].class)
200
- @test_result['tiny_int_test'].should eql(1)
201
- end
202
-
203
- it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
204
- @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (1)'
205
- id1 = @client.last_id
206
- @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (0)'
207
- id2 = @client.last_id
208
- @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'
209
- id3 = @client.last_id
210
-
211
- result1 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast_booleans => true
212
- result2 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1', :cast_booleans => true
213
- result3 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = -1 LIMIT 1', :cast_booleans => true
214
- result1.first['bool_cast_test'].should be_true
215
- result2.first['bool_cast_test'].should be_false
216
- result3.first['bool_cast_test'].should be_true
217
-
218
- @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
219
- end
220
-
221
- it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
222
- @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'
223
- id1 = @client.last_id
224
- @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'
225
- id2 = @client.last_id
226
-
227
- result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", :cast_booleans => true
228
- result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", :cast_booleans => true
229
- result1.first['single_bit_test'].should be_true
230
- result2.first['single_bit_test'].should be_false
231
-
232
- @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
233
- end
234
-
235
- it "should return Fixnum for a SMALLINT value" do
236
- [Fixnum, Bignum].should include(@test_result['small_int_test'].class)
237
- @test_result['small_int_test'].should eql(10)
238
- end
239
-
240
- it "should return Fixnum for a MEDIUMINT value" do
241
- [Fixnum, Bignum].should include(@test_result['medium_int_test'].class)
242
- @test_result['medium_int_test'].should eql(10)
243
- end
244
-
245
- it "should return Fixnum for an INT value" do
246
- [Fixnum, Bignum].should include(@test_result['int_test'].class)
247
- @test_result['int_test'].should eql(10)
248
- end
249
-
250
- it "should return Fixnum for a BIGINT value" do
251
- [Fixnum, Bignum].should include(@test_result['big_int_test'].class)
252
- @test_result['big_int_test'].should eql(10)
253
- end
254
-
255
- it "should return Fixnum for a YEAR value" do
256
- [Fixnum, Bignum].should include(@test_result['year_test'].class)
257
- @test_result['year_test'].should eql(2009)
258
- end
259
-
260
- it "should return BigDecimal for a DECIMAL value" do
261
- @test_result['decimal_test'].class.should eql(BigDecimal)
262
- @test_result['decimal_test'].should eql(10.3)
263
- end
264
-
265
- it "should return Float for a FLOAT value" do
266
- @test_result['float_test'].class.should eql(Float)
267
- @test_result['float_test'].should eql(10.3)
268
- end
269
-
270
- it "should return Float for a DOUBLE value" do
271
- @test_result['double_test'].class.should eql(Float)
272
- @test_result['double_test'].should eql(10.3)
273
- end
274
-
275
- it "should return Time for a DATETIME value when within the supported range" do
276
- @test_result['date_time_test'].class.should eql(Time)
277
- @test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2010-04-04 11:44:00')
278
- end
279
-
280
- if 1.size == 4 # 32bit
281
- unless RUBY_VERSION =~ /1.8/
282
- klass = Time
283
- else
284
- klass = DateTime
285
- end
286
-
287
- it "should return DateTime when timestamp is < 1901-12-13 20:45:52" do
288
- # 1901-12-13T20:45:52 is the min for 32bit Ruby 1.8
289
- r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
290
- r.first['test'].class.should eql(klass)
291
- end
292
-
293
- it "should return DateTime when timestamp is > 2038-01-19T03:14:07" do
294
- # 2038-01-19T03:14:07 is the max for 32bit Ruby 1.8
295
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
296
- r.first['test'].class.should eql(klass)
297
- end
298
- elsif 1.size == 8 # 64bit
299
- unless RUBY_VERSION =~ /1.8/
300
- it "should return Time when timestamp is < 1901-12-13 20:45:52" do
301
- r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
302
- r.first['test'].class.should eql(Time)
303
- end
304
-
305
- it "should return Time when timestamp is > 2038-01-19T03:14:07" do
306
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
307
- r.first['test'].class.should eql(Time)
308
- end
309
- else
310
- it "should return Time when timestamp is > 0138-12-31 11:59:59" do
311
- r = @client.query("SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test")
312
- r.first['test'].class.should eql(Time)
313
- end
314
-
315
- it "should return DateTime when timestamp is < 0139-1-1T00:00:00" do
316
- r = @client.query("SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test")
317
- r.first['test'].class.should eql(DateTime)
318
- end
319
-
320
- it "should return Time when timestamp is > 2038-01-19T03:14:07" do
321
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
322
- r.first['test'].class.should eql(Time)
323
- end
324
- end
325
- end
326
-
327
- it "should return Time for a TIMESTAMP value when within the supported range" do
328
- @test_result['timestamp_test'].class.should eql(Time)
329
- @test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2010-04-04 11:44:00')
330
- end
331
-
332
- it "should return Time for a TIME value" do
333
- @test_result['time_test'].class.should eql(Time)
334
- @test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2000-01-01 11:44:00')
335
- end
336
-
337
- it "should return Date for a DATE value" do
338
- @test_result['date_test'].class.should eql(Date)
339
- @test_result['date_test'].strftime("%Y-%m-%d").should eql('2010-04-04')
340
- end
341
-
342
- it "should return String for an ENUM value" do
343
- @test_result['enum_test'].class.should eql(String)
344
- @test_result['enum_test'].should eql('val1')
345
- end
346
-
347
- it "should raise an error given an invalid DATETIME" do
348
- begin
349
- @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each
350
- rescue Mysql2::Error => e
351
- error = e
352
- end
353
-
354
- error.message.should eql("Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
355
- end
356
-
357
- if defined? Encoding
358
- context "string encoding for ENUM values" do
359
- it "should default to the connection's encoding if Encoding.default_internal is nil" do
360
- with_internal_encoding nil do
361
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
362
- result['enum_test'].encoding.should eql(Encoding.find('utf-8'))
363
-
364
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
365
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
366
- result['enum_test'].encoding.should eql(Encoding.find('us-ascii'))
367
- client2.close
368
- end
369
- end
370
-
371
- it "should use Encoding.default_internal" do
372
- with_internal_encoding 'utf-8' do
373
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
374
- result['enum_test'].encoding.should eql(Encoding.default_internal)
375
- end
376
-
377
- with_internal_encoding 'us-ascii' do
378
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
379
- result['enum_test'].encoding.should eql(Encoding.default_internal)
380
- end
381
- end
382
- end
383
- end
384
-
385
- it "should return String for a SET value" do
386
- @test_result['set_test'].class.should eql(String)
387
- @test_result['set_test'].should eql('val1,val2')
388
- end
389
-
390
- if defined? Encoding
391
- context "string encoding for SET values" do
392
- it "should default to the connection's encoding if Encoding.default_internal is nil" do
393
- with_internal_encoding nil do
394
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
395
- result['set_test'].encoding.should eql(Encoding.find('utf-8'))
396
-
397
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
398
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
399
- result['set_test'].encoding.should eql(Encoding.find('us-ascii'))
400
- client2.close
401
- end
402
- end
403
-
404
- it "should use Encoding.default_internal" do
405
- with_internal_encoding 'utf-8' do
406
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
407
- result['set_test'].encoding.should eql(Encoding.default_internal)
408
- end
409
-
410
- with_internal_encoding 'us-ascii' do
411
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
412
- result['set_test'].encoding.should eql(Encoding.default_internal)
413
- end
414
- end
415
- end
416
- end
417
-
418
- it "should return String for a BINARY value" do
419
- @test_result['binary_test'].class.should eql(String)
420
- @test_result['binary_test'].should eql("test#{"\000"*6}")
421
- end
422
-
423
- if defined? Encoding
424
- context "string encoding for BINARY values" do
425
- it "should default to binary if Encoding.default_internal is nil" do
426
- with_internal_encoding nil do
427
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
428
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
429
- end
430
- end
431
-
432
- it "should not use Encoding.default_internal" do
433
- with_internal_encoding 'utf-8' do
434
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
435
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
436
- end
437
-
438
- with_internal_encoding 'us-ascii' do
439
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
440
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
441
- end
442
- end
443
- end
444
- end
445
-
446
- {
447
- 'char_test' => 'CHAR',
448
- 'varchar_test' => 'VARCHAR',
449
- 'varbinary_test' => 'VARBINARY',
450
- 'tiny_blob_test' => 'TINYBLOB',
451
- 'tiny_text_test' => 'TINYTEXT',
452
- 'blob_test' => 'BLOB',
453
- 'text_test' => 'TEXT',
454
- 'medium_blob_test' => 'MEDIUMBLOB',
455
- 'medium_text_test' => 'MEDIUMTEXT',
456
- 'long_blob_test' => 'LONGBLOB',
457
- 'long_text_test' => 'LONGTEXT'
458
- }.each do |field, type|
459
- it "should return a String for #{type}" do
460
- @test_result[field].class.should eql(String)
461
- @test_result[field].should eql("test")
462
- end
463
-
464
- if defined? Encoding
465
- context "string encoding for #{type} values" do
466
- if ['VARBINARY', 'TINYBLOB', 'BLOB', 'MEDIUMBLOB', 'LONGBLOB'].include?(type)
467
- it "should default to binary if Encoding.default_internal is nil" do
468
- with_internal_encoding nil do
469
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
470
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
471
- end
472
- end
473
-
474
- it "should not use Encoding.default_internal" do
475
- with_internal_encoding 'utf-8' do
476
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
477
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
478
- end
479
-
480
- with_internal_encoding 'us-ascii' do
481
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
482
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
483
- end
484
- end
485
- else
486
- it "should default to utf-8 if Encoding.default_internal is nil" do
487
- with_internal_encoding nil do
488
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
489
- result[field].encoding.should eql(Encoding.find('utf-8'))
490
-
491
- client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
492
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
493
- result[field].encoding.should eql(Encoding.find('us-ascii'))
494
- client2.close
495
- end
496
- end
497
-
498
- it "should use Encoding.default_internal" do
499
- with_internal_encoding 'utf-8' do
500
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
501
- result[field].encoding.should eql(Encoding.default_internal)
502
- end
503
-
504
- with_internal_encoding 'us-ascii' do
505
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
506
- result[field].encoding.should eql(Encoding.default_internal)
507
- end
508
- end
509
- end
510
- end
511
- end
512
- end
513
- end
514
- end
data/spec/rcov.opts DELETED
@@ -1,3 +0,0 @@
1
- --exclude spec,gem
2
- --text-summary
3
- --sort coverage --sort-reverse
data/spec/spec_helper.rb DELETED
@@ -1,87 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'rspec'
4
- require 'mysql2'
5
- require 'timeout'
6
- require 'yaml'
7
- DatabaseCredentials = YAML.load_file('spec/configuration.yml')
8
-
9
- RSpec.configure do |config|
10
- def with_internal_encoding(encoding)
11
- old_enc = Encoding.default_internal
12
- Encoding.default_internal = encoding
13
-
14
- yield
15
- ensure
16
- Encoding.default_internal = old_enc
17
- end
18
-
19
- config.before :each do
20
- @client = Mysql2::Client.new DatabaseCredentials['root']
21
- end
22
-
23
- config.after :each do
24
- @client.close
25
- end
26
-
27
- config.before(:all) do
28
- client = Mysql2::Client.new DatabaseCredentials['root']
29
- client.query %[
30
- CREATE TABLE IF NOT EXISTS mysql2_test (
31
- id MEDIUMINT NOT NULL AUTO_INCREMENT,
32
- null_test VARCHAR(10),
33
- bit_test BIT(64),
34
- single_bit_test BIT(1),
35
- tiny_int_test TINYINT,
36
- bool_cast_test TINYINT(1),
37
- small_int_test SMALLINT,
38
- medium_int_test MEDIUMINT,
39
- int_test INT,
40
- big_int_test BIGINT,
41
- float_test FLOAT(10,3),
42
- float_zero_test FLOAT(10,3),
43
- double_test DOUBLE(10,3),
44
- decimal_test DECIMAL(10,3),
45
- decimal_zero_test DECIMAL(10,3),
46
- date_test DATE,
47
- date_time_test DATETIME,
48
- timestamp_test TIMESTAMP,
49
- time_test TIME,
50
- year_test YEAR(4),
51
- char_test CHAR(10),
52
- varchar_test VARCHAR(10),
53
- binary_test BINARY(10),
54
- varbinary_test VARBINARY(10),
55
- tiny_blob_test TINYBLOB,
56
- tiny_text_test TINYTEXT,
57
- blob_test BLOB,
58
- text_test TEXT,
59
- medium_blob_test MEDIUMBLOB,
60
- medium_text_test MEDIUMTEXT,
61
- long_blob_test LONGBLOB,
62
- long_text_test LONGTEXT,
63
- enum_test ENUM('val1', 'val2'),
64
- set_test SET('val1', 'val2'),
65
- PRIMARY KEY (id)
66
- )
67
- ]
68
- client.query "DELETE FROM mysql2_test;"
69
- client.query %[
70
- INSERT INTO mysql2_test (
71
- null_test, bit_test, single_bit_test, tiny_int_test, bool_cast_test, small_int_test, medium_int_test, int_test, big_int_test,
72
- float_test, float_zero_test, double_test, decimal_test, decimal_zero_test, date_test, date_time_test, timestamp_test, time_test,
73
- year_test, char_test, varchar_test, binary_test, varbinary_test, tiny_blob_test,
74
- tiny_text_test, blob_test, text_test, medium_blob_test, medium_text_test,
75
- long_blob_test, long_text_test, enum_test, set_test
76
- )
77
-
78
- VALUES (
79
- NULL, b'101', b'1', 1, 1, 10, 10, 10, 10,
80
- 10.3, 0, 10.3, 10.3, 0, '2010-4-4', '2010-4-4 11:44:00', '2010-4-4 11:44:00', '11:44:00',
81
- 2009, "test", "test", "test", "test", "test",
82
- "test", "test", "test", "test", "test",
83
- "test", "test", 'val1', 'val1,val2'
84
- )
85
- ]
86
- end
87
- end
data/spec/test_data DELETED
@@ -1 +0,0 @@
1
- \N Hello World