|
6 | 6 | @result = @client.query "SELECT 1"
|
7 | 7 | end
|
8 | 8 |
|
9 |
| - it "should maintain a count while streaming" do |
10 |
| - result = @client.query('SELECT 1') |
11 |
| - |
12 |
| - result.count.should eql(1) |
13 |
| - result.each.to_a |
14 |
| - result.count.should eql(1) |
15 |
| - end |
16 |
| - |
17 |
| - it "should set the actual count of rows after streaming" do |
18 |
| - @client.query "USE test" |
19 |
| - result = @client.query("SELECT * FROM mysql2_test", :stream => true, :cache_rows => false) |
20 |
| - result.count.should eql(0) |
21 |
| - result.each {|r| } |
22 |
| - result.count.should eql(1) |
23 |
| - end |
24 |
| - |
25 |
| - it "should not yield nil at the end of streaming" do |
26 |
| - result = @client.query('SELECT * FROM mysql2_test', :stream => true) |
27 |
| - result.each { |r| r.should_not be_nil} |
28 |
| - end |
29 |
| - |
30 |
| - it "#count should be zero for rows after streaming when there were no results " do |
31 |
| - @client.query "USE test" |
32 |
| - result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false) |
33 |
| - result.count.should eql(0) |
34 |
| - result.each.to_a |
35 |
| - result.count.should eql(0) |
36 |
| - end |
37 |
| - |
38 | 9 | it "should have included Enumerable" do
|
39 | 10 | Mysql2::Result.ancestors.include?(Enumerable).should be_true
|
40 | 11 | end
|
|
121 | 92 |
|
122 | 93 | context "#fields" do
|
123 | 94 | before(:each) do
|
124 |
| - @client.query "USE test" |
125 | 95 | @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1")
|
126 | 96 | end
|
127 | 97 |
|
|
135 | 105 | end
|
136 | 106 | end
|
137 | 107 |
|
| 108 | + context "streaming" do |
| 109 | + it "should maintain a count while streaming" do |
| 110 | + result = @client.query('SELECT 1') |
| 111 | + |
| 112 | + result.count.should eql(1) |
| 113 | + result.each.to_a |
| 114 | + result.count.should eql(1) |
| 115 | + end |
| 116 | + |
| 117 | + it "should set the actual count of rows after streaming" do |
| 118 | + result = @client.query("SELECT * FROM mysql2_test", :stream => true, :cache_rows => false) |
| 119 | + result.count.should eql(0) |
| 120 | + result.each {|r| } |
| 121 | + result.count.should eql(1) |
| 122 | + end |
| 123 | + |
| 124 | + it "should not yield nil at the end of streaming" do |
| 125 | + result = @client.query('SELECT * FROM mysql2_test', :stream => true, :cache_rows => false) |
| 126 | + result.each { |r| r.should_not be_nil} |
| 127 | + end |
| 128 | + |
| 129 | + it "#count should be zero for rows after streaming when there were no results" do |
| 130 | + result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false) |
| 131 | + result.count.should eql(0) |
| 132 | + result.each.to_a |
| 133 | + result.count.should eql(0) |
| 134 | + end |
| 135 | + |
| 136 | + it "should raise an exception if streaming ended due to a timeout" do |
| 137 | + # Create an extra client instance, since we're going to time it out |
| 138 | + client = Mysql2::Client.new DatabaseCredentials['root'] |
| 139 | + client.query "CREATE TEMPORARY TABLE streamingTest (val BINARY(255))" |
| 140 | + |
| 141 | + # Insert enough records to force the result set into multiple reads |
| 142 | + # (the BINARY type is used simply because it forces full width results) |
| 143 | + 10000.times do |i| |
| 144 | + client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')" |
| 145 | + end |
| 146 | + |
| 147 | + client.query "SET net_write_timeout = 1" |
| 148 | + res = client.query "SELECT * FROM streamingTest", :stream => true, :cache_rows => false |
| 149 | + |
| 150 | + lambda { |
| 151 | + res.each_with_index do |row, i| |
| 152 | + # Exhaust the first result packet then trigger a timeout |
| 153 | + sleep 2 if i > 0 && i % 1000 == 0 |
| 154 | + end |
| 155 | + }.should raise_error(Mysql2::Error, /Lost connection/) |
| 156 | + end |
| 157 | + end |
| 158 | + |
138 | 159 | context "row data type mapping" do
|
139 | 160 | before(:each) do
|
140 |
| - @client.query "USE test" |
141 | 161 | @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
142 | 162 | end
|
143 | 163 |
|
|
323 | 343 | result['enum_test'].encoding.should eql(Encoding.find('utf-8'))
|
324 | 344 |
|
325 | 345 | client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
|
326 |
| - client2.query "USE test" |
327 | 346 | result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
328 | 347 | result['enum_test'].encoding.should eql(Encoding.find('us-ascii'))
|
329 | 348 | client2.close
|
|
353 | 372 | result['set_test'].encoding.should eql(Encoding.find('utf-8'))
|
354 | 373 |
|
355 | 374 | client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
|
356 |
| - client2.query "USE test" |
357 | 375 | result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
358 | 376 | result['set_test'].encoding.should eql(Encoding.find('us-ascii'))
|
359 | 377 | client2.close
|
|
436 | 454 | result[field].encoding.should eql(Encoding.find('utf-8'))
|
437 | 455 |
|
438 | 456 | client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
|
439 |
| - client2.query "USE test" |
440 | 457 | result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
441 | 458 | result[field].encoding.should eql(Encoding.find('us-ascii'))
|
442 | 459 | client2.close
|
|
0 commit comments