mysql2 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +16 -0
- data/README.rdoc +12 -4
- data/Rakefile +10 -3
- data/VERSION +1 -1
- data/benchmark/active_record.rb +0 -1
- data/benchmark/escape.rb +2 -2
- data/benchmark/query_with_mysql_casting.rb +2 -2
- data/benchmark/query_without_mysql_casting.rb +2 -2
- data/benchmark/sequel.rb +0 -1
- data/benchmark/setup_db.rb +2 -2
- data/ext/{extconf.rb → mysql2/extconf.rb} +11 -31
- data/ext/mysql2/mysql2_ext.c +496 -0
- data/ext/{mysql2_ext.h → mysql2/mysql2_ext.h} +11 -39
- data/ext/mysql2/result.c +340 -0
- data/ext/mysql2/result.h +7 -0
- data/lib/active_record/connection_adapters/em_mysql2_adapter.rb +59 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +7 -7
- data/lib/active_record/fiber_patches.rb +104 -0
- data/lib/mysql2.rb +9 -3
- data/lib/mysql2/client.rb +211 -0
- data/lib/mysql2/error.rb +11 -0
- data/lib/mysql2/result.rb +5 -0
- data/lib/sequel/adapters/mysql2.rb +2 -3
- data/mysql2.gemspec +15 -8
- data/spec/active_record/active_record_spec.rb +6 -4
- data/spec/em/em_spec.rb +2 -2
- data/spec/mysql2/client_spec.rb +48 -2
- data/spec/mysql2/error_spec.rb +2 -2
- data/spec/mysql2/result_spec.rb +127 -3
- metadata +20 -8
- data/ext/mysql2_ext.c +0 -748
@@ -5,6 +5,7 @@ require 'mysql2' unless defined? Mysql2
|
|
5
5
|
module ActiveRecord
|
6
6
|
class Base
|
7
7
|
def self.mysql2_connection(config)
|
8
|
+
config[:username] = 'root' if config[:username].nil?
|
8
9
|
client = Mysql2::Client.new(config.symbolize_keys)
|
9
10
|
options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
|
10
11
|
ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config)
|
@@ -57,8 +58,8 @@ module ActiveRecord
|
|
57
58
|
when :integer then value.to_i rescue value ? 1 : 0
|
58
59
|
when :float then value.to_f # returns self if it's already a Float
|
59
60
|
when :decimal then self.class.value_to_decimal(value)
|
60
|
-
when :datetime, :timestamp then value.class == Time ? value
|
61
|
-
when :time then value.class == Time ? value
|
61
|
+
when :datetime, :timestamp then value.class == Time ? value : self.class.string_to_time(value)
|
62
|
+
when :time then value.class == Time ? value : self.class.string_to_dummy_time(value)
|
62
63
|
when :date then value.class == Date ? value : self.class.string_to_date(value)
|
63
64
|
when :binary then value
|
64
65
|
when :boolean then self.class.value_to_boolean(value)
|
@@ -73,8 +74,8 @@ module ActiveRecord
|
|
73
74
|
when :integer then "#{var_name}.to_i rescue #{var_name} ? 1 : 0"
|
74
75
|
when :float then "#{var_name}.to_f"
|
75
76
|
when :decimal then "#{self.class.name}.value_to_decimal(#{var_name})"
|
76
|
-
when :datetime, :timestamp then "#{var_name}.class == Time ? #{var_name}
|
77
|
-
when :time then "#{var_name}.class == Time ? #{var_name}
|
77
|
+
when :datetime, :timestamp then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_time(#{var_name})"
|
78
|
+
when :time then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_dummy_time(#{var_name})"
|
78
79
|
when :date then "#{var_name}.class == Date ? #{var_name} : #{self.class.name}.string_to_date(#{var_name})"
|
79
80
|
when :binary then nil
|
80
81
|
when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})"
|
@@ -255,12 +256,11 @@ module ActiveRecord
|
|
255
256
|
# DATABASE STATEMENTS ======================================
|
256
257
|
|
257
258
|
def select_values(sql, name = nil)
|
258
|
-
|
259
|
-
result.map { |row| row.values.first }
|
259
|
+
select(sql, name).map { |row| row.values.first }
|
260
260
|
end
|
261
261
|
|
262
262
|
def select_rows(sql, name = nil)
|
263
|
-
select(sql, name)
|
263
|
+
select(sql, name).map { |row| row.values }
|
264
264
|
end
|
265
265
|
|
266
266
|
# Executes a SQL query and returns a MySQL::Result object. Note that you have to free the Result object after you're done using it.
|
@@ -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
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require '
|
2
|
+
require 'date'
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
require 'mysql2/error'
|
6
|
+
require 'mysql2/mysql2'
|
7
|
+
require 'mysql2/client'
|
8
|
+
require 'mysql2/result'
|
3
9
|
|
4
10
|
# = Mysql2
|
5
11
|
#
|
6
12
|
# A modern, simple and very fast Mysql library for Ruby - binding to libmysql
|
7
13
|
module Mysql2
|
8
|
-
VERSION = "0.1.
|
9
|
-
end
|
14
|
+
VERSION = "0.1.9"
|
15
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
module Mysql2
|
2
|
+
class Client
|
3
|
+
def initialize opts = {}
|
4
|
+
init_connection
|
5
|
+
|
6
|
+
[:reconnect, :connect_timeout].each do |key|
|
7
|
+
next unless opts.key?(key)
|
8
|
+
send(:"#{key}=", opts[key])
|
9
|
+
end
|
10
|
+
# force the encoding to utf8
|
11
|
+
self.charset_name = opts[:encoding] || 'utf8'
|
12
|
+
|
13
|
+
ssl_set(*opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslciper))
|
14
|
+
|
15
|
+
user = opts[:username]
|
16
|
+
pass = opts[:password]
|
17
|
+
host = opts[:host] || 'localhost'
|
18
|
+
port = opts[:port] || 3306
|
19
|
+
database = opts[:database]
|
20
|
+
socket = opts[:socket]
|
21
|
+
|
22
|
+
connect user, pass, host, port, database, socket
|
23
|
+
end
|
24
|
+
|
25
|
+
# NOTE: from ruby-mysql
|
26
|
+
if defined? Encoding
|
27
|
+
CHARSET_MAP = {
|
28
|
+
"armscii8" => nil,
|
29
|
+
"ascii" => Encoding::US_ASCII,
|
30
|
+
"big5" => Encoding::Big5,
|
31
|
+
"binary" => Encoding::ASCII_8BIT,
|
32
|
+
"cp1250" => Encoding::Windows_1250,
|
33
|
+
"cp1251" => Encoding::Windows_1251,
|
34
|
+
"cp1256" => Encoding::Windows_1256,
|
35
|
+
"cp1257" => Encoding::Windows_1257,
|
36
|
+
"cp850" => Encoding::CP850,
|
37
|
+
"cp852" => Encoding::CP852,
|
38
|
+
"cp866" => Encoding::IBM866,
|
39
|
+
"cp932" => Encoding::Windows_31J,
|
40
|
+
"dec8" => nil,
|
41
|
+
"eucjpms" => Encoding::EucJP_ms,
|
42
|
+
"euckr" => Encoding::EUC_KR,
|
43
|
+
"gb2312" => Encoding::EUC_CN,
|
44
|
+
"gbk" => Encoding::GBK,
|
45
|
+
"geostd8" => nil,
|
46
|
+
"greek" => Encoding::ISO_8859_7,
|
47
|
+
"hebrew" => Encoding::ISO_8859_8,
|
48
|
+
"hp8" => nil,
|
49
|
+
"keybcs2" => nil,
|
50
|
+
"koi8r" => Encoding::KOI8_R,
|
51
|
+
"koi8u" => Encoding::KOI8_U,
|
52
|
+
"latin1" => Encoding::ISO_8859_1,
|
53
|
+
"latin2" => Encoding::ISO_8859_2,
|
54
|
+
"latin5" => Encoding::ISO_8859_9,
|
55
|
+
"latin7" => Encoding::ISO_8859_13,
|
56
|
+
"macce" => Encoding::MacCentEuro,
|
57
|
+
"macroman" => Encoding::MacRoman,
|
58
|
+
"sjis" => Encoding::SHIFT_JIS,
|
59
|
+
"swe7" => nil,
|
60
|
+
"tis620" => Encoding::TIS_620,
|
61
|
+
"ucs2" => Encoding::UTF_16BE,
|
62
|
+
"ujis" => Encoding::EucJP_ms,
|
63
|
+
"utf8" => Encoding::UTF_8,
|
64
|
+
}
|
65
|
+
|
66
|
+
MYSQL_CHARSET_MAP = {
|
67
|
+
1 => {:name => "big5", :collation => "big5_chinese_ci"},
|
68
|
+
2 => {:name => "latin2", :collation => "latin2_czech_cs"},
|
69
|
+
3 => {:name => "dec8", :collation => "dec8_swedish_ci"},
|
70
|
+
4 => {:name => "cp850", :collation => "cp850_general_ci"},
|
71
|
+
5 => {:name => "latin1", :collation => "latin1_german1_ci"},
|
72
|
+
6 => {:name => "hp8", :collation => "hp8_english_ci"},
|
73
|
+
7 => {:name => "koi8r", :collation => "koi8r_general_ci"},
|
74
|
+
8 => {:name => "latin1", :collation => "latin1_swedish_ci"},
|
75
|
+
9 => {:name => "latin2", :collation => "latin2_general_ci"},
|
76
|
+
10 => {:name => "swe7", :collation => "swe7_swedish_ci"},
|
77
|
+
11 => {:name => "ascii", :collation => "ascii_general_ci"},
|
78
|
+
12 => {:name => "ujis", :collation => "ujis_japanese_ci"},
|
79
|
+
13 => {:name => "sjis", :collation => "sjis_japanese_ci"},
|
80
|
+
14 => {:name => "cp1251", :collation => "cp1251_bulgarian_ci"},
|
81
|
+
15 => {:name => "latin1", :collation => "latin1_danish_ci"},
|
82
|
+
16 => {:name => "hebrew", :collation => "hebrew_general_ci"},
|
83
|
+
17 => {:name => "filename", :collation => "filename"},
|
84
|
+
18 => {:name => "tis620", :collation => "tis620_thai_ci"},
|
85
|
+
19 => {:name => "euckr", :collation => "euckr_korean_ci"},
|
86
|
+
20 => {:name => "latin7", :collation => "latin7_estonian_cs"},
|
87
|
+
21 => {:name => "latin2", :collation => "latin2_hungarian_ci"},
|
88
|
+
22 => {:name => "koi8u", :collation => "koi8u_general_ci"},
|
89
|
+
23 => {:name => "cp1251", :collation => "cp1251_ukrainian_ci"},
|
90
|
+
24 => {:name => "gb2312", :collation => "gb2312_chinese_ci"},
|
91
|
+
25 => {:name => "greek", :collation => "greek_general_ci"},
|
92
|
+
26 => {:name => "cp1250", :collation => "cp1250_general_ci"},
|
93
|
+
27 => {:name => "latin2", :collation => "latin2_croatian_ci"},
|
94
|
+
28 => {:name => "gbk", :collation => "gbk_chinese_ci"},
|
95
|
+
29 => {:name => "cp1257", :collation => "cp1257_lithuanian_ci"},
|
96
|
+
30 => {:name => "latin5", :collation => "latin5_turkish_ci"},
|
97
|
+
31 => {:name => "latin1", :collation => "latin1_german2_ci"},
|
98
|
+
32 => {:name => "armscii8", :collation => "armscii8_general_ci"},
|
99
|
+
33 => {:name => "utf8", :collation => "utf8_general_ci"},
|
100
|
+
34 => {:name => "cp1250", :collation => "cp1250_czech_cs"},
|
101
|
+
35 => {:name => "ucs2", :collation => "ucs2_general_ci"},
|
102
|
+
36 => {:name => "cp866", :collation => "cp866_general_ci"},
|
103
|
+
37 => {:name => "keybcs2", :collation => "keybcs2_general_ci"},
|
104
|
+
38 => {:name => "macce", :collation => "macce_general_ci"},
|
105
|
+
39 => {:name => "macroman", :collation => "macroman_general_ci"},
|
106
|
+
40 => {:name => "cp852", :collation => "cp852_general_ci"},
|
107
|
+
41 => {:name => "latin7", :collation => "latin7_general_ci"},
|
108
|
+
42 => {:name => "latin7", :collation => "latin7_general_cs"},
|
109
|
+
43 => {:name => "macce", :collation => "macce_bin"},
|
110
|
+
44 => {:name => "cp1250", :collation => "cp1250_croatian_ci"},
|
111
|
+
47 => {:name => "latin1", :collation => "latin1_bin"},
|
112
|
+
48 => {:name => "latin1", :collation => "latin1_general_ci"},
|
113
|
+
49 => {:name => "latin1", :collation => "latin1_general_cs"},
|
114
|
+
50 => {:name => "cp1251", :collation => "cp1251_bin"},
|
115
|
+
51 => {:name => "cp1251", :collation => "cp1251_general_ci"},
|
116
|
+
52 => {:name => "cp1251", :collation => "cp1251_general_cs"},
|
117
|
+
53 => {:name => "macroman", :collation => "macroman_bin"},
|
118
|
+
57 => {:name => "cp1256", :collation => "cp1256_general_ci"},
|
119
|
+
58 => {:name => "cp1257", :collation => "cp1257_bin"},
|
120
|
+
59 => {:name => "cp1257", :collation => "cp1257_general_ci"},
|
121
|
+
63 => {:name => "binary", :collation => "binary"},
|
122
|
+
64 => {:name => "armscii8", :collation => "armscii8_bin"},
|
123
|
+
65 => {:name => "ascii", :collation => "ascii_bin"},
|
124
|
+
66 => {:name => "cp1250", :collation => "cp1250_bin"},
|
125
|
+
67 => {:name => "cp1256", :collation => "cp1256_bin"},
|
126
|
+
68 => {:name => "cp866", :collation => "cp866_bin"},
|
127
|
+
69 => {:name => "dec8", :collation => "dec8_bin"},
|
128
|
+
70 => {:name => "greek", :collation => "greek_bin"},
|
129
|
+
71 => {:name => "hebrew", :collation => "hebrew_bin"},
|
130
|
+
72 => {:name => "hp8", :collation => "hp8_bin"},
|
131
|
+
73 => {:name => "keybcs2", :collation => "keybcs2_bin"},
|
132
|
+
74 => {:name => "koi8r", :collation => "koi8r_bin"},
|
133
|
+
75 => {:name => "koi8u", :collation => "koi8u_bin"},
|
134
|
+
77 => {:name => "latin2", :collation => "latin2_bin"},
|
135
|
+
78 => {:name => "latin5", :collation => "latin5_bin"},
|
136
|
+
79 => {:name => "latin7", :collation => "latin7_bin"},
|
137
|
+
80 => {:name => "cp850", :collation => "cp850_bin"},
|
138
|
+
81 => {:name => "cp852", :collation => "cp852_bin"},
|
139
|
+
82 => {:name => "swe7", :collation => "swe7_bin"},
|
140
|
+
83 => {:name => "utf8", :collation => "utf8_bin"},
|
141
|
+
84 => {:name => "big5", :collation => "big5_bin"},
|
142
|
+
85 => {:name => "euckr", :collation => "euckr_bin"},
|
143
|
+
86 => {:name => "gb2312", :collation => "gb2312_bin"},
|
144
|
+
87 => {:name => "gbk", :collation => "gbk_bin"},
|
145
|
+
88 => {:name => "sjis", :collation => "sjis_bin"},
|
146
|
+
89 => {:name => "tis620", :collation => "tis620_bin"},
|
147
|
+
90 => {:name => "ucs2", :collation => "ucs2_bin"},
|
148
|
+
91 => {:name => "ujis", :collation => "ujis_bin"},
|
149
|
+
92 => {:name => "geostd8", :collation => "geostd8_general_ci"},
|
150
|
+
93 => {:name => "geostd8", :collation => "geostd8_bin"},
|
151
|
+
94 => {:name => "latin1", :collation => "latin1_spanish_ci"},
|
152
|
+
95 => {:name => "cp932", :collation => "cp932_japanese_ci"},
|
153
|
+
96 => {:name => "cp932", :collation => "cp932_bin"},
|
154
|
+
97 => {:name => "eucjpms", :collation => "eucjpms_japanese_ci"},
|
155
|
+
98 => {:name => "eucjpms", :collation => "eucjpms_bin"},
|
156
|
+
99 => {:name => "cp1250", :collation => "cp1250_polish_ci"},
|
157
|
+
128 => {:name => "ucs2", :collation => "ucs2_unicode_ci"},
|
158
|
+
129 => {:name => "ucs2", :collation => "ucs2_icelandic_ci"},
|
159
|
+
130 => {:name => "ucs2", :collation => "ucs2_latvian_ci"},
|
160
|
+
131 => {:name => "ucs2", :collation => "ucs2_romanian_ci"},
|
161
|
+
132 => {:name => "ucs2", :collation => "ucs2_slovenian_ci"},
|
162
|
+
133 => {:name => "ucs2", :collation => "ucs2_polish_ci"},
|
163
|
+
134 => {:name => "ucs2", :collation => "ucs2_estonian_ci"},
|
164
|
+
135 => {:name => "ucs2", :collation => "ucs2_spanish_ci"},
|
165
|
+
136 => {:name => "ucs2", :collation => "ucs2_swedish_ci"},
|
166
|
+
137 => {:name => "ucs2", :collation => "ucs2_turkish_ci"},
|
167
|
+
138 => {:name => "ucs2", :collation => "ucs2_czech_ci"},
|
168
|
+
139 => {:name => "ucs2", :collation => "ucs2_danish_ci"},
|
169
|
+
140 => {:name => "ucs2", :collation => "ucs2_lithuanian_ci"},
|
170
|
+
141 => {:name => "ucs2", :collation => "ucs2_slovak_ci"},
|
171
|
+
142 => {:name => "ucs2", :collation => "ucs2_spanish2_ci"},
|
172
|
+
143 => {:name => "ucs2", :collation => "ucs2_roman_ci"},
|
173
|
+
144 => {:name => "ucs2", :collation => "ucs2_persian_ci"},
|
174
|
+
145 => {:name => "ucs2", :collation => "ucs2_esperanto_ci"},
|
175
|
+
146 => {:name => "ucs2", :collation => "ucs2_hungarian_ci"},
|
176
|
+
192 => {:name => "utf8", :collation => "utf8_unicode_ci"},
|
177
|
+
193 => {:name => "utf8", :collation => "utf8_icelandic_ci"},
|
178
|
+
194 => {:name => "utf8", :collation => "utf8_latvian_ci"},
|
179
|
+
195 => {:name => "utf8", :collation => "utf8_romanian_ci"},
|
180
|
+
196 => {:name => "utf8", :collation => "utf8_slovenian_ci"},
|
181
|
+
197 => {:name => "utf8", :collation => "utf8_polish_ci"},
|
182
|
+
198 => {:name => "utf8", :collation => "utf8_estonian_ci"},
|
183
|
+
199 => {:name => "utf8", :collation => "utf8_spanish_ci"},
|
184
|
+
200 => {:name => "utf8", :collation => "utf8_swedish_ci"},
|
185
|
+
201 => {:name => "utf8", :collation => "utf8_turkish_ci"},
|
186
|
+
202 => {:name => "utf8", :collation => "utf8_czech_ci"},
|
187
|
+
203 => {:name => "utf8", :collation => "utf8_danish_ci"},
|
188
|
+
204 => {:name => "utf8", :collation => "utf8_lithuanian_ci"},
|
189
|
+
205 => {:name => "utf8", :collation => "utf8_slovak_ci"},
|
190
|
+
206 => {:name => "utf8", :collation => "utf8_spanish2_ci"},
|
191
|
+
207 => {:name => "utf8", :collation => "utf8_roman_ci"},
|
192
|
+
208 => {:name => "utf8", :collation => "utf8_persian_ci"},
|
193
|
+
209 => {:name => "utf8", :collation => "utf8_esperanto_ci"},
|
194
|
+
210 => {:name => "utf8", :collation => "utf8_hungarian_ci"},
|
195
|
+
254 => {:name => "utf8", :collation => "utf8_general_cs"}
|
196
|
+
}
|
197
|
+
|
198
|
+
def self.encoding_from_charset(charset)
|
199
|
+
CHARSET_MAP[charset.to_s.downcase]
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.encoding_from_charset_code(code)
|
203
|
+
if mapping = MYSQL_CHARSET_MAP[code]
|
204
|
+
encoding_from_charset(mapping[:name])
|
205
|
+
else
|
206
|
+
nil
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
data/lib/mysql2/error.rb
ADDED
@@ -120,8 +120,7 @@ module Sequel
|
|
120
120
|
# yield the connection if a block is given.
|
121
121
|
def _execute(conn, sql, opts)
|
122
122
|
begin
|
123
|
-
|
124
|
-
r = conn.query(sql)
|
123
|
+
r = log_yield(sql){conn.query(sql)}
|
125
124
|
if opts[:type] == :select
|
126
125
|
yield r if r
|
127
126
|
elsif block_given?
|
@@ -191,7 +190,7 @@ module Sequel
|
|
191
190
|
# instead of yielding results for all statements as hashes.
|
192
191
|
def fetch_rows(sql, &block)
|
193
192
|
execute(sql) do |r|
|
194
|
-
r.each &block
|
193
|
+
r.each(:symbolize_keys => true, &block)
|
195
194
|
end
|
196
195
|
self
|
197
196
|
end
|
data/mysql2.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mysql2}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.9"
|
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-
|
12
|
+
s.date = %q{2010-07-17}
|
13
13
|
s.email = %q{seniorlopez@gmail.com}
|
14
|
-
s.extensions = ["ext/extconf.rb"]
|
14
|
+
s.extensions = ["ext/mysql2/extconf.rb"]
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.rdoc"
|
17
17
|
]
|
@@ -29,13 +29,20 @@ Gem::Specification.new do |s|
|
|
29
29
|
"benchmark/sequel.rb",
|
30
30
|
"benchmark/setup_db.rb",
|
31
31
|
"examples/eventmachine.rb",
|
32
|
-
"ext/extconf.rb",
|
33
|
-
"ext/mysql2_ext.c",
|
34
|
-
"ext/mysql2_ext.h",
|
32
|
+
"ext/mysql2/extconf.rb",
|
33
|
+
"ext/mysql2/mysql2_ext.c",
|
34
|
+
"ext/mysql2/mysql2_ext.h",
|
35
|
+
"ext/mysql2/result.c",
|
36
|
+
"ext/mysql2/result.h",
|
37
|
+
"lib/active_record/connection_adapters/em_mysql2_adapter.rb",
|
35
38
|
"lib/active_record/connection_adapters/mysql2_adapter.rb",
|
39
|
+
"lib/active_record/fiber_patches.rb",
|
36
40
|
"lib/arel/engines/sql/compilers/mysql2_compiler.rb",
|
37
41
|
"lib/mysql2.rb",
|
42
|
+
"lib/mysql2/client.rb",
|
38
43
|
"lib/mysql2/em.rb",
|
44
|
+
"lib/mysql2/error.rb",
|
45
|
+
"lib/mysql2/result.rb",
|
39
46
|
"lib/sequel/adapters/mysql2.rb",
|
40
47
|
"mysql2.gemspec",
|
41
48
|
"spec/active_record/active_record_spec.rb",
|
@@ -50,7 +57,7 @@ Gem::Specification.new do |s|
|
|
50
57
|
s.homepage = %q{http://github.com/brianmario/mysql2}
|
51
58
|
s.rdoc_options = ["--charset=UTF-8"]
|
52
59
|
s.require_paths = ["lib", "ext"]
|
53
|
-
s.rubygems_version = %q{1.3.
|
60
|
+
s.rubygems_version = %q{1.3.7}
|
54
61
|
s.summary = %q{A simple, fast Mysql library for Ruby, binding to libmysql}
|
55
62
|
s.test_files = [
|
56
63
|
"spec/active_record/active_record_spec.rb",
|
@@ -66,7 +73,7 @@ Gem::Specification.new do |s|
|
|
66
73
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
74
|
s.specification_version = 3
|
68
75
|
|
69
|
-
if Gem::Version.new(Gem::
|
76
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
70
77
|
else
|
71
78
|
end
|
72
79
|
else
|