mysql2 0.3.12b4 → 0.3.12b5

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,8 @@ require 'rational' unless RUBY_VERSION >= '1.9.2'
5
5
 
6
6
  require 'mysql2/version' unless defined? Mysql2::VERSION
7
7
  require 'mysql2/error'
8
- require 'mysql2/result'
9
8
  require 'mysql2/mysql2'
9
+ require 'mysql2/result'
10
10
  require 'mysql2/client'
11
11
 
12
12
  # = Mysql2
@@ -37,5 +37,5 @@ module Mysql2::Util
37
37
  return nil unless hash
38
38
  Hash[hash.map { |k,v| [k.to_sym, v] }]
39
39
  end
40
-
40
+
41
41
  end
@@ -23,7 +23,14 @@ module Mysql2
23
23
  # Set MySQL connection options (each one is a call to mysql_options())
24
24
  [:reconnect, :connect_timeout, :local_infile, :read_timeout, :write_timeout].each do |key|
25
25
  next unless opts.key?(key)
26
- send(:"#{key}=", opts[key])
26
+ case key
27
+ when :reconnect, :local_infile
28
+ send(:"#{key}=", !!opts[key])
29
+ when :connect_timeout, :read_timeout, :write_timeout
30
+ send(:"#{key}=", opts[key].to_i)
31
+ else
32
+ send(:"#{key}=", opts[key])
33
+ end
27
34
  end
28
35
 
29
36
  # force the encoding to utf8
@@ -34,7 +41,7 @@ module Mysql2
34
41
  if [:user,:pass,:hostname,:dbname,:db,:sock].any?{|k| @query_options.has_key?(k) }
35
42
  warn "============= WARNING FROM mysql2 ============="
36
43
  warn "The options :user, :pass, :hostname, :dbname, :db, and :sock will be deprecated at some point in the future."
37
- warn "Instead, please use :username, :password, :host, 'localhost', :port, :database, :socket, :flags for the options."
44
+ warn "Instead, please use :username, :password, :host, :port, :database, :socket, :flags for the options."
38
45
  warn "============= END WARNING FROM mysql2 ========="
39
46
  end
40
47
 
@@ -53,214 +60,6 @@ module Mysql2
53
60
  @@default_query_options
54
61
  end
55
62
 
56
- # NOTE: from ruby-mysql
57
- if defined? Encoding
58
- CHARSET_MAP = {
59
- "armscii8" => nil,
60
- "ascii" => Encoding::US_ASCII,
61
- "big5" => Encoding::Big5,
62
- "binary" => Encoding::ASCII_8BIT,
63
- "cp1250" => Encoding::Windows_1250,
64
- "cp1251" => Encoding::Windows_1251,
65
- "cp1256" => Encoding::Windows_1256,
66
- "cp1257" => Encoding::Windows_1257,
67
- "cp850" => Encoding::CP850,
68
- "cp852" => Encoding::CP852,
69
- "cp866" => Encoding::IBM866,
70
- "cp932" => Encoding::Windows_31J,
71
- "dec8" => nil,
72
- "eucjpms" => Encoding::EucJP_ms,
73
- "euckr" => Encoding::EUC_KR,
74
- "gb2312" => Encoding::EUC_CN,
75
- "gbk" => Encoding::GBK,
76
- "geostd8" => nil,
77
- "greek" => Encoding::ISO_8859_7,
78
- "hebrew" => Encoding::ISO_8859_8,
79
- "hp8" => nil,
80
- "keybcs2" => nil,
81
- "koi8r" => Encoding::KOI8_R,
82
- "koi8u" => Encoding::KOI8_U,
83
- "latin1" => Encoding::ISO_8859_1,
84
- "latin2" => Encoding::ISO_8859_2,
85
- "latin5" => Encoding::ISO_8859_9,
86
- "latin7" => Encoding::ISO_8859_13,
87
- "macce" => Encoding::MacCentEuro,
88
- "macroman" => Encoding::MacRoman,
89
- "sjis" => Encoding::SHIFT_JIS,
90
- "swe7" => nil,
91
- "tis620" => Encoding::TIS_620,
92
- "ucs2" => Encoding::UTF_16BE,
93
- "ujis" => Encoding::EucJP_ms,
94
- "utf8" => Encoding::UTF_8,
95
- "utf8mb4" => Encoding::UTF_8,
96
- }
97
-
98
- MYSQL_CHARSET_MAP = {
99
- 1 => {:name => "big5", :collation => "big5_chinese_ci"},
100
- 2 => {:name => "latin2", :collation => "latin2_czech_cs"},
101
- 3 => {:name => "dec8", :collation => "dec8_swedish_ci"},
102
- 4 => {:name => "cp850", :collation => "cp850_general_ci"},
103
- 5 => {:name => "latin1", :collation => "latin1_german1_ci"},
104
- 6 => {:name => "hp8", :collation => "hp8_english_ci"},
105
- 7 => {:name => "koi8r", :collation => "koi8r_general_ci"},
106
- 8 => {:name => "latin1", :collation => "latin1_swedish_ci"},
107
- 9 => {:name => "latin2", :collation => "latin2_general_ci"},
108
- 10 => {:name => "swe7", :collation => "swe7_swedish_ci"},
109
- 11 => {:name => "ascii", :collation => "ascii_general_ci"},
110
- 12 => {:name => "ujis", :collation => "ujis_japanese_ci"},
111
- 13 => {:name => "sjis", :collation => "sjis_japanese_ci"},
112
- 14 => {:name => "cp1251", :collation => "cp1251_bulgarian_ci"},
113
- 15 => {:name => "latin1", :collation => "latin1_danish_ci"},
114
- 16 => {:name => "hebrew", :collation => "hebrew_general_ci"},
115
- 17 => {:name => "filename", :collation => "filename"},
116
- 18 => {:name => "tis620", :collation => "tis620_thai_ci"},
117
- 19 => {:name => "euckr", :collation => "euckr_korean_ci"},
118
- 20 => {:name => "latin7", :collation => "latin7_estonian_cs"},
119
- 21 => {:name => "latin2", :collation => "latin2_hungarian_ci"},
120
- 22 => {:name => "koi8u", :collation => "koi8u_general_ci"},
121
- 23 => {:name => "cp1251", :collation => "cp1251_ukrainian_ci"},
122
- 24 => {:name => "gb2312", :collation => "gb2312_chinese_ci"},
123
- 25 => {:name => "greek", :collation => "greek_general_ci"},
124
- 26 => {:name => "cp1250", :collation => "cp1250_general_ci"},
125
- 27 => {:name => "latin2", :collation => "latin2_croatian_ci"},
126
- 28 => {:name => "gbk", :collation => "gbk_chinese_ci"},
127
- 29 => {:name => "cp1257", :collation => "cp1257_lithuanian_ci"},
128
- 30 => {:name => "latin5", :collation => "latin5_turkish_ci"},
129
- 31 => {:name => "latin1", :collation => "latin1_german2_ci"},
130
- 32 => {:name => "armscii8", :collation => "armscii8_general_ci"},
131
- 33 => {:name => "utf8", :collation => "utf8_general_ci"},
132
- 34 => {:name => "cp1250", :collation => "cp1250_czech_cs"},
133
- 35 => {:name => "ucs2", :collation => "ucs2_general_ci"},
134
- 36 => {:name => "cp866", :collation => "cp866_general_ci"},
135
- 37 => {:name => "keybcs2", :collation => "keybcs2_general_ci"},
136
- 38 => {:name => "macce", :collation => "macce_general_ci"},
137
- 39 => {:name => "macroman", :collation => "macroman_general_ci"},
138
- 40 => {:name => "cp852", :collation => "cp852_general_ci"},
139
- 41 => {:name => "latin7", :collation => "latin7_general_ci"},
140
- 42 => {:name => "latin7", :collation => "latin7_general_cs"},
141
- 43 => {:name => "macce", :collation => "macce_bin"},
142
- 44 => {:name => "cp1250", :collation => "cp1250_croatian_ci"},
143
- 45 => {:name => "utf8mb4", :collation => "utf8mb4_general_ci"},
144
- 46 => {:name => "utf8mb4", :collation => "utf8mb4_bin"},
145
- 47 => {:name => "latin1", :collation => "latin1_bin"},
146
- 48 => {:name => "latin1", :collation => "latin1_general_ci"},
147
- 49 => {:name => "latin1", :collation => "latin1_general_cs"},
148
- 50 => {:name => "cp1251", :collation => "cp1251_bin"},
149
- 51 => {:name => "cp1251", :collation => "cp1251_general_ci"},
150
- 52 => {:name => "cp1251", :collation => "cp1251_general_cs"},
151
- 53 => {:name => "macroman", :collation => "macroman_bin"},
152
- 57 => {:name => "cp1256", :collation => "cp1256_general_ci"},
153
- 58 => {:name => "cp1257", :collation => "cp1257_bin"},
154
- 59 => {:name => "cp1257", :collation => "cp1257_general_ci"},
155
- 63 => {:name => "binary", :collation => "binary"},
156
- 64 => {:name => "armscii8", :collation => "armscii8_bin"},
157
- 65 => {:name => "ascii", :collation => "ascii_bin"},
158
- 66 => {:name => "cp1250", :collation => "cp1250_bin"},
159
- 67 => {:name => "cp1256", :collation => "cp1256_bin"},
160
- 68 => {:name => "cp866", :collation => "cp866_bin"},
161
- 69 => {:name => "dec8", :collation => "dec8_bin"},
162
- 70 => {:name => "greek", :collation => "greek_bin"},
163
- 71 => {:name => "hebrew", :collation => "hebrew_bin"},
164
- 72 => {:name => "hp8", :collation => "hp8_bin"},
165
- 73 => {:name => "keybcs2", :collation => "keybcs2_bin"},
166
- 74 => {:name => "koi8r", :collation => "koi8r_bin"},
167
- 75 => {:name => "koi8u", :collation => "koi8u_bin"},
168
- 77 => {:name => "latin2", :collation => "latin2_bin"},
169
- 78 => {:name => "latin5", :collation => "latin5_bin"},
170
- 79 => {:name => "latin7", :collation => "latin7_bin"},
171
- 80 => {:name => "cp850", :collation => "cp850_bin"},
172
- 81 => {:name => "cp852", :collation => "cp852_bin"},
173
- 82 => {:name => "swe7", :collation => "swe7_bin"},
174
- 83 => {:name => "utf8", :collation => "utf8_bin"},
175
- 84 => {:name => "big5", :collation => "big5_bin"},
176
- 85 => {:name => "euckr", :collation => "euckr_bin"},
177
- 86 => {:name => "gb2312", :collation => "gb2312_bin"},
178
- 87 => {:name => "gbk", :collation => "gbk_bin"},
179
- 88 => {:name => "sjis", :collation => "sjis_bin"},
180
- 89 => {:name => "tis620", :collation => "tis620_bin"},
181
- 90 => {:name => "ucs2", :collation => "ucs2_bin"},
182
- 91 => {:name => "ujis", :collation => "ujis_bin"},
183
- 92 => {:name => "geostd8", :collation => "geostd8_general_ci"},
184
- 93 => {:name => "geostd8", :collation => "geostd8_bin"},
185
- 94 => {:name => "latin1", :collation => "latin1_spanish_ci"},
186
- 95 => {:name => "cp932", :collation => "cp932_japanese_ci"},
187
- 96 => {:name => "cp932", :collation => "cp932_bin"},
188
- 97 => {:name => "eucjpms", :collation => "eucjpms_japanese_ci"},
189
- 98 => {:name => "eucjpms", :collation => "eucjpms_bin"},
190
- 99 => {:name => "cp1250", :collation => "cp1250_polish_ci"},
191
- 128 => {:name => "ucs2", :collation => "ucs2_unicode_ci"},
192
- 129 => {:name => "ucs2", :collation => "ucs2_icelandic_ci"},
193
- 130 => {:name => "ucs2", :collation => "ucs2_latvian_ci"},
194
- 131 => {:name => "ucs2", :collation => "ucs2_romanian_ci"},
195
- 132 => {:name => "ucs2", :collation => "ucs2_slovenian_ci"},
196
- 133 => {:name => "ucs2", :collation => "ucs2_polish_ci"},
197
- 134 => {:name => "ucs2", :collation => "ucs2_estonian_ci"},
198
- 135 => {:name => "ucs2", :collation => "ucs2_spanish_ci"},
199
- 136 => {:name => "ucs2", :collation => "ucs2_swedish_ci"},
200
- 137 => {:name => "ucs2", :collation => "ucs2_turkish_ci"},
201
- 138 => {:name => "ucs2", :collation => "ucs2_czech_ci"},
202
- 139 => {:name => "ucs2", :collation => "ucs2_danish_ci"},
203
- 140 => {:name => "ucs2", :collation => "ucs2_lithuanian_ci"},
204
- 141 => {:name => "ucs2", :collation => "ucs2_slovak_ci"},
205
- 142 => {:name => "ucs2", :collation => "ucs2_spanish2_ci"},
206
- 143 => {:name => "ucs2", :collation => "ucs2_roman_ci"},
207
- 144 => {:name => "ucs2", :collation => "ucs2_persian_ci"},
208
- 145 => {:name => "ucs2", :collation => "ucs2_esperanto_ci"},
209
- 146 => {:name => "ucs2", :collation => "ucs2_hungarian_ci"},
210
- 192 => {:name => "utf8", :collation => "utf8_unicode_ci"},
211
- 193 => {:name => "utf8", :collation => "utf8_icelandic_ci"},
212
- 194 => {:name => "utf8", :collation => "utf8_latvian_ci"},
213
- 195 => {:name => "utf8", :collation => "utf8_romanian_ci"},
214
- 196 => {:name => "utf8", :collation => "utf8_slovenian_ci"},
215
- 197 => {:name => "utf8", :collation => "utf8_polish_ci"},
216
- 198 => {:name => "utf8", :collation => "utf8_estonian_ci"},
217
- 199 => {:name => "utf8", :collation => "utf8_spanish_ci"},
218
- 200 => {:name => "utf8", :collation => "utf8_swedish_ci"},
219
- 201 => {:name => "utf8", :collation => "utf8_turkish_ci"},
220
- 202 => {:name => "utf8", :collation => "utf8_czech_ci"},
221
- 203 => {:name => "utf8", :collation => "utf8_danish_ci"},
222
- 204 => {:name => "utf8", :collation => "utf8_lithuanian_ci"},
223
- 205 => {:name => "utf8", :collation => "utf8_slovak_ci"},
224
- 206 => {:name => "utf8", :collation => "utf8_spanish2_ci"},
225
- 207 => {:name => "utf8", :collation => "utf8_roman_ci"},
226
- 208 => {:name => "utf8", :collation => "utf8_persian_ci"},
227
- 209 => {:name => "utf8", :collation => "utf8_esperanto_ci"},
228
- 210 => {:name => "utf8", :collation => "utf8_hungarian_ci"},
229
- 224 => {:name => "utf8mb4", :collation => "utf8mb4_unicode_ci"},
230
- 225 => {:name => "utf8mb4", :collation => "utf8mb4_icelandic_ci"},
231
- 226 => {:name => "utf8mb4", :collation => "utf8mb4_latvian_ci"},
232
- 227 => {:name => "utf8mb4", :collation => "utf8mb4_romanian_ci"},
233
- 228 => {:name => "utf8mb4", :collation => "utf8mb4_slovenian_ci"},
234
- 229 => {:name => "utf8mb4", :collation => "utf8mb4_polish_ci"},
235
- 230 => {:name => "utf8mb4", :collation => "utf8mb4_estonian_ci"},
236
- 231 => {:name => "utf8mb4", :collation => "utf8mb4_spanish_ci"},
237
- 232 => {:name => "utf8mb4", :collation => "utf8mb4_swedish_ci"},
238
- 233 => {:name => "utf8mb4", :collation => "utf8mb4_turkish_ci"},
239
- 234 => {:name => "utf8mb4", :collation => "utf8mb4_czech_ci"},
240
- 235 => {:name => "utf8mb4", :collation => "utf8mb4_danish_ci"},
241
- 236 => {:name => "utf8mb4", :collation => "utf8mb4_lithuanian_ci"},
242
- 237 => {:name => "utf8mb4", :collation => "utf8mb4_slovak_ci"},
243
- 238 => {:name => "utf8mb4", :collation => "utf8mb4_spanish2_ci"},
244
- 239 => {:name => "utf8mb4", :collation => "utf8mb4_roman_ci"},
245
- 240 => {:name => "utf8mb4", :collation => "utf8mb4_persian_ci"},
246
- 241 => {:name => "utf8mb4", :collation => "utf8mb4_esperanto_ci"},
247
- 242 => {:name => "utf8mb4", :collation => "utf8mb4_hungarian_ci"},
248
- 254 => {:name => "utf8", :collation => "utf8_general_cs"}
249
- }
250
-
251
- def self.encoding_from_charset(charset)
252
- CHARSET_MAP[charset.to_s.downcase]
253
- end
254
-
255
- def self.encoding_from_charset_code(code)
256
- if mapping = MYSQL_CHARSET_MAP[code]
257
- encoding_from_charset(mapping[:name])
258
- else
259
- nil
260
- end
261
- end
262
- end
263
-
264
63
  private
265
64
  def self.local_offset
266
65
  ::Time.local(2010).utc_offset.to_r / 86400
@@ -1,3 +1,3 @@
1
1
  module Mysql2
2
- VERSION = "0.3.12b4"
2
+ VERSION = "0.3.12b5"
3
3
  end
@@ -6,12 +6,30 @@ describe Mysql2::Client do
6
6
  @client = Mysql2::Client.new DatabaseCredentials['root']
7
7
  end
8
8
 
9
+ it "should raise an exception upon connection failure" do
10
+ lambda {
11
+ # The odd local host IP address forces the mysql client library to
12
+ # use a TCP socket rather than a domain socket.
13
+ Mysql2::Client.new DatabaseCredentials['root'].merge('host' => '127.0.0.2', 'port' => 999999)
14
+ }.should raise_error(Mysql2::Error)
15
+ end
16
+
9
17
  if defined? Encoding
10
18
  it "should raise an exception on create for invalid encodings" do
11
19
  lambda {
12
20
  c = Mysql2::Client.new(:encoding => "fake")
13
21
  }.should raise_error(Mysql2::Error)
14
22
  end
23
+
24
+ it "should not raise an exception on create for a valid encoding" do
25
+ lambda {
26
+ c = Mysql2::Client.new(:encoding => "utf8")
27
+ }.should_not raise_error(Mysql2::Error)
28
+
29
+ lambda {
30
+ c = Mysql2::Client.new(:encoding => "big5")
31
+ }.should_not raise_error(Mysql2::Error)
32
+ end
15
33
  end
16
34
 
17
35
  it "should accept connect flags and pass them to #connect" do
@@ -85,6 +103,31 @@ describe Mysql2::Client do
85
103
  @client.should respond_to(:query)
86
104
  end
87
105
 
106
+ it "should respond to #warning_count" do
107
+ @client.should respond_to(:warning_count)
108
+ end
109
+
110
+ context "#warning_count" do
111
+ context "when no warnings" do
112
+ before(:each) do
113
+ @client.query('select 1')
114
+ end
115
+ it "should 0" do
116
+ @client.warning_count.should == 0
117
+ end
118
+ end
119
+ context "when has a warnings" do
120
+ before(:each) do
121
+ # "the statement produces extra information that can be viewed by issuing a SHOW WARNINGS"
122
+ # http://dev.mysql.com/doc/refman/5.0/en/explain-extended.html
123
+ @client.query("explain extended select 1")
124
+ end
125
+ it "should > 0" do
126
+ @client.warning_count.should > 0
127
+ end
128
+ end
129
+ end
130
+
88
131
  it "should expect connect_timeout to be a positive integer" do
89
132
  lambda {
90
133
  Mysql2::Client.new(:connect_timeout => -1)
@@ -126,9 +169,26 @@ describe Mysql2::Client do
126
169
  }.should raise_error(TypeError)
127
170
  end
128
171
 
129
- it "should accept an options hash that inherits from Mysql2::Client.default_query_options" do
130
- @client.query "SELECT 1", :something => :else
131
- @client.query_options.should eql(@client.query_options.merge(:something => :else))
172
+ it "should not retain query options set on a query for subsequent queries, but should retain it in the result" do
173
+ result = @client.query "SELECT 1", :something => :else
174
+ @client.query_options[:something].should be_nil
175
+ result.instance_variable_get('@query_options').should eql(@client.query_options.merge(:something => :else))
176
+ @client.instance_variable_get('@current_query_options').should eql(@client.query_options.merge(:something => :else))
177
+
178
+ result = @client.query "SELECT 1"
179
+ result.instance_variable_get('@query_options').should eql(@client.query_options)
180
+ @client.instance_variable_get('@current_query_options').should eql(@client.query_options)
181
+ end
182
+
183
+ it "should allow changing query options for subsequent queries" do
184
+ @client.query_options.merge!(:something => :else)
185
+ result = @client.query "SELECT 1"
186
+ @client.query_options[:something].should eql(:else)
187
+ result.instance_variable_get('@query_options')[:something].should eql(:else)
188
+
189
+ # Clean up after this test
190
+ @client.query_options.delete(:something)
191
+ @client.query_options[:something].should be_nil
132
192
  end
133
193
 
134
194
  it "should return results as a hash by default" do
@@ -245,15 +305,47 @@ describe Mysql2::Client do
245
305
  }.should_not raise_error(Mysql2::Error)
246
306
  end
247
307
 
308
+ it "should handle Timeouts without leaving the connection hanging if reconnect is set to true after construction true" do
309
+ client = Mysql2::Client.new(DatabaseCredentials['root'])
310
+ begin
311
+ Timeout.timeout(1) do
312
+ client.query("SELECT sleep(2)")
313
+ end
314
+ rescue Timeout::Error
315
+ end
316
+
317
+ lambda {
318
+ client.query("SELECT 1")
319
+ }.should raise_error(Mysql2::Error)
320
+
321
+ client.reconnect = true
322
+
323
+ begin
324
+ Timeout.timeout(1) do
325
+ client.query("SELECT sleep(2)")
326
+ end
327
+ rescue Timeout::Error
328
+ end
329
+
330
+ lambda {
331
+ client.query("SELECT 1")
332
+ }.should_not raise_error(Mysql2::Error)
333
+
334
+ end
335
+
248
336
  it "threaded queries should be supported" do
249
337
  threads, results = [], {}
338
+ lock = Mutex.new
250
339
  connect = lambda{
251
340
  Mysql2::Client.new(DatabaseCredentials['root'])
252
341
  }
253
342
  Timeout.timeout(0.7) do
254
343
  5.times {
255
344
  threads << Thread.new do
256
- results[Thread.current.object_id] = connect.call.query("SELECT sleep(0.5) as result")
345
+ result = connect.call.query("SELECT sleep(0.5) as result")
346
+ lock.synchronize do
347
+ results[Thread.current.object_id] = result
348
+ end
257
349
  end
258
350
  }
259
351
  end
@@ -281,14 +373,6 @@ describe Mysql2::Client do
281
373
  result = @client.async_result
282
374
  result.class.should eql(Mysql2::Result)
283
375
  end
284
-
285
- it "should not allow options to be set on an open connection" do
286
- lambda {
287
- @client.escape ""
288
- @client.query("SELECT 1")
289
- @client.options(0, 0)
290
- }.should raise_error(Mysql2::Error)
291
- end
292
376
  end
293
377
 
294
378
  context "Multiple results sets" do
@@ -313,6 +397,31 @@ describe Mysql2::Client do
313
397
 
314
398
  @multi_client.query( "select 3 as 'next'").first.should == { 'next' => 3 }
315
399
  end
400
+
401
+ it "will raise on query if there are outstanding results to read" do
402
+ @multi_client.query("SELECT 1; SELECT 2; SELECT 3")
403
+ lambda {
404
+ @multi_client.query("SELECT 4")
405
+ }.should raise_error(Mysql2::Error)
406
+ end
407
+
408
+ it "#abandon_results! should work" do
409
+ @multi_client.query("SELECT 1; SELECT 2; SELECT 3")
410
+ @multi_client.abandon_results!
411
+ lambda {
412
+ @multi_client.query("SELECT 4")
413
+ }.should_not raise_error(Mysql2::Error)
414
+ end
415
+
416
+ it "#more_results? should work" do
417
+ @multi_client.query( "select 1 as 'set_1'; select 2 as 'set_2'")
418
+ @multi_client.more_results?.should == true
419
+
420
+ @multi_client.next_result
421
+ @multi_client.store_result
422
+
423
+ @multi_client.more_results?.should == false
424
+ end
316
425
  end
317
426
  end
318
427
 
@@ -354,7 +463,7 @@ describe Mysql2::Client do
354
463
  }.should_not raise_error(SystemStackError)
355
464
  end
356
465
 
357
- if RUBY_VERSION =~ /1.9/
466
+ unless RUBY_VERSION =~ /1.8/
358
467
  it "should carry over the original string's encoding" do
359
468
  str = "abc'def\"ghi\0jkl%mno"
360
469
  escaped = Mysql2::Client.escape(str)
@@ -571,7 +680,7 @@ describe Mysql2::Client do
571
680
  @client.ping.should eql(false)
572
681
  end
573
682
 
574
- if RUBY_VERSION =~ /1.9/
683
+ unless RUBY_VERSION =~ /1.8/
575
684
  it "should respond to #encoding" do
576
685
  @client.should respond_to(:encoding)
577
686
  end