mysql2 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a4ccc20c41020f497f28c56fe825ca41349ee9c
4
- data.tar.gz: 7ea3444599e0c9d8b0efb610d9b7fa408aa355c7
3
+ metadata.gz: 03a4d85f4672425142825728e8c69d84f4f898af
4
+ data.tar.gz: 3c78c54532a405a2e05b85692dd18f219729c46c
5
5
  SHA512:
6
- metadata.gz: 3dc8dd2dfa209530b8793abf02476682d01cdbe44d6a847421b90fdaf38150a1ac33a7f9ba1db1df07398e22bfdfb27e1ad23aa2d0f4e1640a9169b3db683321
7
- data.tar.gz: 107cc184c12df06949fa54851673c96c977ced271383f52e03b1bb714dab7a06c0211a0110202a9f397703f3d55bb70d2c7420a537b286c5fa5ba890be9dc578
6
+ metadata.gz: 94cc9c40b48e34c8831315eff9d80ae043569d5a69708ca157f976b9cba75a7c7672a3f12300a3312a02a24b87a1b81185216792fd1fe9968f92446c6f33eed5
7
+ data.tar.gz: 2092fd9e8cb83c053bd2b0b89e09fa1f872a535de01dd2f1927bcd3eaced860764ff3e8793d1d971cc9eeb08a4d504a3d3c4da7cf7ab67fa21f0bcc84bc21a3c
data/README.md CHANGED
@@ -484,9 +484,9 @@ As for field values themselves, I'm workin on it - but expect that soon.
484
484
 
485
485
  This gem is tested with the following Ruby versions on Linux and Mac OS X:
486
486
 
487
- * Ruby MRI 1.8.7, 1.9.3, 2.0.0, 2.1.x, 2.2.x
487
+ * Ruby MRI 1.8.7, 1.9.3, 2.0.0, 2.1.x, 2.2.x, 2.3.x
488
488
  * Ruby Enterprise Edition (based on MRI 1.8.7)
489
- * Rubinius 2.x
489
+ * Rubinius 2.x, 3.x
490
490
 
491
491
  This gem is tested with the following MySQL and MariaDB versions:
492
492
 
@@ -494,11 +494,11 @@ This gem is tested with the following MySQL and MariaDB versions:
494
494
  * MySQL Connector/C 6.0 and 6.1 (primarily on Windows)
495
495
  * MariaDB 5.5, 10.0, 10.1
496
496
 
497
- ### Rails / Active Record
497
+ ### Ruby on Rails / Active Record
498
498
 
499
- * mysql2 0.4.x works with Active Record 4.2.5 and higher.
500
- * mysql2 0.3.x works with Active Record 3.1 and higher (the AR adapter is now included in AR proper).
501
- * mysql2 0.2.x includes an Active Record adapter compatible with AR 2.3 and 3.0, and should not be used with AR 3.1 or higher.
499
+ * mysql2 0.4.x works with Rails / Active Record 4.2.5 - 5.0 and higher.
500
+ * mysql2 0.3.x works with Rails / Active Record 3.1, 3.2, 4.x, 5.0.
501
+ * mysql2 0.2.x works with Rails / Active Record 2.3 - 3.0.
502
502
 
503
503
  ### Asynchronous Active Record
504
504
 
@@ -346,15 +346,15 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
346
346
  conn_enc = rb_to_encoding(wrapper->encoding);
347
347
  #endif
348
348
 
349
+ if (wrapper->fields == Qnil) {
350
+ wrapper->numberOfFields = mysql_num_fields(wrapper->result);
351
+ wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
352
+ }
349
353
  if (args->asArray) {
350
354
  rowVal = rb_ary_new2(wrapper->numberOfFields);
351
355
  } else {
352
356
  rowVal = rb_hash_new();
353
357
  }
354
- if (wrapper->fields == Qnil) {
355
- wrapper->numberOfFields = mysql_num_fields(wrapper->result);
356
- wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
357
- }
358
358
 
359
359
  if (wrapper->result_buffers == NULL) {
360
360
  rb_mysql_result_alloc_result_buffers(self, fields);
@@ -541,16 +541,16 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, MYSQL_FIELD * fields, const r
541
541
  return Qnil;
542
542
  }
543
543
 
544
+ if (wrapper->fields == Qnil) {
545
+ wrapper->numberOfFields = mysql_num_fields(wrapper->result);
546
+ wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
547
+ }
544
548
  if (args->asArray) {
545
549
  rowVal = rb_ary_new2(wrapper->numberOfFields);
546
550
  } else {
547
551
  rowVal = rb_hash_new();
548
552
  }
549
553
  fieldLengths = mysql_fetch_lengths(wrapper->result);
550
- if (wrapper->fields == Qnil) {
551
- wrapper->numberOfFields = mysql_num_fields(wrapper->result);
552
- wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
553
- }
554
554
 
555
555
  for (i = 0; i < wrapper->numberOfFields; i++) {
556
556
  VALUE field = rb_mysql_result_fetch_field(self, i, args->symbolizeKeys);
@@ -834,7 +834,9 @@ static VALUE rb_mysql_result_each_(VALUE self,
834
834
 
835
835
  if (row == Qnil) {
836
836
  /* we don't need the mysql C dataset around anymore, peace it */
837
- rb_mysql_result_free_result(wrapper);
837
+ if (args->cacheRows) {
838
+ rb_mysql_result_free_result(wrapper);
839
+ }
838
840
  return Qnil;
839
841
  }
840
842
 
@@ -842,7 +844,7 @@ static VALUE rb_mysql_result_each_(VALUE self,
842
844
  rb_yield(row);
843
845
  }
844
846
  }
845
- if (wrapper->lastRowProcessed == wrapper->numberOfRows) {
847
+ if (wrapper->lastRowProcessed == wrapper->numberOfRows && args->cacheRows) {
846
848
  /* we don't need the mysql C dataset around anymore, peace it */
847
849
  rb_mysql_result_free_result(wrapper);
848
850
  }
@@ -886,6 +888,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
886
888
 
887
889
  if (wrapper->stmt_wrapper && !cacheRows && !wrapper->is_streaming) {
888
890
  rb_warn(":cache_rows is forced for prepared statements (if not streaming)");
891
+ cacheRows = 1;
889
892
  }
890
893
 
891
894
  if (wrapper->stmt_wrapper && !cast) {
@@ -913,13 +916,12 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
913
916
  app_timezone = Qnil;
914
917
  }
915
918
 
916
- if (wrapper->lastRowProcessed == 0 && !wrapper->is_streaming) {
919
+ if (wrapper->rows == Qnil && !wrapper->is_streaming) {
917
920
  wrapper->numberOfRows = wrapper->stmt_wrapper ? mysql_stmt_num_rows(wrapper->stmt_wrapper->stmt) : mysql_num_rows(wrapper->result);
918
- if (wrapper->numberOfRows == 0) {
919
- rb_mysql_result_free_result(wrapper);
920
- wrapper->rows = rb_ary_new();
921
- return wrapper->rows;
922
- }
921
+ wrapper->rows = rb_ary_new2(wrapper->numberOfRows);
922
+ } else if (wrapper->rows && !cacheRows) {
923
+ mysql_data_seek(wrapper->result, 0);
924
+ wrapper->lastRowProcessed = 0;
923
925
  wrapper->rows = rb_ary_new2(wrapper->numberOfRows);
924
926
  }
925
927
 
@@ -1,3 +1,3 @@
1
1
  module Mysql2
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -382,24 +382,24 @@ RSpec.describe Mysql2::Client do
382
382
 
383
383
  it "should expect connect_timeout to be a positive integer" do
384
384
  expect {
385
- Mysql2::Client.new(:connect_timeout => -1)
385
+ Mysql2::Client.new(DatabaseCredentials['root'].merge(:connect_timeout => -1))
386
386
  }.to raise_error(Mysql2::Error)
387
387
  end
388
388
 
389
389
  it "should expect read_timeout to be a positive integer" do
390
390
  expect {
391
- Mysql2::Client.new(:read_timeout => -1)
391
+ Mysql2::Client.new(DatabaseCredentials['root'].merge(:read_timeout => -1))
392
392
  }.to raise_error(Mysql2::Error)
393
393
  end
394
394
 
395
395
  it "should expect write_timeout to be a positive integer" do
396
396
  expect {
397
- Mysql2::Client.new(:write_timeout => -1)
397
+ Mysql2::Client.new(DatabaseCredentials['root'].merge(:write_timeout => -1))
398
398
  }.to raise_error(Mysql2::Error)
399
399
  end
400
400
 
401
401
  it "should allow nil read_timeout" do
402
- client = Mysql2::Client.new(:read_timeout => nil)
402
+ client = Mysql2::Client.new(DatabaseCredentials['root'].merge(:read_timeout => nil))
403
403
 
404
404
  expect(client.read_timeout).to be_nil
405
405
  end
@@ -82,6 +82,11 @@ RSpec.describe Mysql2::Result do
82
82
  expect(result.first.object_id).not_to eql(result.first.object_id)
83
83
  end
84
84
 
85
+ it "should be able to iterate a second time even if cache_rows is disabled" do
86
+ result = @client.query "SELECT 1 UNION SELECT 2", :cache_rows => false
87
+ expect(result.to_a).to eql(result.to_a)
88
+ end
89
+
85
90
  it "should yield different value for #first if streaming" do
86
91
  result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
87
92
  expect(result.first).not_to eql(result.first)
@@ -128,6 +128,14 @@ RSpec.describe Mysql2::Statement do
128
128
  expect(test_result['decimal_test']).to eql(123.45)
129
129
  end
130
130
 
131
+ it "should warn but still work if cache_rows is set to false" do
132
+ @client.query_options.merge!(:cache_rows => false)
133
+ statement = @client.prepare 'SELECT 1'
134
+ result = nil
135
+ expect { result = statement.execute.to_a }.to output(/:cache_rows is forced for prepared statements/).to_stderr
136
+ expect(result.length).to eq(1)
137
+ end
138
+
131
139
  context "utf8_db" do
132
140
  before(:each) do
133
141
  @client.query("DROP DATABASE IF EXISTS test_mysql2_stmt_utf8")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-24 00:00:00.000000000 Z
12
+ date: 2016-04-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.0.14
98
+ rubygems_version: 2.0.14.1
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: A simple, fast Mysql library for Ruby, binding to libmysql