solaris-mysql2 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rvmrc +1 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +244 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +334 -0
- data/Rakefile +5 -0
- data/benchmark/active_record.rb +51 -0
- data/benchmark/active_record_threaded.rb +42 -0
- data/benchmark/allocations.rb +33 -0
- data/benchmark/escape.rb +36 -0
- data/benchmark/query_with_mysql_casting.rb +80 -0
- data/benchmark/query_without_mysql_casting.rb +56 -0
- data/benchmark/sequel.rb +37 -0
- data/benchmark/setup_db.rb +119 -0
- data/benchmark/threaded.rb +44 -0
- data/examples/eventmachine.rb +21 -0
- data/examples/threaded.rb +20 -0
- data/ext/mysql2/client.c +901 -0
- data/ext/mysql2/client.h +42 -0
- data/ext/mysql2/extconf.rb +74 -0
- data/ext/mysql2/mysql2_ext.c +12 -0
- data/ext/mysql2/mysql2_ext.h +42 -0
- data/ext/mysql2/result.c +566 -0
- data/ext/mysql2/result.h +20 -0
- data/ext/mysql2/wait_for_single_fd.h +36 -0
- data/lib/mysql2.rb +21 -0
- data/lib/mysql2/client.rb +264 -0
- data/lib/mysql2/em.rb +37 -0
- data/lib/mysql2/error.rb +15 -0
- data/lib/mysql2/result.rb +5 -0
- data/lib/mysql2/version.rb +3 -0
- data/solaris-mysql2.gemspec +29 -0
- data/spec/em/em_spec.rb +50 -0
- data/spec/mysql2/client_spec.rb +465 -0
- data/spec/mysql2/error_spec.rb +69 -0
- data/spec/mysql2/result_spec.rb +388 -0
- data/spec/rcov.opts +3 -0
- data/spec/spec_helper.rb +67 -0
- data/tasks/benchmarks.rake +20 -0
- data/tasks/compile.rake +71 -0
- data/tasks/rspec.rake +16 -0
- data/tasks/vendor_mysql.rake +40 -0
- metadata +198 -0
data/ext/mysql2/result.h
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifndef MYSQL2_RESULT_H
|
2
|
+
#define MYSQL2_RESULT_H
|
3
|
+
|
4
|
+
void init_mysql2_result();
|
5
|
+
VALUE rb_mysql_result_to_obj(MYSQL_RES * r);
|
6
|
+
|
7
|
+
typedef struct {
|
8
|
+
VALUE fields;
|
9
|
+
VALUE rows;
|
10
|
+
VALUE encoding;
|
11
|
+
unsigned int numberOfFields;
|
12
|
+
unsigned long numberOfRows;
|
13
|
+
unsigned long lastRowProcessed;
|
14
|
+
char resultFreed;
|
15
|
+
MYSQL_RES *result;
|
16
|
+
} mysql2_result_wrapper;
|
17
|
+
|
18
|
+
#define GetMysql2Result(obj, sval) (sval = (mysql2_result_wrapper*)DATA_PTR(obj));
|
19
|
+
|
20
|
+
#endif
|
@@ -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.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'date'
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'rational' unless RUBY_VERSION >= '1.9.2'
|
5
|
+
|
6
|
+
require 'mysql2/version' unless defined? Mysql2::VERSION
|
7
|
+
require 'mysql2/error'
|
8
|
+
require 'mysql2/result'
|
9
|
+
require 'mysql2/mysql2'
|
10
|
+
require 'mysql2/client'
|
11
|
+
|
12
|
+
# = Mysql2
|
13
|
+
#
|
14
|
+
# A modern, simple and very fast Mysql library for Ruby - binding to libmysql
|
15
|
+
module Mysql2
|
16
|
+
end
|
17
|
+
|
18
|
+
if defined?(ActiveRecord::VERSION::STRING) && ActiveRecord::VERSION::STRING < "3.1"
|
19
|
+
puts "WARNING: This version of mysql2 (#{Mysql2::VERSION}) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1"
|
20
|
+
puts "WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x"
|
21
|
+
end
|
@@ -0,0 +1,264 @@
|
|
1
|
+
module Mysql2
|
2
|
+
class Client
|
3
|
+
attr_reader :query_options
|
4
|
+
@@default_query_options = {
|
5
|
+
:as => :hash, # the type of object you want each row back as; also supports :array (an array of values)
|
6
|
+
:async => false, # don't wait for a result after sending the query, you'll have to monitor the socket yourself then eventually call Mysql2::Client#async_result
|
7
|
+
:cast_booleans => false, # cast tinyint(1) fields as true/false in ruby
|
8
|
+
:symbolize_keys => false, # return field names as symbols instead of strings
|
9
|
+
:database_timezone => :local, # timezone Mysql2 will assume datetime objects are stored in
|
10
|
+
:application_timezone => nil, # timezone Mysql2 will convert to before handing the object back to the caller
|
11
|
+
:cache_rows => true, # tells Mysql2 to use it's internal row cache for results
|
12
|
+
:connect_flags => REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION,
|
13
|
+
:cast => true
|
14
|
+
}
|
15
|
+
|
16
|
+
def initialize(opts = {})
|
17
|
+
@query_options = @@default_query_options.dup
|
18
|
+
@query_options.merge! opts
|
19
|
+
|
20
|
+
init_connection
|
21
|
+
|
22
|
+
[:reconnect, :connect_timeout].each do |key|
|
23
|
+
next unless opts.key?(key)
|
24
|
+
send(:"#{key}=", opts[key])
|
25
|
+
end
|
26
|
+
# force the encoding to utf8
|
27
|
+
self.charset_name = opts[:encoding] || 'utf8'
|
28
|
+
|
29
|
+
@read_timeout = opts[:read_timeout]
|
30
|
+
if @read_timeout and @read_timeout < 0
|
31
|
+
raise Mysql2::Error, "read_timeout must be a positive integer, you passed #{@read_timeout}"
|
32
|
+
end
|
33
|
+
|
34
|
+
ssl_set(*opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher))
|
35
|
+
|
36
|
+
user = opts[:username]
|
37
|
+
pass = opts[:password]
|
38
|
+
host = opts[:host] || 'localhost'
|
39
|
+
port = opts[:port] || 3306
|
40
|
+
database = opts[:database]
|
41
|
+
socket = opts[:socket]
|
42
|
+
flags = opts[:flags] ? opts[:flags] | @query_options[:connect_flags] : @query_options[:connect_flags]
|
43
|
+
|
44
|
+
connect user, pass, host, port, database, socket, flags
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.default_query_options
|
48
|
+
@@default_query_options
|
49
|
+
end
|
50
|
+
|
51
|
+
# NOTE: from ruby-mysql
|
52
|
+
if defined? Encoding
|
53
|
+
CHARSET_MAP = {
|
54
|
+
"armscii8" => nil,
|
55
|
+
"ascii" => Encoding::US_ASCII,
|
56
|
+
"big5" => Encoding::Big5,
|
57
|
+
"binary" => Encoding::ASCII_8BIT,
|
58
|
+
"cp1250" => Encoding::Windows_1250,
|
59
|
+
"cp1251" => Encoding::Windows_1251,
|
60
|
+
"cp1256" => Encoding::Windows_1256,
|
61
|
+
"cp1257" => Encoding::Windows_1257,
|
62
|
+
"cp850" => Encoding::CP850,
|
63
|
+
"cp852" => Encoding::CP852,
|
64
|
+
"cp866" => Encoding::IBM866,
|
65
|
+
"cp932" => Encoding::Windows_31J,
|
66
|
+
"dec8" => nil,
|
67
|
+
"eucjpms" => Encoding::EucJP_ms,
|
68
|
+
"euckr" => Encoding::EUC_KR,
|
69
|
+
"gb2312" => Encoding::EUC_CN,
|
70
|
+
"gbk" => Encoding::GBK,
|
71
|
+
"geostd8" => nil,
|
72
|
+
"greek" => Encoding::ISO_8859_7,
|
73
|
+
"hebrew" => Encoding::ISO_8859_8,
|
74
|
+
"hp8" => nil,
|
75
|
+
"keybcs2" => nil,
|
76
|
+
"koi8r" => Encoding::KOI8_R,
|
77
|
+
"koi8u" => Encoding::KOI8_U,
|
78
|
+
"latin1" => Encoding::ISO_8859_1,
|
79
|
+
"latin2" => Encoding::ISO_8859_2,
|
80
|
+
"latin5" => Encoding::ISO_8859_9,
|
81
|
+
"latin7" => Encoding::ISO_8859_13,
|
82
|
+
"macce" => Encoding::MacCentEuro,
|
83
|
+
"macroman" => Encoding::MacRoman,
|
84
|
+
"sjis" => Encoding::SHIFT_JIS,
|
85
|
+
"swe7" => nil,
|
86
|
+
"tis620" => Encoding::TIS_620,
|
87
|
+
"ucs2" => Encoding::UTF_16BE,
|
88
|
+
"ujis" => Encoding::EucJP_ms,
|
89
|
+
"utf8" => Encoding::UTF_8,
|
90
|
+
"utf8mb4" => Encoding::UTF_8,
|
91
|
+
}
|
92
|
+
|
93
|
+
MYSQL_CHARSET_MAP = {
|
94
|
+
1 => {:name => "big5", :collation => "big5_chinese_ci"},
|
95
|
+
2 => {:name => "latin2", :collation => "latin2_czech_cs"},
|
96
|
+
3 => {:name => "dec8", :collation => "dec8_swedish_ci"},
|
97
|
+
4 => {:name => "cp850", :collation => "cp850_general_ci"},
|
98
|
+
5 => {:name => "latin1", :collation => "latin1_german1_ci"},
|
99
|
+
6 => {:name => "hp8", :collation => "hp8_english_ci"},
|
100
|
+
7 => {:name => "koi8r", :collation => "koi8r_general_ci"},
|
101
|
+
8 => {:name => "latin1", :collation => "latin1_swedish_ci"},
|
102
|
+
9 => {:name => "latin2", :collation => "latin2_general_ci"},
|
103
|
+
10 => {:name => "swe7", :collation => "swe7_swedish_ci"},
|
104
|
+
11 => {:name => "ascii", :collation => "ascii_general_ci"},
|
105
|
+
12 => {:name => "ujis", :collation => "ujis_japanese_ci"},
|
106
|
+
13 => {:name => "sjis", :collation => "sjis_japanese_ci"},
|
107
|
+
14 => {:name => "cp1251", :collation => "cp1251_bulgarian_ci"},
|
108
|
+
15 => {:name => "latin1", :collation => "latin1_danish_ci"},
|
109
|
+
16 => {:name => "hebrew", :collation => "hebrew_general_ci"},
|
110
|
+
17 => {:name => "filename", :collation => "filename"},
|
111
|
+
18 => {:name => "tis620", :collation => "tis620_thai_ci"},
|
112
|
+
19 => {:name => "euckr", :collation => "euckr_korean_ci"},
|
113
|
+
20 => {:name => "latin7", :collation => "latin7_estonian_cs"},
|
114
|
+
21 => {:name => "latin2", :collation => "latin2_hungarian_ci"},
|
115
|
+
22 => {:name => "koi8u", :collation => "koi8u_general_ci"},
|
116
|
+
23 => {:name => "cp1251", :collation => "cp1251_ukrainian_ci"},
|
117
|
+
24 => {:name => "gb2312", :collation => "gb2312_chinese_ci"},
|
118
|
+
25 => {:name => "greek", :collation => "greek_general_ci"},
|
119
|
+
26 => {:name => "cp1250", :collation => "cp1250_general_ci"},
|
120
|
+
27 => {:name => "latin2", :collation => "latin2_croatian_ci"},
|
121
|
+
28 => {:name => "gbk", :collation => "gbk_chinese_ci"},
|
122
|
+
29 => {:name => "cp1257", :collation => "cp1257_lithuanian_ci"},
|
123
|
+
30 => {:name => "latin5", :collation => "latin5_turkish_ci"},
|
124
|
+
31 => {:name => "latin1", :collation => "latin1_german2_ci"},
|
125
|
+
32 => {:name => "armscii8", :collation => "armscii8_general_ci"},
|
126
|
+
33 => {:name => "utf8", :collation => "utf8_general_ci"},
|
127
|
+
34 => {:name => "cp1250", :collation => "cp1250_czech_cs"},
|
128
|
+
35 => {:name => "ucs2", :collation => "ucs2_general_ci"},
|
129
|
+
36 => {:name => "cp866", :collation => "cp866_general_ci"},
|
130
|
+
37 => {:name => "keybcs2", :collation => "keybcs2_general_ci"},
|
131
|
+
38 => {:name => "macce", :collation => "macce_general_ci"},
|
132
|
+
39 => {:name => "macroman", :collation => "macroman_general_ci"},
|
133
|
+
40 => {:name => "cp852", :collation => "cp852_general_ci"},
|
134
|
+
41 => {:name => "latin7", :collation => "latin7_general_ci"},
|
135
|
+
42 => {:name => "latin7", :collation => "latin7_general_cs"},
|
136
|
+
43 => {:name => "macce", :collation => "macce_bin"},
|
137
|
+
44 => {:name => "cp1250", :collation => "cp1250_croatian_ci"},
|
138
|
+
45 => {:name => "utf8mb4", :collation => "utf8mb4_general_ci"},
|
139
|
+
46 => {:name => "utf8mb4", :collation => "utf8mb4_bin"},
|
140
|
+
47 => {:name => "latin1", :collation => "latin1_bin"},
|
141
|
+
48 => {:name => "latin1", :collation => "latin1_general_ci"},
|
142
|
+
49 => {:name => "latin1", :collation => "latin1_general_cs"},
|
143
|
+
50 => {:name => "cp1251", :collation => "cp1251_bin"},
|
144
|
+
51 => {:name => "cp1251", :collation => "cp1251_general_ci"},
|
145
|
+
52 => {:name => "cp1251", :collation => "cp1251_general_cs"},
|
146
|
+
53 => {:name => "macroman", :collation => "macroman_bin"},
|
147
|
+
57 => {:name => "cp1256", :collation => "cp1256_general_ci"},
|
148
|
+
58 => {:name => "cp1257", :collation => "cp1257_bin"},
|
149
|
+
59 => {:name => "cp1257", :collation => "cp1257_general_ci"},
|
150
|
+
63 => {:name => "binary", :collation => "binary"},
|
151
|
+
64 => {:name => "armscii8", :collation => "armscii8_bin"},
|
152
|
+
65 => {:name => "ascii", :collation => "ascii_bin"},
|
153
|
+
66 => {:name => "cp1250", :collation => "cp1250_bin"},
|
154
|
+
67 => {:name => "cp1256", :collation => "cp1256_bin"},
|
155
|
+
68 => {:name => "cp866", :collation => "cp866_bin"},
|
156
|
+
69 => {:name => "dec8", :collation => "dec8_bin"},
|
157
|
+
70 => {:name => "greek", :collation => "greek_bin"},
|
158
|
+
71 => {:name => "hebrew", :collation => "hebrew_bin"},
|
159
|
+
72 => {:name => "hp8", :collation => "hp8_bin"},
|
160
|
+
73 => {:name => "keybcs2", :collation => "keybcs2_bin"},
|
161
|
+
74 => {:name => "koi8r", :collation => "koi8r_bin"},
|
162
|
+
75 => {:name => "koi8u", :collation => "koi8u_bin"},
|
163
|
+
77 => {:name => "latin2", :collation => "latin2_bin"},
|
164
|
+
78 => {:name => "latin5", :collation => "latin5_bin"},
|
165
|
+
79 => {:name => "latin7", :collation => "latin7_bin"},
|
166
|
+
80 => {:name => "cp850", :collation => "cp850_bin"},
|
167
|
+
81 => {:name => "cp852", :collation => "cp852_bin"},
|
168
|
+
82 => {:name => "swe7", :collation => "swe7_bin"},
|
169
|
+
83 => {:name => "utf8", :collation => "utf8_bin"},
|
170
|
+
84 => {:name => "big5", :collation => "big5_bin"},
|
171
|
+
85 => {:name => "euckr", :collation => "euckr_bin"},
|
172
|
+
86 => {:name => "gb2312", :collation => "gb2312_bin"},
|
173
|
+
87 => {:name => "gbk", :collation => "gbk_bin"},
|
174
|
+
88 => {:name => "sjis", :collation => "sjis_bin"},
|
175
|
+
89 => {:name => "tis620", :collation => "tis620_bin"},
|
176
|
+
90 => {:name => "ucs2", :collation => "ucs2_bin"},
|
177
|
+
91 => {:name => "ujis", :collation => "ujis_bin"},
|
178
|
+
92 => {:name => "geostd8", :collation => "geostd8_general_ci"},
|
179
|
+
93 => {:name => "geostd8", :collation => "geostd8_bin"},
|
180
|
+
94 => {:name => "latin1", :collation => "latin1_spanish_ci"},
|
181
|
+
95 => {:name => "cp932", :collation => "cp932_japanese_ci"},
|
182
|
+
96 => {:name => "cp932", :collation => "cp932_bin"},
|
183
|
+
97 => {:name => "eucjpms", :collation => "eucjpms_japanese_ci"},
|
184
|
+
98 => {:name => "eucjpms", :collation => "eucjpms_bin"},
|
185
|
+
99 => {:name => "cp1250", :collation => "cp1250_polish_ci"},
|
186
|
+
128 => {:name => "ucs2", :collation => "ucs2_unicode_ci"},
|
187
|
+
129 => {:name => "ucs2", :collation => "ucs2_icelandic_ci"},
|
188
|
+
130 => {:name => "ucs2", :collation => "ucs2_latvian_ci"},
|
189
|
+
131 => {:name => "ucs2", :collation => "ucs2_romanian_ci"},
|
190
|
+
132 => {:name => "ucs2", :collation => "ucs2_slovenian_ci"},
|
191
|
+
133 => {:name => "ucs2", :collation => "ucs2_polish_ci"},
|
192
|
+
134 => {:name => "ucs2", :collation => "ucs2_estonian_ci"},
|
193
|
+
135 => {:name => "ucs2", :collation => "ucs2_spanish_ci"},
|
194
|
+
136 => {:name => "ucs2", :collation => "ucs2_swedish_ci"},
|
195
|
+
137 => {:name => "ucs2", :collation => "ucs2_turkish_ci"},
|
196
|
+
138 => {:name => "ucs2", :collation => "ucs2_czech_ci"},
|
197
|
+
139 => {:name => "ucs2", :collation => "ucs2_danish_ci"},
|
198
|
+
140 => {:name => "ucs2", :collation => "ucs2_lithuanian_ci"},
|
199
|
+
141 => {:name => "ucs2", :collation => "ucs2_slovak_ci"},
|
200
|
+
142 => {:name => "ucs2", :collation => "ucs2_spanish2_ci"},
|
201
|
+
143 => {:name => "ucs2", :collation => "ucs2_roman_ci"},
|
202
|
+
144 => {:name => "ucs2", :collation => "ucs2_persian_ci"},
|
203
|
+
145 => {:name => "ucs2", :collation => "ucs2_esperanto_ci"},
|
204
|
+
146 => {:name => "ucs2", :collation => "ucs2_hungarian_ci"},
|
205
|
+
192 => {:name => "utf8", :collation => "utf8_unicode_ci"},
|
206
|
+
193 => {:name => "utf8", :collation => "utf8_icelandic_ci"},
|
207
|
+
194 => {:name => "utf8", :collation => "utf8_latvian_ci"},
|
208
|
+
195 => {:name => "utf8", :collation => "utf8_romanian_ci"},
|
209
|
+
196 => {:name => "utf8", :collation => "utf8_slovenian_ci"},
|
210
|
+
197 => {:name => "utf8", :collation => "utf8_polish_ci"},
|
211
|
+
198 => {:name => "utf8", :collation => "utf8_estonian_ci"},
|
212
|
+
199 => {:name => "utf8", :collation => "utf8_spanish_ci"},
|
213
|
+
200 => {:name => "utf8", :collation => "utf8_swedish_ci"},
|
214
|
+
201 => {:name => "utf8", :collation => "utf8_turkish_ci"},
|
215
|
+
202 => {:name => "utf8", :collation => "utf8_czech_ci"},
|
216
|
+
203 => {:name => "utf8", :collation => "utf8_danish_ci"},
|
217
|
+
204 => {:name => "utf8", :collation => "utf8_lithuanian_ci"},
|
218
|
+
205 => {:name => "utf8", :collation => "utf8_slovak_ci"},
|
219
|
+
206 => {:name => "utf8", :collation => "utf8_spanish2_ci"},
|
220
|
+
207 => {:name => "utf8", :collation => "utf8_roman_ci"},
|
221
|
+
208 => {:name => "utf8", :collation => "utf8_persian_ci"},
|
222
|
+
209 => {:name => "utf8", :collation => "utf8_esperanto_ci"},
|
223
|
+
210 => {:name => "utf8", :collation => "utf8_hungarian_ci"},
|
224
|
+
224 => {:name => "utf8mb4", :collation => "utf8mb4_unicode_ci"},
|
225
|
+
225 => {:name => "utf8mb4", :collation => "utf8mb4_icelandic_ci"},
|
226
|
+
226 => {:name => "utf8mb4", :collation => "utf8mb4_latvian_ci"},
|
227
|
+
227 => {:name => "utf8mb4", :collation => "utf8mb4_romanian_ci"},
|
228
|
+
228 => {:name => "utf8mb4", :collation => "utf8mb4_slovenian_ci"},
|
229
|
+
229 => {:name => "utf8mb4", :collation => "utf8mb4_polish_ci"},
|
230
|
+
230 => {:name => "utf8mb4", :collation => "utf8mb4_estonian_ci"},
|
231
|
+
231 => {:name => "utf8mb4", :collation => "utf8mb4_spanish_ci"},
|
232
|
+
232 => {:name => "utf8mb4", :collation => "utf8mb4_swedish_ci"},
|
233
|
+
233 => {:name => "utf8mb4", :collation => "utf8mb4_turkish_ci"},
|
234
|
+
234 => {:name => "utf8mb4", :collation => "utf8mb4_czech_ci"},
|
235
|
+
235 => {:name => "utf8mb4", :collation => "utf8mb4_danish_ci"},
|
236
|
+
236 => {:name => "utf8mb4", :collation => "utf8mb4_lithuanian_ci"},
|
237
|
+
237 => {:name => "utf8mb4", :collation => "utf8mb4_slovak_ci"},
|
238
|
+
238 => {:name => "utf8mb4", :collation => "utf8mb4_spanish2_ci"},
|
239
|
+
239 => {:name => "utf8mb4", :collation => "utf8mb4_roman_ci"},
|
240
|
+
240 => {:name => "utf8mb4", :collation => "utf8mb4_persian_ci"},
|
241
|
+
241 => {:name => "utf8mb4", :collation => "utf8mb4_esperanto_ci"},
|
242
|
+
242 => {:name => "utf8mb4", :collation => "utf8mb4_hungarian_ci"},
|
243
|
+
254 => {:name => "utf8", :collation => "utf8_general_cs"}
|
244
|
+
}
|
245
|
+
|
246
|
+
def self.encoding_from_charset(charset)
|
247
|
+
CHARSET_MAP[charset.to_s.downcase]
|
248
|
+
end
|
249
|
+
|
250
|
+
def self.encoding_from_charset_code(code)
|
251
|
+
if mapping = MYSQL_CHARSET_MAP[code]
|
252
|
+
encoding_from_charset(mapping[:name])
|
253
|
+
else
|
254
|
+
nil
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
private
|
260
|
+
def self.local_offset
|
261
|
+
::Time.local(2010).utc_offset.to_r / 86400
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
data/lib/mysql2/em.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'mysql2'
|
5
|
+
|
6
|
+
module Mysql2
|
7
|
+
module EM
|
8
|
+
class Client < ::Mysql2::Client
|
9
|
+
module Watcher
|
10
|
+
def initialize(client, deferable)
|
11
|
+
@client = client
|
12
|
+
@deferable = deferable
|
13
|
+
end
|
14
|
+
|
15
|
+
def notify_readable
|
16
|
+
detach
|
17
|
+
begin
|
18
|
+
@deferable.succeed(@client.async_result)
|
19
|
+
rescue Exception => e
|
20
|
+
@deferable.fail(e)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def query(sql, opts={})
|
26
|
+
if ::EM.reactor_running?
|
27
|
+
super(sql, opts.merge(:async => true))
|
28
|
+
deferable = ::EM::DefaultDeferrable.new
|
29
|
+
::EM.watch(self.socket, Watcher, self, deferable).notify_readable = true
|
30
|
+
deferable
|
31
|
+
else
|
32
|
+
super(sql, opts)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/mysql2/error.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Mysql2
|
2
|
+
class Error < StandardError
|
3
|
+
attr_accessor :error_number, :sql_state
|
4
|
+
|
5
|
+
def initialize msg
|
6
|
+
super
|
7
|
+
@error_number = nil
|
8
|
+
@sql_state = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
# Mysql gem compatibility
|
12
|
+
alias_method :errno, :error_number
|
13
|
+
alias_method :error, :message
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../lib/mysql2/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{solaris-mysql2}
|
5
|
+
s.version = Mysql2::VERSION
|
6
|
+
s.authors = ["Brian Lopez"]
|
7
|
+
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
8
|
+
s.email = %q{seniorlopez@gmail.com}
|
9
|
+
s.extensions = ["ext/mysql2/extconf.rb"]
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.homepage = %q{http://github.com/brianmario/mysql2}
|
12
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
13
|
+
s.require_paths = ["lib"]
|
14
|
+
s.rubygems_version = %q{1.4.2}
|
15
|
+
s.summary = %q{A simple, fast Mysql library for Ruby, binding to libmysql}
|
16
|
+
s.test_files = `git ls-files spec examples`.split("\n")
|
17
|
+
|
18
|
+
# tests
|
19
|
+
s.add_development_dependency 'eventmachine'
|
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
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
# benchmarks
|
24
|
+
s.add_development_dependency 'activerecord'
|
25
|
+
s.add_development_dependency 'mysql'
|
26
|
+
s.add_development_dependency 'do_mysql'
|
27
|
+
s.add_development_dependency 'sequel'
|
28
|
+
s.add_development_dependency 'faker'
|
29
|
+
end
|
data/spec/em/em_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
begin
|
4
|
+
require 'eventmachine'
|
5
|
+
require 'mysql2/em'
|
6
|
+
|
7
|
+
describe Mysql2::EM::Client do
|
8
|
+
it "should support async queries" do
|
9
|
+
results = []
|
10
|
+
EM.run do
|
11
|
+
client1 = Mysql2::EM::Client.new
|
12
|
+
defer1 = client1.query "SELECT sleep(0.1) as first_query"
|
13
|
+
defer1.callback do |result|
|
14
|
+
results << result.first
|
15
|
+
EM.stop_event_loop
|
16
|
+
end
|
17
|
+
|
18
|
+
client2 = Mysql2::EM::Client.new
|
19
|
+
defer2 = client2.query "SELECT sleep(0.025) second_query"
|
20
|
+
defer2.callback do |result|
|
21
|
+
results << result.first
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
results[0].keys.should include("second_query")
|
26
|
+
results[1].keys.should include("first_query")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should support queries in callbacks" do
|
30
|
+
results = []
|
31
|
+
EM.run do
|
32
|
+
client = Mysql2::EM::Client.new
|
33
|
+
defer1 = client.query "SELECT sleep(0.025) as first_query"
|
34
|
+
defer1.callback do |result|
|
35
|
+
results << result.first
|
36
|
+
defer2 = client.query "SELECT sleep(0.025) as second_query"
|
37
|
+
defer2.callback do |result|
|
38
|
+
results << result.first
|
39
|
+
EM.stop_event_loop
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
results[0].keys.should include("first_query")
|
45
|
+
results[1].keys.should include("second_query")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
rescue LoadError
|
49
|
+
puts "EventMachine not installed, skipping the specs that use it"
|
50
|
+
end
|