mysql2 0.2.13 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 1.9.2@mysql2 --create
1
+ rvm use 1.9.3@mysql2 --create
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.14 (November 9th, 2011)
4
+ * use rb_wait_for_single_fd() if available
5
+ * fixed a bug with inheriting query options
6
+ * remove ext/ from the default loadpath
7
+ * fix build issues on OSX with Xcode 4.2 (gcc-llvm compiler)
8
+
3
9
  ## 0.2.13 (August 16th, 2011)
4
10
  * fix stupid bug around symbol encoding support (thanks coderrr!)
5
11
 
@@ -167,4 +173,4 @@
167
173
  * updated extconf (thanks to the mysqlplus project) for easier gem building
168
174
 
169
175
  ## 0.1.0 (April 6th, 2010)
170
- * initial release
176
+ * initial release
data/ext/mysql2/client.c CHANGED
@@ -4,6 +4,7 @@
4
4
  #ifndef _WIN32
5
5
  #include <sys/socket.h>
6
6
  #endif
7
+ #include "wait_for_single_fd.h"
7
8
 
8
9
  VALUE cMysql2Client;
9
10
  extern VALUE mMysql2, cMysql2Error;
@@ -45,6 +46,7 @@ struct nogvl_connect_args {
45
46
  struct nogvl_send_query_args {
46
47
  MYSQL *mysql;
47
48
  VALUE sql;
49
+ mysql_client_wrapper *wrapper;
48
50
  };
49
51
 
50
52
  /*
@@ -145,7 +147,7 @@ static VALUE nogvl_close(void *ptr) {
145
147
  #endif
146
148
 
147
149
  mysql_close(wrapper->client);
148
- xfree(wrapper->client);
150
+ free(wrapper->client);
149
151
  }
150
152
 
151
153
  return Qnil;
@@ -156,7 +158,7 @@ static void rb_mysql_client_free(void * ptr) {
156
158
 
157
159
  nogvl_close(wrapper);
158
160
 
159
- xfree(ptr);
161
+ free(ptr);
160
162
  }
161
163
 
162
164
  static VALUE allocate(VALUE klass) {
@@ -167,7 +169,7 @@ static VALUE allocate(VALUE klass) {
167
169
  wrapper->active = 0;
168
170
  wrapper->reconnect_enabled = 0;
169
171
  wrapper->closed = 1;
170
- wrapper->client = (MYSQL*)xmalloc(sizeof(MYSQL));
172
+ wrapper->client = (MYSQL*)malloc(sizeof(MYSQL));
171
173
  return obj;
172
174
  }
173
175
 
@@ -179,19 +181,19 @@ static VALUE rb_mysql_client_escape(RB_MYSQL_UNUSED VALUE klass, VALUE str) {
179
181
  Check_Type(str, T_STRING);
180
182
 
181
183
  oldLen = RSTRING_LEN(str);
182
- newStr = xmalloc(oldLen*2+1);
184
+ newStr = malloc(oldLen*2+1);
183
185
 
184
186
  newLen = mysql_escape_string((char *)newStr, StringValuePtr(str), oldLen);
185
187
  if (newLen == oldLen) {
186
188
  // no need to return a new ruby string if nothing changed
187
- xfree(newStr);
189
+ free(newStr);
188
190
  return str;
189
191
  } else {
190
192
  rb_str = rb_str_new((const char*)newStr, newLen);
191
193
  #ifdef HAVE_RUBY_ENCODING_H
192
194
  rb_enc_copy(rb_str, str);
193
195
  #endif
194
- xfree(newStr);
196
+ free(newStr);
195
197
  return rb_str;
196
198
  }
197
199
  }
@@ -249,6 +251,17 @@ static VALUE nogvl_send_query(void *ptr) {
249
251
  return rv == 0 ? Qtrue : Qfalse;
250
252
  }
251
253
 
254
+ static VALUE do_send_query(void *args) {
255
+ struct nogvl_send_query_args *query_args = args;
256
+ mysql_client_wrapper *wrapper = query_args->wrapper;
257
+ if (rb_thread_blocking_region(nogvl_send_query, args, RUBY_UBF_IO, 0) == Qfalse) {
258
+ // an error occurred, we're not active anymore
259
+ MARK_CONN_INACTIVE(self);
260
+ return rb_raise_mysql2_error(wrapper);
261
+ }
262
+ return Qnil;
263
+ }
264
+
252
265
  /*
253
266
  * even though we did rb_thread_select before calling this, a large
254
267
  * response can overflow the socket buffers and cause us to eventually
@@ -341,9 +354,7 @@ static VALUE do_query(void *args) {
341
354
  struct timeval tv;
342
355
  struct timeval* tvp;
343
356
  long int sec;
344
- fd_set fdset;
345
357
  int retval;
346
- int fd_set_fd;
347
358
  VALUE read_timeout;
348
359
 
349
360
  async_args = (struct async_query_args *)args;
@@ -364,14 +375,8 @@ static VALUE do_query(void *args) {
364
375
  tvp->tv_usec = 0;
365
376
  }
366
377
 
367
- fd_set_fd = async_args->fd;
368
378
  for(;;) {
369
- // the below code is largely from do_mysql
370
- // http://github.com/datamapper/do
371
- FD_ZERO(&fdset);
372
- FD_SET(fd_set_fd, &fdset);
373
-
374
- retval = rb_thread_select(fd_set_fd + 1, &fdset, NULL, NULL, tvp);
379
+ retval = rb_wait_for_single_fd(async_args->fd, RB_WAITFD_IN, tvp);
375
380
 
376
381
  if (retval == 0) {
377
382
  rb_raise(cMysql2Error, "Timeout waiting for a response from the last query. (waited %d seconds)", FIX2INT(read_timeout));
@@ -426,13 +431,6 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
426
431
  REQUIRE_OPEN_DB(wrapper);
427
432
  args.mysql = wrapper->client;
428
433
 
429
- // see if this connection is still waiting on a result from a previous query
430
- if (wrapper->active == 0) {
431
- // mark this connection active
432
- wrapper->active = 1;
433
- } else {
434
- rb_raise(cMysql2Error, "This connection is still waiting for a result, try again once you have the result");
435
- }
436
434
 
437
435
  defaults = rb_iv_get(self, "@query_options");
438
436
  if (rb_scan_args(argc, argv, "11", &args.sql, &opts) == 2) {
@@ -453,12 +451,17 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
453
451
  args.sql = rb_str_export_to_enc(args.sql, conn_enc);
454
452
  #endif
455
453
 
456
- if (rb_thread_blocking_region(nogvl_send_query, &args, RUBY_UBF_IO, 0) == Qfalse) {
457
- // an error occurred, we're not active anymore
458
- MARK_CONN_INACTIVE(self);
459
- return rb_raise_mysql2_error(wrapper);
454
+ // see if this connection is still waiting on a result from a previous query
455
+ if (wrapper->active == 0) {
456
+ // mark this connection active
457
+ wrapper->active = 1;
458
+ } else {
459
+ rb_raise(cMysql2Error, "This connection is still waiting for a result, try again once you have the result");
460
460
  }
461
461
 
462
+ args.wrapper = wrapper;
463
+ rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
464
+
462
465
  #ifndef _WIN32
463
466
  if (!async) {
464
467
  async_args.fd = wrapper->client->net.fd;
@@ -496,12 +499,12 @@ static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
496
499
  #endif
497
500
 
498
501
  oldLen = RSTRING_LEN(str);
499
- newStr = xmalloc(oldLen*2+1);
502
+ newStr = malloc(oldLen*2+1);
500
503
 
501
504
  newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, StringValuePtr(str), oldLen);
502
505
  if (newLen == oldLen) {
503
506
  // no need to return a new ruby string if nothing changed
504
- xfree(newStr);
507
+ free(newStr);
505
508
  return str;
506
509
  } else {
507
510
  rb_str = rb_str_new((const char*)newStr, newLen);
@@ -511,7 +514,7 @@ static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
511
514
  rb_str = rb_str_export_to_enc(rb_str, default_internal_enc);
512
515
  }
513
516
  #endif
514
- xfree(newStr);
517
+ free(newStr);
515
518
  return rb_str;
516
519
  }
517
520
  }
@@ -884,4 +887,4 @@ void init_mysql2_client() {
884
887
  rb_const_set(cMysql2Client, rb_intern("BASIC_FLAGS"),
885
888
  INT2NUM(CLIENT_BASIC_FLAGS));
886
889
  #endif
887
- }
890
+ }
@@ -7,6 +7,7 @@ end
7
7
 
8
8
  # 1.9-only
9
9
  have_func('rb_thread_blocking_region')
10
+ have_func('rb_wait_for_single_fd')
10
11
 
11
12
  # borrowed from mysqlplus
12
13
  # http://github.com/oldmoe/mysqlplus/blob/master/ext/extconf.rb
data/ext/mysql2/result.c CHANGED
@@ -139,7 +139,7 @@ static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int
139
139
  }
140
140
 
141
141
  #ifdef HAVE_RUBY_ENCODING_H
142
- inline VALUE mysql2_set_field_string_encoding(VALUE val, MYSQL_FIELD field, rb_encoding *default_internal_enc, rb_encoding *conn_enc) {
142
+ static VALUE mysql2_set_field_string_encoding(VALUE val, MYSQL_FIELD field, rb_encoding *default_internal_enc, rb_encoding *conn_enc) {
143
143
  // if binary flag is set, respect it's wishes
144
144
  if (field.flags & BINARY_FLAG && field.charsetnr == 63) {
145
145
  rb_enc_associate(val, binaryEncoding);
@@ -0,0 +1,36 @@
1
+ /*
2
+ * backwards compatibility for pre-1.9.3 C API
3
+ *
4
+ * Ruby 1.9.3 provides this API which allows the use of ppoll() on Linux
5
+ * to minimize select() and malloc() overhead on high-numbered FDs.
6
+ */
7
+ #ifdef HAVE_RB_WAIT_FOR_SINGLE_FD
8
+ # include <ruby/io.h>
9
+ #else
10
+ # define RB_WAITFD_IN 0x001
11
+ # define RB_WAITFD_PRI 0x002
12
+ # define RB_WAITFD_OUT 0x004
13
+
14
+ static int my_wait_for_single_fd(int fd, int events, struct timeval *tvp)
15
+ {
16
+ fd_set fdset;
17
+ fd_set *rfds = NULL;
18
+ fd_set *wfds = NULL;
19
+ fd_set *efds = NULL;
20
+
21
+ FD_ZERO(&fdset);
22
+ FD_SET(fd, &fdset);
23
+
24
+ if (events & RB_WAITFD_IN)
25
+ rfds = &fdset;
26
+ if (events & RB_WAITFD_OUT)
27
+ wfds = &fdset;
28
+ if (events & RB_WAITFD_PRI)
29
+ efds = &fdset;
30
+
31
+ return rb_thread_select(fd + 1, rfds, wfds, efds, tvp);
32
+ }
33
+
34
+ #define rb_wait_for_single_fd(fd,events,tvp) \
35
+ my_wait_for_single_fd((fd),(events),(tvp))
36
+ #endif
data/lib/mysql2/client.rb CHANGED
@@ -15,6 +15,7 @@ module Mysql2
15
15
 
16
16
  def initialize(opts = {})
17
17
  @query_options = @@default_query_options.dup
18
+ @query_options.merge! opts
18
19
 
19
20
  init_connection
20
21
 
@@ -30,7 +31,7 @@ module Mysql2
30
31
  raise Mysql2::Error, "read_timeout must be a positive integer, you passed #{@read_timeout}"
31
32
  end
32
33
 
33
- ssl_set(*opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslciper))
34
+ ssl_set(*opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher))
34
35
 
35
36
  user = opts[:username]
36
37
  pass = opts[:password]
@@ -1,3 +1,3 @@
1
1
  module Mysql2
2
- VERSION = "0.2.13"
3
- end
2
+ VERSION = "0.2.14"
3
+ end
data/mysql2.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.files = `git ls-files`.split("\n")
11
11
  s.homepage = %q{http://github.com/brianmario/mysql2}
12
12
  s.rdoc_options = ["--charset=UTF-8"]
13
- s.require_paths = ["lib", "ext"]
13
+ s.require_paths = ["lib"]
14
14
  s.rubygems_version = %q{1.4.2}
15
15
  s.summary = %q{A simple, fast Mysql library for Ruby, binding to libmysql}
16
16
  s.test_files = `git ls-files spec examples`.split("\n")
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  # tests
19
19
  s.add_development_dependency 'eventmachine'
20
20
  s.add_development_dependency 'rake-compiler', "~> 0.7.7"
21
+ s.add_development_dependency 'rake', '0.8.7' # NB: 0.8.7 required by rake-compiler 0.7.9
21
22
  s.add_development_dependency 'rspec'
22
23
  # benchmarks
23
24
  s.add_development_dependency 'activerecord'
@@ -26,4 +27,3 @@ Gem::Specification.new do |s|
26
27
  s.add_development_dependency 'sequel'
27
28
  s.add_development_dependency 'faker'
28
29
  end
29
-
metadata CHANGED
@@ -1,112 +1,162 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mysql2
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.13
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 14
10
+ version: 0.2.14
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Brian Lopez
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-08-17 00:00:00.000000000 -07:00
17
+
18
+ date: 2011-11-09 00:00:00 -08:00
13
19
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: eventmachine
17
- requirement: &70274481462240 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
23
33
  type: :development
24
- prerelease: false
25
- version_requirements: *70274481462240
26
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
27
36
  name: rake-compiler
28
- requirement: &70274481461740 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
29
39
  none: false
30
- requirements:
40
+ requirements:
31
41
  - - ~>
32
- - !ruby/object:Gem::Version
42
+ - !ruby/object:Gem::Version
43
+ hash: 13
44
+ segments:
45
+ - 0
46
+ - 7
47
+ - 7
33
48
  version: 0.7.7
34
49
  type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rake
35
53
  prerelease: false
36
- version_requirements: *70274481461740
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
- requirement: &70274481461320 !ruby/object:Gem::Requirement
54
+ requirement: &id003 !ruby/object:Gem::Requirement
40
55
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
56
+ requirements:
57
+ - - "="
58
+ - !ruby/object:Gem::Version
59
+ hash: 49
60
+ segments:
61
+ - 0
62
+ - 8
63
+ - 7
64
+ version: 0.8.7
45
65
  type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
46
69
  prerelease: false
47
- version_requirements: *70274481461320
48
- - !ruby/object:Gem::Dependency
49
- name: activerecord
50
- requirement: &70274481460860 !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
51
71
  none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
56
79
  type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: activerecord
57
83
  prerelease: false
58
- version_requirements: *70274481460860
59
- - !ruby/object:Gem::Dependency
60
- name: mysql
61
- requirement: &70274481460440 !ruby/object:Gem::Requirement
84
+ requirement: &id005 !ruby/object:Gem::Requirement
62
85
  none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
67
93
  type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: mysql
68
97
  prerelease: false
69
- version_requirements: *70274481460440
70
- - !ruby/object:Gem::Dependency
71
- name: do_mysql
72
- requirement: &70274481460020 !ruby/object:Gem::Requirement
98
+ requirement: &id006 !ruby/object:Gem::Requirement
73
99
  none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
78
107
  type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: do_mysql
79
111
  prerelease: false
80
- version_requirements: *70274481460020
81
- - !ruby/object:Gem::Dependency
82
- name: sequel
83
- requirement: &70274481459600 !ruby/object:Gem::Requirement
112
+ requirement: &id007 !ruby/object:Gem::Requirement
84
113
  none: false
85
- requirements:
86
- - - ! '>='
87
- - !ruby/object:Gem::Version
88
- version: '0'
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
89
121
  type: :development
122
+ version_requirements: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ name: sequel
90
125
  prerelease: false
91
- version_requirements: *70274481459600
92
- - !ruby/object:Gem::Dependency
93
- name: faker
94
- requirement: &70274465320920 !ruby/object:Gem::Requirement
126
+ requirement: &id008 !ruby/object:Gem::Requirement
95
127
  none: false
96
- requirements:
97
- - - ! '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
100
135
  type: :development
136
+ version_requirements: *id008
137
+ - !ruby/object:Gem::Dependency
138
+ name: faker
101
139
  prerelease: false
102
- version_requirements: *70274465320920
140
+ requirement: &id009 !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ type: :development
150
+ version_requirements: *id009
103
151
  description:
104
152
  email: seniorlopez@gmail.com
105
153
  executables: []
106
- extensions:
154
+
155
+ extensions:
107
156
  - ext/mysql2/extconf.rb
108
157
  extra_rdoc_files: []
109
- files:
158
+
159
+ files:
110
160
  - .gitignore
111
161
  - .rspec
112
162
  - .rvmrc
@@ -133,6 +183,7 @@ files:
133
183
  - ext/mysql2/mysql2_ext.h
134
184
  - ext/mysql2/result.c
135
185
  - ext/mysql2/result.h
186
+ - ext/mysql2/wait_for_single_fd.h
136
187
  - lib/active_record/connection_adapters/em_mysql2_adapter.rb
137
188
  - lib/active_record/connection_adapters/mysql2_adapter.rb
138
189
  - lib/active_record/fiber_patches.rb
@@ -159,31 +210,38 @@ files:
159
210
  has_rdoc: true
160
211
  homepage: http://github.com/brianmario/mysql2
161
212
  licenses: []
213
+
162
214
  post_install_message:
163
- rdoc_options:
215
+ rdoc_options:
164
216
  - --charset=UTF-8
165
- require_paths:
217
+ require_paths:
166
218
  - lib
167
- - ext
168
- required_ruby_version: !ruby/object:Gem::Requirement
219
+ required_ruby_version: !ruby/object:Gem::Requirement
169
220
  none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- required_rubygems_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ hash: 3
225
+ segments:
226
+ - 0
227
+ version: "0"
228
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
229
  none: false
176
- requirements:
177
- - - ! '>='
178
- - !ruby/object:Gem::Version
179
- version: '0'
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ hash: 3
234
+ segments:
235
+ - 0
236
+ version: "0"
180
237
  requirements: []
238
+
181
239
  rubyforge_project:
182
240
  rubygems_version: 1.6.2
183
241
  signing_key:
184
242
  specification_version: 3
185
243
  summary: A simple, fast Mysql library for Ruby, binding to libmysql
186
- test_files:
244
+ test_files:
187
245
  - examples/eventmachine.rb
188
246
  - examples/threaded.rb
189
247
  - spec/em/em_fiber_spec.rb