mysql2 0.5.0 → 0.5.1

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: 658cf051d498ace207785b75cead2b0f938bba92
4
- data.tar.gz: 7f50c5cf9a45656a5347809d4494ee0c17eb8208
3
+ metadata.gz: a6bf072c2ecc5ecb841ac10b4f0d7af76143e1a0
4
+ data.tar.gz: 3f92fd936bed501a93ebf7d32848b89059989310
5
5
  SHA512:
6
- metadata.gz: '05994292d6c1de48d3fcc1af99c5c2ec85c09a6bb1111e19129d9434fcdf191d838a91fee9d61d6a67576a6ff316a39b418b9cf13e159d99cbbad2e49eb28e78'
7
- data.tar.gz: 5d668a60aa6ed4053787b84c1cb3114604b2c22c225492b53124d7d023fd02f6c9b54f848453fedce72ac64092723b989f3cafb471605ffa5606444cf0a4d26b
6
+ metadata.gz: 9efb2aa011d4e0f0fd5c6bb1a088164686cb515f78c97d20121a9810f6b4bef9f9be07f7deebf4100153a096b3e3a319f6d7ebabe1b53c1841970a0617729c0c
7
+ data.tar.gz: 3d15ed281a359a7fb8d5815769c2d6555066796cf9f3abf55ff39375a847d186ba32508820e850f09dfb34e3a3560521bc0c151355bcaa9295c3669b4c1e089f
data/README.md CHANGED
@@ -178,6 +178,9 @@ Pass your arguments to the execute method in the same number and order as the
178
178
  question marks in the statement. Query options can be passed as keyword arguments
179
179
  to the execute method.
180
180
 
181
+ Be sure to read about the known limitations of prepared statements at
182
+ https://dev.mysql.com/doc/refman/5.6/en/c-api-prepared-statement-problems.html
183
+
181
184
  ``` ruby
182
185
  statement = @client.prepare("SELECT * FROM users WHERE login_count = ?")
183
186
  result1 = statement.execute(1)
@@ -534,6 +537,7 @@ This gem is tested with the following MySQL and MariaDB versions:
534
537
 
535
538
  ### Ruby on Rails / Active Record
536
539
 
540
+ * mysql2 0.5.x works with Rails / Active Record 5.0.7, 5.1.6, and higher.
537
541
  * mysql2 0.4.x works with Rails / Active Record 4.2.5 - 5.0 and higher.
538
542
  * mysql2 0.3.x works with Rails / Active Record 3.1, 3.2, 4.x, 5.0.
539
543
  * mysql2 0.2.x works with Rails / Active Record 2.3 - 3.0.
@@ -63,6 +63,7 @@ if inc && lib
63
63
  abort "-----\nCannot find library dir(s) #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
64
64
  warn "-----\nUsing --with-mysql-dir=#{File.dirname inc}\n-----"
65
65
  rpath_dir = lib
66
+ have_library('mysqlclient')
66
67
  elsif (mc = (with_config('mysql-config') || Dir[GLOB].first))
67
68
  # If the user has provided a --with-mysql-config argument, we must respect it or fail.
68
69
  # If the user gave --with-mysql-config with no argument means we should try to find it.
@@ -403,6 +403,39 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {
403
403
  }
404
404
  }
405
405
 
406
+ // Duplicate the options hash, merge! extra opts, put the copy into the Result object
407
+ current = rb_hash_dup(rb_iv_get(stmt_wrapper->client, "@query_options"));
408
+ (void)RB_GC_GUARD(current);
409
+ Check_Type(current, T_HASH);
410
+
411
+ // Merge in hash opts/keyword arguments
412
+ if (!NIL_P(opts)) {
413
+ rb_funcall(current, intern_merge_bang, 1, opts);
414
+ }
415
+
416
+ is_streaming = (Qtrue == rb_hash_aref(current, sym_stream));
417
+
418
+ // From stmt_execute to mysql_stmt_result_metadata to stmt_store_result, no
419
+ // Ruby API calls are allowed so that GC is not invoked. If the connection is
420
+ // in results-streaming-mode for Statement A, and in the middle Statement B
421
+ // gets garbage collected, a message will be sent to the server notifying it
422
+ // to release Statement B, resulting in the following error:
423
+ // Commands out of sync; you can't run this command now
424
+ //
425
+ // In streaming mode, statement execute must return a cursor because we
426
+ // cannot prevent other Statement objects from being garbage collected
427
+ // between fetches of each row of the result set. The following error
428
+ // occurs if cursor mode is not set:
429
+ // Row retrieval was canceled by mysql_stmt_close
430
+
431
+ if (is_streaming) {
432
+ unsigned long type = CURSOR_TYPE_READ_ONLY;
433
+ if (mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &type)) {
434
+ FREE_BINDS;
435
+ rb_raise(cMysql2Error, "Unable to stream prepared statement, could not set CURSOR_TYPE_READ_ONLY");
436
+ }
437
+ }
438
+
406
439
  if ((VALUE)rb_thread_call_without_gvl(nogvl_stmt_execute, stmt, RUBY_UBF_IO, 0) == Qfalse) {
407
440
  FREE_BINDS;
408
441
  rb_raise_mysql2_stmt_error(stmt_wrapper);
@@ -421,17 +454,6 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {
421
454
  return Qnil;
422
455
  }
423
456
 
424
- // Duplicate the options hash, merge! extra opts, put the copy into the Result object
425
- current = rb_hash_dup(rb_iv_get(stmt_wrapper->client, "@query_options"));
426
- (void)RB_GC_GUARD(current);
427
- Check_Type(current, T_HASH);
428
-
429
- // Merge in hash opts/keyword arguments
430
- if (!NIL_P(opts)) {
431
- rb_funcall(current, intern_merge_bang, 1, opts);
432
- }
433
-
434
- is_streaming = (Qtrue == rb_hash_aref(current, sym_stream));
435
457
  if (!is_streaming) {
436
458
  // recieve the whole result set from the server
437
459
  if (mysql_stmt_store_result(stmt)) {
@@ -1,3 +1,3 @@
1
1
  module Mysql2
2
- VERSION = "0.5.0".freeze
2
+ VERSION = "0.5.1".freeze
3
3
  end
@@ -6,6 +6,10 @@ RSpec.describe Mysql2::Statement do
6
6
  end
7
7
 
8
8
  def stmt_count
9
+ # Use the performance schema in MySQL 5.7 and above
10
+ @client.query("SELECT COUNT(1) AS count FROM performance_schema.prepared_statements_instances").first['count'].to_i
11
+ rescue Mysql2::Error
12
+ # Fall back to the global prepapred statement counter
9
13
  @client.query("SHOW STATUS LIKE 'Prepared_stmt_count'").first['Value'].to_i
10
14
  end
11
15
 
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.5.0
4
+ version: 0.5.1
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: 2018-03-20 00:00:00.000000000 Z
12
+ date: 2018-04-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: