mysql2 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +6 -1
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/ext/mysql2/client.c +109 -4
- data/ext/mysql2/result.c +34 -14
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +5 -0
- data/lib/mysql2.rb +2 -1
- data/lib/mysql2/client.rb +7 -1
- data/mysql2.gemspec +2 -2
- data/spec/mysql2/client_spec.rb +24 -0
- data/spec/mysql2/result_spec.rb +7 -2
- data/spec/spec_helper.rb +2 -3
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
3
|
+
## 0.2.3 (August 20th, 2010)
|
4
|
+
* connection flags can now be passed to the constructor via the :flags key
|
5
|
+
* switch AR adapter connection over to use FOUND_ROWS option
|
6
|
+
* patch to ensure we use DateTime objects in place of Time for timestamps that are out of the supported range on 32bit platforms < 1.9.2
|
7
|
+
|
8
|
+
## 0.2.2 (August 19th, 2010)
|
4
9
|
* Change how AR adapter would send initial commands upon connecting
|
5
10
|
** we can make multiple session variable assignments in a single query
|
6
11
|
* fix signal handling when waiting on queries
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/ext/mysql2/client.c
CHANGED
@@ -150,7 +150,7 @@ static VALUE allocate(VALUE klass) {
|
|
150
150
|
return obj;
|
151
151
|
}
|
152
152
|
|
153
|
-
static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE port, VALUE database, VALUE socket) {
|
153
|
+
static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE port, VALUE database, VALUE socket, VALUE flags) {
|
154
154
|
struct nogvl_connect_args args;
|
155
155
|
GET_CLIENT(self)
|
156
156
|
|
@@ -161,7 +161,7 @@ static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE po
|
|
161
161
|
args.passwd = NIL_P(pass) ? NULL : StringValuePtr(pass);
|
162
162
|
args.db = NIL_P(database) ? NULL : StringValuePtr(database);
|
163
163
|
args.mysql = client;
|
164
|
-
args.client_flag =
|
164
|
+
args.client_flag = NUM2INT(flags);
|
165
165
|
|
166
166
|
if (rb_thread_blocking_region(nogvl_connect, &args, RUBY_UBF_IO, 0) == Qfalse) {
|
167
167
|
// unable to connect
|
@@ -523,7 +523,7 @@ void init_mysql2_client() {
|
|
523
523
|
rb_define_private_method(cMysql2Client, "charset_name=", set_charset_name, 1);
|
524
524
|
rb_define_private_method(cMysql2Client, "ssl_set", set_ssl_options, 5);
|
525
525
|
rb_define_private_method(cMysql2Client, "init_connection", init_connection, 0);
|
526
|
-
rb_define_private_method(cMysql2Client, "connect", rb_connect,
|
526
|
+
rb_define_private_method(cMysql2Client, "connect", rb_connect, 7);
|
527
527
|
|
528
528
|
intern_encoding_from_charset = rb_intern("encoding_from_charset");
|
529
529
|
|
@@ -538,4 +538,109 @@ void init_mysql2_client() {
|
|
538
538
|
intern_error_number_eql = rb_intern("error_number=");
|
539
539
|
intern_sql_state_eql = rb_intern("sql_state=");
|
540
540
|
|
541
|
-
|
541
|
+
#ifdef CLIENT_LONG_PASSWORD
|
542
|
+
rb_const_set(cMysql2Client, rb_intern("LONG_PASSWORD"),
|
543
|
+
INT2NUM(CLIENT_LONG_PASSWORD));
|
544
|
+
#endif
|
545
|
+
|
546
|
+
#ifdef CLIENT_FOUND_ROWS
|
547
|
+
rb_const_set(cMysql2Client, rb_intern("FOUND_ROWS"),
|
548
|
+
INT2NUM(CLIENT_FOUND_ROWS));
|
549
|
+
#endif
|
550
|
+
|
551
|
+
#ifdef CLIENT_LONG_FLAG
|
552
|
+
rb_const_set(cMysql2Client, rb_intern("LONG_FLAG"),
|
553
|
+
INT2NUM(CLIENT_LONG_FLAG));
|
554
|
+
#endif
|
555
|
+
|
556
|
+
#ifdef CLIENT_CONNECT_WITH_DB
|
557
|
+
rb_const_set(cMysql2Client, rb_intern("CONNECT_WITH_DB"),
|
558
|
+
INT2NUM(CLIENT_CONNECT_WITH_DB));
|
559
|
+
#endif
|
560
|
+
|
561
|
+
#ifdef CLIENT_NO_SCHEMA
|
562
|
+
rb_const_set(cMysql2Client, rb_intern("NO_SCHEMA"),
|
563
|
+
INT2NUM(CLIENT_NO_SCHEMA));
|
564
|
+
#endif
|
565
|
+
|
566
|
+
#ifdef CLIENT_COMPRESS
|
567
|
+
rb_const_set(cMysql2Client, rb_intern("COMPRESS"), INT2NUM(CLIENT_COMPRESS));
|
568
|
+
#endif
|
569
|
+
|
570
|
+
#ifdef CLIENT_ODBC
|
571
|
+
rb_const_set(cMysql2Client, rb_intern("ODBC"), INT2NUM(CLIENT_ODBC));
|
572
|
+
#endif
|
573
|
+
|
574
|
+
#ifdef CLIENT_LOCAL_FILES
|
575
|
+
rb_const_set(cMysql2Client, rb_intern("LOCAL_FILES"),
|
576
|
+
INT2NUM(CLIENT_LOCAL_FILES));
|
577
|
+
#endif
|
578
|
+
|
579
|
+
#ifdef CLIENT_IGNORE_SPACE
|
580
|
+
rb_const_set(cMysql2Client, rb_intern("IGNORE_SPACE"),
|
581
|
+
INT2NUM(CLIENT_IGNORE_SPACE));
|
582
|
+
#endif
|
583
|
+
|
584
|
+
#ifdef CLIENT_PROTOCOL_41
|
585
|
+
rb_const_set(cMysql2Client, rb_intern("PROTOCOL_41"),
|
586
|
+
INT2NUM(CLIENT_PROTOCOL_41));
|
587
|
+
#endif
|
588
|
+
|
589
|
+
#ifdef CLIENT_INTERACTIVE
|
590
|
+
rb_const_set(cMysql2Client, rb_intern("INTERACTIVE"),
|
591
|
+
INT2NUM(CLIENT_INTERACTIVE));
|
592
|
+
#endif
|
593
|
+
|
594
|
+
#ifdef CLIENT_SSL
|
595
|
+
rb_const_set(cMysql2Client, rb_intern("SSL"), INT2NUM(CLIENT_SSL));
|
596
|
+
#endif
|
597
|
+
|
598
|
+
#ifdef CLIENT_IGNORE_SIGPIPE
|
599
|
+
rb_const_set(cMysql2Client, rb_intern("IGNORE_SIGPIPE"),
|
600
|
+
INT2NUM(CLIENT_IGNORE_SIGPIPE));
|
601
|
+
#endif
|
602
|
+
|
603
|
+
#ifdef CLIENT_TRANSACTIONS
|
604
|
+
rb_const_set(cMysql2Client, rb_intern("TRANSACTIONS"),
|
605
|
+
INT2NUM(CLIENT_TRANSACTIONS));
|
606
|
+
#endif
|
607
|
+
|
608
|
+
#ifdef CLIENT_RESERVED
|
609
|
+
rb_const_set(cMysql2Client, rb_intern("RESERVED"), INT2NUM(CLIENT_RESERVED));
|
610
|
+
#endif
|
611
|
+
|
612
|
+
#ifdef CLIENT_SECURE_CONNECTION
|
613
|
+
rb_const_set(cMysql2Client, rb_intern("SECURE_CONNECTION"),
|
614
|
+
INT2NUM(CLIENT_SECURE_CONNECTION));
|
615
|
+
#endif
|
616
|
+
|
617
|
+
#ifdef CLIENT_MULTI_STATEMENTS
|
618
|
+
rb_const_set(cMysql2Client, rb_intern("MULTI_STATEMENTS"),
|
619
|
+
INT2NUM(CLIENT_MULTI_STATEMENTS));
|
620
|
+
#endif
|
621
|
+
|
622
|
+
#ifdef CLIENT_PS_MULTI_RESULTS
|
623
|
+
rb_const_set(cMysql2Client, rb_intern("PS_MULTI_RESULTS"),
|
624
|
+
INT2NUM(CLIENT_PS_MULTI_RESULTS));
|
625
|
+
#endif
|
626
|
+
|
627
|
+
#ifdef CLIENT_SSL_VERIFY_SERVER_CERT
|
628
|
+
rb_const_set(cMysql2Client, rb_intern("SSL_VERIFY_SERVER_CERT"),
|
629
|
+
INT2NUM(CLIENT_SSL_VERIFY_SERVER_CERT));
|
630
|
+
#endif
|
631
|
+
|
632
|
+
#ifdef CLIENT_REMEMBER_OPTIONS
|
633
|
+
rb_const_set(cMysql2Client, rb_intern("REMEMBER_OPTIONS"),
|
634
|
+
INT2NUM(CLIENT_REMEMBER_OPTIONS));
|
635
|
+
#endif
|
636
|
+
|
637
|
+
#ifdef CLIENT_ALL_FLAGS
|
638
|
+
rb_const_set(cMysql2Client, rb_intern("ALL_FLAGS"),
|
639
|
+
INT2NUM(CLIENT_ALL_FLAGS));
|
640
|
+
#endif
|
641
|
+
|
642
|
+
#ifdef CLIENT_BASIC_FLAGS
|
643
|
+
rb_const_set(cMysql2Client, rb_intern("BASIC_FLAGS"),
|
644
|
+
INT2NUM(CLIENT_BASIC_FLAGS));
|
645
|
+
#endif
|
646
|
+
}
|
data/ext/mysql2/result.c
CHANGED
@@ -6,11 +6,11 @@ rb_encoding *binaryEncoding;
|
|
6
6
|
|
7
7
|
VALUE cMysql2Result;
|
8
8
|
VALUE cBigDecimal, cDate, cDateTime;
|
9
|
-
VALUE opt_decimal_zero, opt_float_zero, opt_time_year, opt_time_month;
|
9
|
+
VALUE opt_decimal_zero, opt_float_zero, opt_time_year, opt_time_month, opt_utc_offset;
|
10
10
|
extern VALUE mMysql2, cMysql2Client, cMysql2Error;
|
11
11
|
static VALUE intern_encoding_from_charset;
|
12
12
|
static ID intern_new, intern_utc, intern_local, intern_encoding_from_charset_code,
|
13
|
-
intern_localtime;
|
13
|
+
intern_localtime, intern_local_offset, intern_civil, intern_new_offset;
|
14
14
|
static ID sym_symbolize_keys, sym_as, sym_array, sym_database_timezone, sym_application_timezone,
|
15
15
|
sym_local, sym_utc, sym_cast_booleans;
|
16
16
|
static ID intern_merge;
|
@@ -127,7 +127,7 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
|
|
127
127
|
for (i = 0; i < wrapper->numberOfFields; i++) {
|
128
128
|
VALUE field = rb_mysql_result_fetch_field(self, i, symbolizeKeys);
|
129
129
|
if (row[i]) {
|
130
|
-
VALUE val;
|
130
|
+
VALUE val = Qnil;
|
131
131
|
switch(fields[i].type) {
|
132
132
|
case MYSQL_TYPE_NULL: // NULL-type field
|
133
133
|
val = Qnil;
|
@@ -190,12 +190,28 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
|
|
190
190
|
rb_raise(cMysql2Error, "Invalid date: %s", row[i]);
|
191
191
|
val = Qnil;
|
192
192
|
} else {
|
193
|
-
|
194
|
-
|
195
|
-
if (
|
196
|
-
|
197
|
-
}
|
198
|
-
|
193
|
+
if (year < 1902 || year+month+day > 2058) { // use DateTime instead
|
194
|
+
VALUE offset = INT2NUM(0);
|
195
|
+
if (db_timezone == intern_local) {
|
196
|
+
offset = rb_funcall(cMysql2Client, intern_local_offset, 0);
|
197
|
+
}
|
198
|
+
val = rb_funcall(cDateTime, intern_civil, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), offset);
|
199
|
+
if (!NIL_P(app_timezone)) {
|
200
|
+
if (app_timezone == intern_local) {
|
201
|
+
offset = rb_funcall(cMysql2Client, intern_local_offset, 0);
|
202
|
+
val = rb_funcall(val, intern_new_offset, 1, offset);
|
203
|
+
} else { // utc
|
204
|
+
val = rb_funcall(val, intern_new_offset, 1, opt_utc_offset);
|
205
|
+
}
|
206
|
+
}
|
207
|
+
} else {
|
208
|
+
val = rb_funcall(rb_cTime, db_timezone, 6, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec));
|
209
|
+
if (!NIL_P(app_timezone)) {
|
210
|
+
if (app_timezone == intern_local) {
|
211
|
+
val = rb_funcall(val, intern_localtime, 0);
|
212
|
+
} else { // utc
|
213
|
+
val = rb_funcall(val, intern_utc, 0);
|
214
|
+
}
|
199
215
|
}
|
200
216
|
}
|
201
217
|
}
|
@@ -420,11 +436,14 @@ void init_mysql2_result() {
|
|
420
436
|
intern_encoding_from_charset = rb_intern("encoding_from_charset");
|
421
437
|
intern_encoding_from_charset_code = rb_intern("encoding_from_charset_code");
|
422
438
|
|
423
|
-
intern_new
|
424
|
-
intern_utc
|
425
|
-
intern_local
|
426
|
-
intern_merge
|
427
|
-
intern_localtime
|
439
|
+
intern_new = rb_intern("new");
|
440
|
+
intern_utc = rb_intern("utc");
|
441
|
+
intern_local = rb_intern("local");
|
442
|
+
intern_merge = rb_intern("merge");
|
443
|
+
intern_localtime = rb_intern("localtime");
|
444
|
+
intern_local_offset = rb_intern("local_offset");
|
445
|
+
intern_civil = rb_intern("civil");
|
446
|
+
intern_new_offset = rb_intern("new_offset");
|
428
447
|
|
429
448
|
sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
|
430
449
|
sym_as = ID2SYM(rb_intern("as"));
|
@@ -441,6 +460,7 @@ void init_mysql2_result() {
|
|
441
460
|
opt_float_zero = rb_float_new((double)0);
|
442
461
|
opt_time_year = INT2NUM(2000);
|
443
462
|
opt_time_month = INT2NUM(1);
|
463
|
+
opt_utc_offset = INT2NUM(0);
|
444
464
|
|
445
465
|
#ifdef HAVE_RUBY_ENCODING_H
|
446
466
|
binaryEncoding = rb_enc_find("binary");
|
@@ -6,6 +6,11 @@ module ActiveRecord
|
|
6
6
|
class Base
|
7
7
|
def self.mysql2_connection(config)
|
8
8
|
config[:username] = 'root' if config[:username].nil?
|
9
|
+
|
10
|
+
if Mysql2::Client.const_defined? :FOUND_ROWS
|
11
|
+
config[:flags] = Mysql2::Client::FOUND_ROWS
|
12
|
+
end
|
13
|
+
|
9
14
|
client = Mysql2::Client.new(config.symbolize_keys)
|
10
15
|
options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
|
11
16
|
ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config)
|
data/lib/mysql2.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'date'
|
3
3
|
require 'bigdecimal'
|
4
|
+
require 'rational' unless RUBY_VERSION >= '1.9.2'
|
4
5
|
|
5
6
|
require 'mysql2/error'
|
6
7
|
require 'mysql2/mysql2'
|
@@ -11,5 +12,5 @@ require 'mysql2/result'
|
|
11
12
|
#
|
12
13
|
# A modern, simple and very fast Mysql library for Ruby - binding to libmysql
|
13
14
|
module Mysql2
|
14
|
-
VERSION = "0.2.
|
15
|
+
VERSION = "0.2.3"
|
15
16
|
end
|
data/lib/mysql2/client.rb
CHANGED
@@ -30,8 +30,9 @@ module Mysql2
|
|
30
30
|
port = opts[:port] || 3306
|
31
31
|
database = opts[:database]
|
32
32
|
socket = opts[:socket]
|
33
|
+
flags = opts[:flags] || 0
|
33
34
|
|
34
|
-
connect user, pass, host, port, database, socket
|
35
|
+
connect user, pass, host, port, database, socket, flags
|
35
36
|
end
|
36
37
|
|
37
38
|
def self.default_query_options
|
@@ -223,5 +224,10 @@ module Mysql2
|
|
223
224
|
end
|
224
225
|
end
|
225
226
|
end
|
227
|
+
|
228
|
+
private
|
229
|
+
def self.local_offset
|
230
|
+
::Time.local(2010).utc_offset.to_r / 86400
|
231
|
+
end
|
226
232
|
end
|
227
233
|
end
|
data/mysql2.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mysql2}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Lopez"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-20}
|
13
13
|
s.email = %q{seniorlopez@gmail.com}
|
14
14
|
s.extensions = ["ext/mysql2/extconf.rb"]
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/mysql2/client_spec.rb
CHANGED
@@ -14,6 +14,30 @@ describe Mysql2::Client do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
it "should accept connect flags and pass them to #connect" do
|
18
|
+
klient = Class.new(Mysql2::Client) do
|
19
|
+
attr_reader :connect_args
|
20
|
+
def connect *args
|
21
|
+
@connect_args ||= []
|
22
|
+
@connect_args << args
|
23
|
+
end
|
24
|
+
end
|
25
|
+
client = klient.new :flags => Mysql2::Client::FOUND_ROWS
|
26
|
+
client.connect_args.last.last.should == Mysql2::Client::FOUND_ROWS
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should default flags to 0" do
|
30
|
+
klient = Class.new(Mysql2::Client) do
|
31
|
+
attr_reader :connect_args
|
32
|
+
def connect *args
|
33
|
+
@connect_args ||= []
|
34
|
+
@connect_args << args
|
35
|
+
end
|
36
|
+
end
|
37
|
+
client = klient.new
|
38
|
+
client.connect_args.last.last.should == 0
|
39
|
+
end
|
40
|
+
|
17
41
|
it "should have a global default_query_options hash" do
|
18
42
|
Mysql2::Client.should respond_to(:default_query_options)
|
19
43
|
end
|
data/spec/mysql2/result_spec.rb
CHANGED
@@ -143,12 +143,17 @@ describe Mysql2::Result do
|
|
143
143
|
@test_result['double_test'].should eql(10.3)
|
144
144
|
end
|
145
145
|
|
146
|
-
it "should return Time for a DATETIME value" do
|
146
|
+
it "should return Time for a DATETIME value when within the supported range" do
|
147
147
|
@test_result['date_time_test'].class.should eql(Time)
|
148
148
|
@test_result['date_time_test'].strftime("%F %T").should eql('2010-04-04 11:44:00')
|
149
149
|
end
|
150
150
|
|
151
|
-
it "should return
|
151
|
+
it "should return DateTime for a DATETIME value when outside the supported range" do
|
152
|
+
r = @client.query("SELECT CAST('1901-1-1 01:01:01' AS DATETIME) as test")
|
153
|
+
r.first['test'].class.should eql(DateTime)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should return Time for a TIMESTAMP value when within the supported range" do
|
152
157
|
@test_result['timestamp_test'].class.should eql(Time)
|
153
158
|
@test_result['timestamp_test'].strftime("%F %T").should eql('2010-04-04 11:44:00')
|
154
159
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
|
3
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
2
|
|
3
|
+
require 'rubygems'
|
5
4
|
require 'mysql2'
|
6
5
|
require 'timeout'
|
7
6
|
|
@@ -64,4 +63,4 @@ Spec::Runner.configure do |config|
|
|
64
63
|
)
|
65
64
|
]
|
66
65
|
end
|
67
|
-
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Lopez
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-20 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|