mysql2 0.2.6-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +117 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +240 -0
- data/Rakefile +5 -0
- data/VERSION +1 -0
- data/benchmark/active_record.rb +53 -0
- data/benchmark/allocations.rb +33 -0
- data/benchmark/escape.rb +39 -0
- data/benchmark/query_with_mysql_casting.rb +83 -0
- data/benchmark/query_without_mysql_casting.rb +50 -0
- data/benchmark/sequel.rb +39 -0
- data/benchmark/setup_db.rb +115 -0
- data/examples/eventmachine.rb +21 -0
- data/examples/threaded.rb +20 -0
- data/ext/mysql2/client.c +659 -0
- data/ext/mysql2/client.h +41 -0
- data/ext/mysql2/extconf.rb +65 -0
- data/ext/mysql2/mysql2_ext.c +12 -0
- data/ext/mysql2/mysql2_ext.h +32 -0
- data/ext/mysql2/result.c +475 -0
- data/ext/mysql2/result.h +20 -0
- data/lib/active_record/connection_adapters/em_mysql2_adapter.rb +63 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +654 -0
- data/lib/active_record/fiber_patches.rb +104 -0
- data/lib/arel/engines/sql/compilers/mysql2_compiler.rb +11 -0
- data/lib/mysql2.rb +16 -0
- data/lib/mysql2/client.rb +235 -0
- data/lib/mysql2/em.rb +33 -0
- data/lib/mysql2/error.rb +15 -0
- data/lib/mysql2/result.rb +5 -0
- data/mysql2.gemspec +89 -0
- data/spec/em/em_spec.rb +49 -0
- data/spec/mysql2/client_spec.rb +348 -0
- data/spec/mysql2/error_spec.rb +25 -0
- data/spec/mysql2/result_spec.rb +318 -0
- data/spec/rcov.opts +3 -0
- data/spec/spec_helper.rb +67 -0
- data/tasks/benchmarks.rake +8 -0
- data/tasks/compile.rake +54 -0
- data/tasks/jeweler.rake +17 -0
- data/tasks/rspec.rake +16 -0
- data/tasks/vendor_mysql.rake +41 -0
- metadata +120 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
# Necessary monkeypatching to make AR fiber-friendly.
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
|
6
|
+
def self.fiber_pools
|
7
|
+
@fiber_pools ||= []
|
8
|
+
end
|
9
|
+
def self.register_fiber_pool(fp)
|
10
|
+
fiber_pools << fp
|
11
|
+
end
|
12
|
+
|
13
|
+
class FiberedMonitor
|
14
|
+
class Queue
|
15
|
+
def initialize
|
16
|
+
@queue = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def wait(timeout)
|
20
|
+
t = timeout || 5
|
21
|
+
fiber = Fiber.current
|
22
|
+
x = EM::Timer.new(t) do
|
23
|
+
@queue.delete(fiber)
|
24
|
+
fiber.resume(false)
|
25
|
+
end
|
26
|
+
@queue << fiber
|
27
|
+
returning Fiber.yield do
|
28
|
+
x.cancel
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def signal
|
33
|
+
fiber = @queue.pop
|
34
|
+
fiber.resume(true) if fiber
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def synchronize
|
39
|
+
yield
|
40
|
+
end
|
41
|
+
|
42
|
+
def new_cond
|
43
|
+
Queue.new
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# ActiveRecord's connection pool is based on threads. Since we are working
|
48
|
+
# with EM and a single thread, multiple fiber design, we need to provide
|
49
|
+
# our own connection pool that keys off of Fiber.current so that different
|
50
|
+
# fibers running in the same thread don't try to use the same connection.
|
51
|
+
class ConnectionPool
|
52
|
+
def initialize(spec)
|
53
|
+
@spec = spec
|
54
|
+
|
55
|
+
# The cache of reserved connections mapped to threads
|
56
|
+
@reserved_connections = {}
|
57
|
+
|
58
|
+
# The mutex used to synchronize pool access
|
59
|
+
@connection_mutex = FiberedMonitor.new
|
60
|
+
@queue = @connection_mutex.new_cond
|
61
|
+
|
62
|
+
# default 5 second timeout unless on ruby 1.9
|
63
|
+
@timeout = spec.config[:wait_timeout] || 5
|
64
|
+
|
65
|
+
# default max pool size to 5
|
66
|
+
@size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
|
67
|
+
|
68
|
+
@connections = []
|
69
|
+
@checked_out = []
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def current_connection_id #:nodoc:
|
75
|
+
Fiber.current.object_id
|
76
|
+
end
|
77
|
+
|
78
|
+
# Remove stale fibers from the cache.
|
79
|
+
def remove_stale_cached_threads!(cache, &block)
|
80
|
+
keys = Set.new(cache.keys)
|
81
|
+
|
82
|
+
ActiveRecord::ConnectionAdapters.fiber_pools.each do |pool|
|
83
|
+
pool.busy_fibers.each_pair do |object_id, fiber|
|
84
|
+
keys.delete(object_id)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
keys.each do |key|
|
89
|
+
next unless cache.has_key?(key)
|
90
|
+
block.call(key, cache[key])
|
91
|
+
cache.delete(key)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def checkout_and_verify(c)
|
96
|
+
@checked_out << c
|
97
|
+
c.run_callbacks :checkout
|
98
|
+
c.verify!
|
99
|
+
c
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
data/lib/mysql2.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'date'
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'rational' unless RUBY_VERSION >= '1.9.2'
|
5
|
+
|
6
|
+
require 'mysql2/error'
|
7
|
+
require 'mysql2/mysql2'
|
8
|
+
require 'mysql2/client'
|
9
|
+
require 'mysql2/result'
|
10
|
+
|
11
|
+
# = Mysql2
|
12
|
+
#
|
13
|
+
# A modern, simple and very fast Mysql library for Ruby - binding to libmysql
|
14
|
+
module Mysql2
|
15
|
+
VERSION = "0.2.6"
|
16
|
+
end
|
@@ -0,0 +1,235 @@
|
|
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
|
+
}
|
14
|
+
|
15
|
+
def initialize(opts = {})
|
16
|
+
@query_options = @@default_query_options.dup
|
17
|
+
|
18
|
+
init_connection
|
19
|
+
|
20
|
+
[:reconnect, :connect_timeout].each do |key|
|
21
|
+
next unless opts.key?(key)
|
22
|
+
send(:"#{key}=", opts[key])
|
23
|
+
end
|
24
|
+
# force the encoding to utf8
|
25
|
+
self.charset_name = opts[:encoding] || 'utf8'
|
26
|
+
|
27
|
+
ssl_set(*opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslciper))
|
28
|
+
|
29
|
+
user = opts[:username]
|
30
|
+
pass = opts[:password]
|
31
|
+
host = opts[:host] || 'localhost'
|
32
|
+
port = opts[:port] || 3306
|
33
|
+
database = opts[:database]
|
34
|
+
socket = opts[:socket]
|
35
|
+
flags = opts[:flags] ? opts[:flags] | @query_options[:connect_flags] : @query_options[:connect_flags]
|
36
|
+
|
37
|
+
connect user, pass, host, port, database, socket, flags
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.default_query_options
|
41
|
+
@@default_query_options
|
42
|
+
end
|
43
|
+
|
44
|
+
# NOTE: from ruby-mysql
|
45
|
+
if defined? Encoding
|
46
|
+
CHARSET_MAP = {
|
47
|
+
"armscii8" => nil,
|
48
|
+
"ascii" => Encoding::US_ASCII,
|
49
|
+
"big5" => Encoding::Big5,
|
50
|
+
"binary" => Encoding::ASCII_8BIT,
|
51
|
+
"cp1250" => Encoding::Windows_1250,
|
52
|
+
"cp1251" => Encoding::Windows_1251,
|
53
|
+
"cp1256" => Encoding::Windows_1256,
|
54
|
+
"cp1257" => Encoding::Windows_1257,
|
55
|
+
"cp850" => Encoding::CP850,
|
56
|
+
"cp852" => Encoding::CP852,
|
57
|
+
"cp866" => Encoding::IBM866,
|
58
|
+
"cp932" => Encoding::Windows_31J,
|
59
|
+
"dec8" => nil,
|
60
|
+
"eucjpms" => Encoding::EucJP_ms,
|
61
|
+
"euckr" => Encoding::EUC_KR,
|
62
|
+
"gb2312" => Encoding::EUC_CN,
|
63
|
+
"gbk" => Encoding::GBK,
|
64
|
+
"geostd8" => nil,
|
65
|
+
"greek" => Encoding::ISO_8859_7,
|
66
|
+
"hebrew" => Encoding::ISO_8859_8,
|
67
|
+
"hp8" => nil,
|
68
|
+
"keybcs2" => nil,
|
69
|
+
"koi8r" => Encoding::KOI8_R,
|
70
|
+
"koi8u" => Encoding::KOI8_U,
|
71
|
+
"latin1" => Encoding::ISO_8859_1,
|
72
|
+
"latin2" => Encoding::ISO_8859_2,
|
73
|
+
"latin5" => Encoding::ISO_8859_9,
|
74
|
+
"latin7" => Encoding::ISO_8859_13,
|
75
|
+
"macce" => Encoding::MacCentEuro,
|
76
|
+
"macroman" => Encoding::MacRoman,
|
77
|
+
"sjis" => Encoding::SHIFT_JIS,
|
78
|
+
"swe7" => nil,
|
79
|
+
"tis620" => Encoding::TIS_620,
|
80
|
+
"ucs2" => Encoding::UTF_16BE,
|
81
|
+
"ujis" => Encoding::EucJP_ms,
|
82
|
+
"utf8" => Encoding::UTF_8,
|
83
|
+
}
|
84
|
+
|
85
|
+
MYSQL_CHARSET_MAP = {
|
86
|
+
1 => {:name => "big5", :collation => "big5_chinese_ci"},
|
87
|
+
2 => {:name => "latin2", :collation => "latin2_czech_cs"},
|
88
|
+
3 => {:name => "dec8", :collation => "dec8_swedish_ci"},
|
89
|
+
4 => {:name => "cp850", :collation => "cp850_general_ci"},
|
90
|
+
5 => {:name => "latin1", :collation => "latin1_german1_ci"},
|
91
|
+
6 => {:name => "hp8", :collation => "hp8_english_ci"},
|
92
|
+
7 => {:name => "koi8r", :collation => "koi8r_general_ci"},
|
93
|
+
8 => {:name => "latin1", :collation => "latin1_swedish_ci"},
|
94
|
+
9 => {:name => "latin2", :collation => "latin2_general_ci"},
|
95
|
+
10 => {:name => "swe7", :collation => "swe7_swedish_ci"},
|
96
|
+
11 => {:name => "ascii", :collation => "ascii_general_ci"},
|
97
|
+
12 => {:name => "ujis", :collation => "ujis_japanese_ci"},
|
98
|
+
13 => {:name => "sjis", :collation => "sjis_japanese_ci"},
|
99
|
+
14 => {:name => "cp1251", :collation => "cp1251_bulgarian_ci"},
|
100
|
+
15 => {:name => "latin1", :collation => "latin1_danish_ci"},
|
101
|
+
16 => {:name => "hebrew", :collation => "hebrew_general_ci"},
|
102
|
+
17 => {:name => "filename", :collation => "filename"},
|
103
|
+
18 => {:name => "tis620", :collation => "tis620_thai_ci"},
|
104
|
+
19 => {:name => "euckr", :collation => "euckr_korean_ci"},
|
105
|
+
20 => {:name => "latin7", :collation => "latin7_estonian_cs"},
|
106
|
+
21 => {:name => "latin2", :collation => "latin2_hungarian_ci"},
|
107
|
+
22 => {:name => "koi8u", :collation => "koi8u_general_ci"},
|
108
|
+
23 => {:name => "cp1251", :collation => "cp1251_ukrainian_ci"},
|
109
|
+
24 => {:name => "gb2312", :collation => "gb2312_chinese_ci"},
|
110
|
+
25 => {:name => "greek", :collation => "greek_general_ci"},
|
111
|
+
26 => {:name => "cp1250", :collation => "cp1250_general_ci"},
|
112
|
+
27 => {:name => "latin2", :collation => "latin2_croatian_ci"},
|
113
|
+
28 => {:name => "gbk", :collation => "gbk_chinese_ci"},
|
114
|
+
29 => {:name => "cp1257", :collation => "cp1257_lithuanian_ci"},
|
115
|
+
30 => {:name => "latin5", :collation => "latin5_turkish_ci"},
|
116
|
+
31 => {:name => "latin1", :collation => "latin1_german2_ci"},
|
117
|
+
32 => {:name => "armscii8", :collation => "armscii8_general_ci"},
|
118
|
+
33 => {:name => "utf8", :collation => "utf8_general_ci"},
|
119
|
+
34 => {:name => "cp1250", :collation => "cp1250_czech_cs"},
|
120
|
+
35 => {:name => "ucs2", :collation => "ucs2_general_ci"},
|
121
|
+
36 => {:name => "cp866", :collation => "cp866_general_ci"},
|
122
|
+
37 => {:name => "keybcs2", :collation => "keybcs2_general_ci"},
|
123
|
+
38 => {:name => "macce", :collation => "macce_general_ci"},
|
124
|
+
39 => {:name => "macroman", :collation => "macroman_general_ci"},
|
125
|
+
40 => {:name => "cp852", :collation => "cp852_general_ci"},
|
126
|
+
41 => {:name => "latin7", :collation => "latin7_general_ci"},
|
127
|
+
42 => {:name => "latin7", :collation => "latin7_general_cs"},
|
128
|
+
43 => {:name => "macce", :collation => "macce_bin"},
|
129
|
+
44 => {:name => "cp1250", :collation => "cp1250_croatian_ci"},
|
130
|
+
47 => {:name => "latin1", :collation => "latin1_bin"},
|
131
|
+
48 => {:name => "latin1", :collation => "latin1_general_ci"},
|
132
|
+
49 => {:name => "latin1", :collation => "latin1_general_cs"},
|
133
|
+
50 => {:name => "cp1251", :collation => "cp1251_bin"},
|
134
|
+
51 => {:name => "cp1251", :collation => "cp1251_general_ci"},
|
135
|
+
52 => {:name => "cp1251", :collation => "cp1251_general_cs"},
|
136
|
+
53 => {:name => "macroman", :collation => "macroman_bin"},
|
137
|
+
57 => {:name => "cp1256", :collation => "cp1256_general_ci"},
|
138
|
+
58 => {:name => "cp1257", :collation => "cp1257_bin"},
|
139
|
+
59 => {:name => "cp1257", :collation => "cp1257_general_ci"},
|
140
|
+
63 => {:name => "binary", :collation => "binary"},
|
141
|
+
64 => {:name => "armscii8", :collation => "armscii8_bin"},
|
142
|
+
65 => {:name => "ascii", :collation => "ascii_bin"},
|
143
|
+
66 => {:name => "cp1250", :collation => "cp1250_bin"},
|
144
|
+
67 => {:name => "cp1256", :collation => "cp1256_bin"},
|
145
|
+
68 => {:name => "cp866", :collation => "cp866_bin"},
|
146
|
+
69 => {:name => "dec8", :collation => "dec8_bin"},
|
147
|
+
70 => {:name => "greek", :collation => "greek_bin"},
|
148
|
+
71 => {:name => "hebrew", :collation => "hebrew_bin"},
|
149
|
+
72 => {:name => "hp8", :collation => "hp8_bin"},
|
150
|
+
73 => {:name => "keybcs2", :collation => "keybcs2_bin"},
|
151
|
+
74 => {:name => "koi8r", :collation => "koi8r_bin"},
|
152
|
+
75 => {:name => "koi8u", :collation => "koi8u_bin"},
|
153
|
+
77 => {:name => "latin2", :collation => "latin2_bin"},
|
154
|
+
78 => {:name => "latin5", :collation => "latin5_bin"},
|
155
|
+
79 => {:name => "latin7", :collation => "latin7_bin"},
|
156
|
+
80 => {:name => "cp850", :collation => "cp850_bin"},
|
157
|
+
81 => {:name => "cp852", :collation => "cp852_bin"},
|
158
|
+
82 => {:name => "swe7", :collation => "swe7_bin"},
|
159
|
+
83 => {:name => "utf8", :collation => "utf8_bin"},
|
160
|
+
84 => {:name => "big5", :collation => "big5_bin"},
|
161
|
+
85 => {:name => "euckr", :collation => "euckr_bin"},
|
162
|
+
86 => {:name => "gb2312", :collation => "gb2312_bin"},
|
163
|
+
87 => {:name => "gbk", :collation => "gbk_bin"},
|
164
|
+
88 => {:name => "sjis", :collation => "sjis_bin"},
|
165
|
+
89 => {:name => "tis620", :collation => "tis620_bin"},
|
166
|
+
90 => {:name => "ucs2", :collation => "ucs2_bin"},
|
167
|
+
91 => {:name => "ujis", :collation => "ujis_bin"},
|
168
|
+
92 => {:name => "geostd8", :collation => "geostd8_general_ci"},
|
169
|
+
93 => {:name => "geostd8", :collation => "geostd8_bin"},
|
170
|
+
94 => {:name => "latin1", :collation => "latin1_spanish_ci"},
|
171
|
+
95 => {:name => "cp932", :collation => "cp932_japanese_ci"},
|
172
|
+
96 => {:name => "cp932", :collation => "cp932_bin"},
|
173
|
+
97 => {:name => "eucjpms", :collation => "eucjpms_japanese_ci"},
|
174
|
+
98 => {:name => "eucjpms", :collation => "eucjpms_bin"},
|
175
|
+
99 => {:name => "cp1250", :collation => "cp1250_polish_ci"},
|
176
|
+
128 => {:name => "ucs2", :collation => "ucs2_unicode_ci"},
|
177
|
+
129 => {:name => "ucs2", :collation => "ucs2_icelandic_ci"},
|
178
|
+
130 => {:name => "ucs2", :collation => "ucs2_latvian_ci"},
|
179
|
+
131 => {:name => "ucs2", :collation => "ucs2_romanian_ci"},
|
180
|
+
132 => {:name => "ucs2", :collation => "ucs2_slovenian_ci"},
|
181
|
+
133 => {:name => "ucs2", :collation => "ucs2_polish_ci"},
|
182
|
+
134 => {:name => "ucs2", :collation => "ucs2_estonian_ci"},
|
183
|
+
135 => {:name => "ucs2", :collation => "ucs2_spanish_ci"},
|
184
|
+
136 => {:name => "ucs2", :collation => "ucs2_swedish_ci"},
|
185
|
+
137 => {:name => "ucs2", :collation => "ucs2_turkish_ci"},
|
186
|
+
138 => {:name => "ucs2", :collation => "ucs2_czech_ci"},
|
187
|
+
139 => {:name => "ucs2", :collation => "ucs2_danish_ci"},
|
188
|
+
140 => {:name => "ucs2", :collation => "ucs2_lithuanian_ci"},
|
189
|
+
141 => {:name => "ucs2", :collation => "ucs2_slovak_ci"},
|
190
|
+
142 => {:name => "ucs2", :collation => "ucs2_spanish2_ci"},
|
191
|
+
143 => {:name => "ucs2", :collation => "ucs2_roman_ci"},
|
192
|
+
144 => {:name => "ucs2", :collation => "ucs2_persian_ci"},
|
193
|
+
145 => {:name => "ucs2", :collation => "ucs2_esperanto_ci"},
|
194
|
+
146 => {:name => "ucs2", :collation => "ucs2_hungarian_ci"},
|
195
|
+
192 => {:name => "utf8", :collation => "utf8_unicode_ci"},
|
196
|
+
193 => {:name => "utf8", :collation => "utf8_icelandic_ci"},
|
197
|
+
194 => {:name => "utf8", :collation => "utf8_latvian_ci"},
|
198
|
+
195 => {:name => "utf8", :collation => "utf8_romanian_ci"},
|
199
|
+
196 => {:name => "utf8", :collation => "utf8_slovenian_ci"},
|
200
|
+
197 => {:name => "utf8", :collation => "utf8_polish_ci"},
|
201
|
+
198 => {:name => "utf8", :collation => "utf8_estonian_ci"},
|
202
|
+
199 => {:name => "utf8", :collation => "utf8_spanish_ci"},
|
203
|
+
200 => {:name => "utf8", :collation => "utf8_swedish_ci"},
|
204
|
+
201 => {:name => "utf8", :collation => "utf8_turkish_ci"},
|
205
|
+
202 => {:name => "utf8", :collation => "utf8_czech_ci"},
|
206
|
+
203 => {:name => "utf8", :collation => "utf8_danish_ci"},
|
207
|
+
204 => {:name => "utf8", :collation => "utf8_lithuanian_ci"},
|
208
|
+
205 => {:name => "utf8", :collation => "utf8_slovak_ci"},
|
209
|
+
206 => {:name => "utf8", :collation => "utf8_spanish2_ci"},
|
210
|
+
207 => {:name => "utf8", :collation => "utf8_roman_ci"},
|
211
|
+
208 => {:name => "utf8", :collation => "utf8_persian_ci"},
|
212
|
+
209 => {:name => "utf8", :collation => "utf8_esperanto_ci"},
|
213
|
+
210 => {:name => "utf8", :collation => "utf8_hungarian_ci"},
|
214
|
+
254 => {:name => "utf8", :collation => "utf8_general_cs"}
|
215
|
+
}
|
216
|
+
|
217
|
+
def self.encoding_from_charset(charset)
|
218
|
+
CHARSET_MAP[charset.to_s.downcase]
|
219
|
+
end
|
220
|
+
|
221
|
+
def self.encoding_from_charset_code(code)
|
222
|
+
if mapping = MYSQL_CHARSET_MAP[code]
|
223
|
+
encoding_from_charset(mapping[:name])
|
224
|
+
else
|
225
|
+
nil
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
private
|
231
|
+
def self.local_offset
|
232
|
+
::Time.local(2010).utc_offset.to_r / 86400
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
data/lib/mysql2/em.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'eventmachine' unless defined? EventMachine
|
4
|
+
require 'mysql2' unless defined? 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
|
+
super(sql, opts.merge(:async => true))
|
27
|
+
deferable = ::EM::DefaultDeferrable.new
|
28
|
+
::EM.watch(self.socket, Watcher, self, deferable).notify_readable = true
|
29
|
+
deferable
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
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
|
data/mysql2.gemspec
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mysql2}
|
8
|
+
s.version = "0.2.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Brian Lopez"]
|
12
|
+
s.date = %q{2010-10-19}
|
13
|
+
s.email = %q{seniorlopez@gmail.com}
|
14
|
+
s.extensions = ["ext/mysql2/extconf.rb"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
".rspec",
|
21
|
+
"CHANGELOG.md",
|
22
|
+
"MIT-LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"benchmark/active_record.rb",
|
27
|
+
"benchmark/allocations.rb",
|
28
|
+
"benchmark/escape.rb",
|
29
|
+
"benchmark/query_with_mysql_casting.rb",
|
30
|
+
"benchmark/query_without_mysql_casting.rb",
|
31
|
+
"benchmark/sequel.rb",
|
32
|
+
"benchmark/setup_db.rb",
|
33
|
+
"examples/eventmachine.rb",
|
34
|
+
"examples/threaded.rb",
|
35
|
+
"ext/mysql2/client.c",
|
36
|
+
"ext/mysql2/client.h",
|
37
|
+
"ext/mysql2/extconf.rb",
|
38
|
+
"ext/mysql2/mysql2_ext.c",
|
39
|
+
"ext/mysql2/mysql2_ext.h",
|
40
|
+
"ext/mysql2/result.c",
|
41
|
+
"ext/mysql2/result.h",
|
42
|
+
"lib/active_record/connection_adapters/em_mysql2_adapter.rb",
|
43
|
+
"lib/active_record/connection_adapters/mysql2_adapter.rb",
|
44
|
+
"lib/active_record/fiber_patches.rb",
|
45
|
+
"lib/arel/engines/sql/compilers/mysql2_compiler.rb",
|
46
|
+
"lib/mysql2.rb",
|
47
|
+
"lib/mysql2/client.rb",
|
48
|
+
"lib/mysql2/em.rb",
|
49
|
+
"lib/mysql2/error.rb",
|
50
|
+
"lib/mysql2/result.rb",
|
51
|
+
"mysql2.gemspec",
|
52
|
+
"spec/em/em_spec.rb",
|
53
|
+
"spec/mysql2/client_spec.rb",
|
54
|
+
"spec/mysql2/error_spec.rb",
|
55
|
+
"spec/mysql2/result_spec.rb",
|
56
|
+
"spec/rcov.opts",
|
57
|
+
"spec/spec_helper.rb",
|
58
|
+
"tasks/benchmarks.rake",
|
59
|
+
"tasks/compile.rake",
|
60
|
+
"tasks/jeweler.rake",
|
61
|
+
"tasks/rspec.rake",
|
62
|
+
"tasks/vendor_mysql.rake"
|
63
|
+
]
|
64
|
+
s.homepage = %q{http://github.com/brianmario/mysql2}
|
65
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
66
|
+
s.require_paths = ["lib", "ext"]
|
67
|
+
s.rubygems_version = %q{1.3.7}
|
68
|
+
s.summary = %q{A simple, fast Mysql library for Ruby, binding to libmysql}
|
69
|
+
s.test_files = [
|
70
|
+
"spec/em/em_spec.rb",
|
71
|
+
"spec/mysql2/client_spec.rb",
|
72
|
+
"spec/mysql2/error_spec.rb",
|
73
|
+
"spec/mysql2/result_spec.rb",
|
74
|
+
"spec/spec_helper.rb",
|
75
|
+
"examples/eventmachine.rb",
|
76
|
+
"examples/threaded.rb"
|
77
|
+
]
|
78
|
+
|
79
|
+
if s.respond_to? :specification_version then
|
80
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
81
|
+
s.specification_version = 3
|
82
|
+
|
83
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
84
|
+
else
|
85
|
+
end
|
86
|
+
else
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|