mysql2 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/ext/mysql2/extconf.rb +1 -0
- data/ext/mysql2/mysql_enc_to_ruby.h +10 -0
- data/ext/mysql2/result.c +2 -1
- data/ext/mysql2/statement.c +33 -11
- data/lib/mysql2/version.rb +1 -1
- data/spec/mysql2/statement_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62ba5d2530e40ed2dcefd98c2219c95b166a7385
|
4
|
+
data.tar.gz: c17840a416a95f241cd9259c57aaacac100d17f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50d8ecc5c61d004953d4da51b69ca0d8166c1c665757f677eedea84c62173490a6b0b1b67cec9e661397306fb0607930f6cf5b062fd8f77c2d9c2ea02b8d2d69
|
7
|
+
data.tar.gz: d62e82ffffe4e1a84d37f1a3745c58c0d5b0f88d0cc1403b93a452a0af454e6aa1a49653cb70b494b092ffa7f924ed66293c58ec0ddbe2e8497eedcf631ffd7c
|
data/README.md
CHANGED
@@ -74,10 +74,11 @@ To see line numbers in backtraces, declare these environment variables
|
|
74
74
|
|
75
75
|
### Linux and other Unixes
|
76
76
|
|
77
|
-
You may need to install a package such as `libmysqlclient-dev
|
78
|
-
refer to your distribution's package guide to
|
79
|
-
The most common issue we see is a user who has
|
80
|
-
|
77
|
+
You may need to install a package such as `libmysqlclient-dev`, `mysql-devel`,
|
78
|
+
or `default-libmysqlclient-dev`; refer to your distribution's package guide to
|
79
|
+
find the particular package. The most common issue we see is a user who has
|
80
|
+
the library file `libmysqlclient.so` but is missing the header file `mysql.h`
|
81
|
+
-- double check that you have the _-dev_ packages installed.
|
81
82
|
|
82
83
|
### Mac OS X
|
83
84
|
|
@@ -178,6 +179,9 @@ Pass your arguments to the execute method in the same number and order as the
|
|
178
179
|
question marks in the statement. Query options can be passed as keyword arguments
|
179
180
|
to the execute method.
|
180
181
|
|
182
|
+
Be sure to read about the known limitations of prepared statements at
|
183
|
+
https://dev.mysql.com/doc/refman/5.6/en/c-api-prepared-statement-problems.html
|
184
|
+
|
181
185
|
``` ruby
|
182
186
|
statement = @client.prepare("SELECT * FROM users WHERE login_count = ?")
|
183
187
|
result1 = statement.execute(1)
|
@@ -534,6 +538,7 @@ This gem is tested with the following MySQL and MariaDB versions:
|
|
534
538
|
|
535
539
|
### Ruby on Rails / Active Record
|
536
540
|
|
541
|
+
* mysql2 0.5.x works with Rails / Active Record 5.0.7, 5.1.6, and higher.
|
537
542
|
* mysql2 0.4.x works with Rails / Active Record 4.2.5 - 5.0 and higher.
|
538
543
|
* mysql2 0.3.x works with Rails / Active Record 3.1, 3.2, 4.x, 5.0.
|
539
544
|
* mysql2 0.2.x works with Rails / Active Record 2.3 - 3.0.
|
data/ext/mysql2/extconf.rb
CHANGED
@@ -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.
|
@@ -245,5 +245,15 @@ static const char *mysql2_mysql_enc_to_rb[] = {
|
|
245
245
|
"UTF-8",
|
246
246
|
"UTF-8",
|
247
247
|
"UTF-8",
|
248
|
+
"UTF-8",
|
249
|
+
NULL,
|
250
|
+
NULL,
|
251
|
+
NULL,
|
252
|
+
NULL,
|
253
|
+
NULL,
|
254
|
+
NULL,
|
255
|
+
NULL,
|
248
256
|
"UTF-8"
|
249
257
|
};
|
258
|
+
|
259
|
+
#define CHARSETNR_SIZE (sizeof(mysql2_mysql_enc_to_rb)/sizeof(mysql2_mysql_enc_to_rb[0]))
|
data/ext/mysql2/result.c
CHANGED
@@ -179,7 +179,8 @@ static VALUE mysql2_set_field_string_encoding(VALUE val, MYSQL_FIELD field, rb_e
|
|
179
179
|
const char *enc_name;
|
180
180
|
int enc_index;
|
181
181
|
|
182
|
-
enc_name = mysql2_mysql_enc_to_rb[field.charsetnr-1];
|
182
|
+
enc_name = (field.charsetnr-1 < CHARSETNR_SIZE) ? mysql2_mysql_enc_to_rb[field.charsetnr-1] : NULL;
|
183
|
+
|
183
184
|
if (enc_name != NULL) {
|
184
185
|
/* use the field encoding we were able to match */
|
185
186
|
enc_index = rb_enc_find_index(enc_name);
|
data/ext/mysql2/statement.c
CHANGED
@@ -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)) {
|
data/lib/mysql2/version.rb
CHANGED
@@ -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.
|
4
|
+
version: 0.5.2
|
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-
|
12
|
+
date: 2018-07-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|