mysql2_bigint 0.2.6.1

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.
Files changed (46) hide show
  1. data/CHANGELOG.md +120 -0
  2. data/Gemfile +3 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +248 -0
  5. data/Rakefile +5 -0
  6. data/benchmark/active_record.rb +51 -0
  7. data/benchmark/allocations.rb +33 -0
  8. data/benchmark/escape.rb +36 -0
  9. data/benchmark/query_with_mysql_casting.rb +80 -0
  10. data/benchmark/query_without_mysql_casting.rb +47 -0
  11. data/benchmark/sequel.rb +37 -0
  12. data/benchmark/setup_db.rb +119 -0
  13. data/examples/eventmachine.rb +21 -0
  14. data/examples/threaded.rb +20 -0
  15. data/ext/mysql2/client.c +768 -0
  16. data/ext/mysql2/client.h +41 -0
  17. data/ext/mysql2/extconf.rb +69 -0
  18. data/ext/mysql2/mysql2_ext.c +12 -0
  19. data/ext/mysql2/mysql2_ext.h +38 -0
  20. data/ext/mysql2/result.c +488 -0
  21. data/ext/mysql2/result.h +20 -0
  22. data/lib/active_record/connection_adapters/em_mysql2_adapter.rb +64 -0
  23. data/lib/active_record/connection_adapters/mysql2_adapter.rb +654 -0
  24. data/lib/active_record/fiber_patches.rb +104 -0
  25. data/lib/arel/engines/sql/compilers/mysql2_compiler.rb +11 -0
  26. data/lib/mysql2.rb +16 -0
  27. data/lib/mysql2/client.rb +240 -0
  28. data/lib/mysql2/em.rb +37 -0
  29. data/lib/mysql2/em_fiber.rb +31 -0
  30. data/lib/mysql2/error.rb +15 -0
  31. data/lib/mysql2/result.rb +5 -0
  32. data/lib/mysql2/version.rb +3 -0
  33. data/lib/mysql2_bigint.rb +1 -0
  34. data/mysql2_bigint.gemspec +32 -0
  35. data/spec/em/em_fiber_spec.rb +22 -0
  36. data/spec/em/em_spec.rb +49 -0
  37. data/spec/mysql2/client_spec.rb +385 -0
  38. data/spec/mysql2/error_spec.rb +25 -0
  39. data/spec/mysql2/result_spec.rb +328 -0
  40. data/spec/rcov.opts +3 -0
  41. data/spec/spec_helper.rb +66 -0
  42. data/tasks/benchmarks.rake +20 -0
  43. data/tasks/compile.rake +53 -0
  44. data/tasks/rspec.rake +16 -0
  45. data/tasks/vendor_mysql.rake +41 -0
  46. metadata +199 -0
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Mysql2::Error do
5
+ before(:each) do
6
+ @error = Mysql2::Error.new "testing"
7
+ end
8
+
9
+ it "should respond to #error_number" do
10
+ @error.should respond_to(:error_number)
11
+ end
12
+
13
+ it "should respond to #sql_state" do
14
+ @error.should respond_to(:sql_state)
15
+ end
16
+
17
+ # Mysql gem compatibility
18
+ it "should alias #error_number to #errno" do
19
+ @error.should respond_to(:errno)
20
+ end
21
+
22
+ it "should alias #message to #error" do
23
+ @error.should respond_to(:error)
24
+ end
25
+ end
@@ -0,0 +1,328 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe Mysql2::Result do
5
+ before(:each) do
6
+ @client = Mysql2::Client.new :host => "localhost", :username => "root", :database => 'test'
7
+ end
8
+
9
+ before(:each) do
10
+ @result = @client.query "SELECT 1"
11
+ end
12
+
13
+ it "should have included Enumerable" do
14
+ Mysql2::Result.ancestors.include?(Enumerable).should be_true
15
+ end
16
+
17
+ it "should respond to #each" do
18
+ @result.should respond_to(:each)
19
+ end
20
+
21
+ it "should raise a Mysql2::Error exception upon a bad query" do
22
+ lambda {
23
+ @client.query "bad sql"
24
+ }.should raise_error(Mysql2::Error)
25
+
26
+ lambda {
27
+ @client.query "SELECT 1"
28
+ }.should_not raise_error(Mysql2::Error)
29
+ end
30
+
31
+ context "#each" do
32
+ it "should yield rows as hash's" do
33
+ @result.each do |row|
34
+ row.class.should eql(Hash)
35
+ end
36
+ end
37
+
38
+ it "should yield rows as hash's with symbol keys if :symbolize_keys was set to true" do
39
+ @result.each(:symbolize_keys => true) do |row|
40
+ row.keys.first.class.should eql(Symbol)
41
+ end
42
+ end
43
+
44
+ it "should be able to return results as an array" do
45
+ @result.each(:as => :array) do |row|
46
+ row.class.should eql(Array)
47
+ end
48
+ end
49
+
50
+ it "should cache previously yielded results by default" do
51
+ @result.first.object_id.should eql(@result.first.object_id)
52
+ end
53
+
54
+ it "should not cache previously yielded results if cache_rows is disabled" do
55
+ result = @client.query "SELECT 1", :cache_rows => false
56
+ result.first.object_id.should_not eql(result.first.object_id)
57
+ end
58
+ end
59
+
60
+ context "#fields" do
61
+ before(:each) do
62
+ @client.query "USE test"
63
+ @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1")
64
+ end
65
+
66
+ it "method should exist" do
67
+ @test_result.should respond_to(:fields)
68
+ end
69
+
70
+ it "should return an array of field names in proper order" do
71
+ result = @client.query "SELECT 'a', 'b', 'c'"
72
+ result.fields.should eql(['a', 'b', 'c'])
73
+ end
74
+ end
75
+
76
+ context "row data type mapping" do
77
+ before(:each) do
78
+ @client.query "USE test"
79
+ @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
80
+ end
81
+
82
+ it "should return nil for a NULL value" do
83
+ @test_result['null_test'].class.should eql(NilClass)
84
+ @test_result['null_test'].should eql(nil)
85
+ end
86
+
87
+ it "should return Fixnum for a BIT value" do
88
+ @test_result['bit_test'].class.should eql(String)
89
+ @test_result['bit_test'].should eql("\000\000\000\000\000\000\000\005")
90
+ end
91
+
92
+ it "should return Fixnum for a TINYINT value" do
93
+ [Fixnum, Bignum].should include(@test_result['tiny_int_test'].class)
94
+ @test_result['tiny_int_test'].should eql(1)
95
+ end
96
+
97
+ it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
98
+ @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (1)'
99
+ id1 = @client.last_id
100
+ @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (0)'
101
+ id2 = @client.last_id
102
+
103
+ result1 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast_booleans => true
104
+ result2 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1', :cast_booleans => true
105
+ result1.first['bool_cast_test'].should be_true
106
+ result2.first['bool_cast_test'].should be_false
107
+
108
+ @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
109
+ end
110
+
111
+ it "should return Fixnum for a SMALLINT value" do
112
+ [Fixnum, Bignum].should include(@test_result['small_int_test'].class)
113
+ @test_result['small_int_test'].should eql(10)
114
+ end
115
+
116
+ it "should return Fixnum for a MEDIUMINT value" do
117
+ [Fixnum, Bignum].should include(@test_result['medium_int_test'].class)
118
+ @test_result['medium_int_test'].should eql(10)
119
+ end
120
+
121
+ it "should return Fixnum for an INT value" do
122
+ [Fixnum, Bignum].should include(@test_result['int_test'].class)
123
+ @test_result['int_test'].should eql(10)
124
+ end
125
+
126
+ it "should return Fixnum for a BIGINT value" do
127
+ [Fixnum, Bignum].should include(@test_result['big_int_test'].class)
128
+ @test_result['big_int_test'].should eql(10)
129
+ end
130
+
131
+ it "should return Fixnum for a YEAR value" do
132
+ [Fixnum, Bignum].should include(@test_result['year_test'].class)
133
+ @test_result['year_test'].should eql(2009)
134
+ end
135
+
136
+ it "should return BigDecimal for a DECIMAL value" do
137
+ @test_result['decimal_test'].class.should eql(BigDecimal)
138
+ @test_result['decimal_test'].should eql(10.3)
139
+ end
140
+
141
+ it "should return Float for a FLOAT value" do
142
+ @test_result['float_test'].class.should eql(Float)
143
+ @test_result['float_test'].should eql(10.3)
144
+ end
145
+
146
+ it "should return Float for a DOUBLE value" do
147
+ @test_result['double_test'].class.should eql(Float)
148
+ @test_result['double_test'].should eql(10.3)
149
+ end
150
+
151
+ it "should return Time for a DATETIME value when within the supported range" do
152
+ @test_result['date_time_test'].class.should eql(Time)
153
+ @test_result['date_time_test'].strftime("%F %T").should eql('2010-04-04 11:44:00')
154
+ end
155
+
156
+ it "should return DateTime for a DATETIME value when outside the supported range, Time if otherwise" do
157
+ if RUBY_PLATFORM =~ /mswin/
158
+ inside_year = 1970
159
+ outside_year = inside_year-1
160
+ else
161
+ inside_year = 1902
162
+ outside_year = inside_year-1
163
+ end
164
+ r = @client.query("SELECT CAST('#{inside_year}-1-1 01:01:01' AS DATETIME) as test")
165
+ r.first['test'].class.should eql(Time)
166
+
167
+ r = @client.query("SELECT CAST('#{outside_year}-1-1 01:01:01' AS DATETIME) as test")
168
+ r.first['test'].class.should eql(DateTime)
169
+ end
170
+
171
+ it "should return Time for a TIMESTAMP value when within the supported range" do
172
+ @test_result['timestamp_test'].class.should eql(Time)
173
+ @test_result['timestamp_test'].strftime("%F %T").should eql('2010-04-04 11:44:00')
174
+ end
175
+
176
+ it "should return Time for a TIME value" do
177
+ @test_result['time_test'].class.should eql(Time)
178
+ @test_result['time_test'].strftime("%F %T").should eql('2000-01-01 11:44:00')
179
+ end
180
+
181
+ it "should return Date for a DATE value" do
182
+ @test_result['date_test'].class.should eql(Date)
183
+ @test_result['date_test'].strftime("%F").should eql('2010-04-04')
184
+ end
185
+
186
+ it "should return String for an ENUM value" do
187
+ @test_result['enum_test'].class.should eql(String)
188
+ @test_result['enum_test'].should eql('val1')
189
+ end
190
+
191
+ if defined? Encoding
192
+ context "string encoding for ENUM values" do
193
+ it "should default to the connection's encoding if Encoding.default_internal is nil" do
194
+ Encoding.default_internal = nil
195
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
196
+ result['enum_test'].encoding.should eql(Encoding.find('utf-8'))
197
+
198
+ client2 = Mysql2::Client.new :encoding => 'ascii'
199
+ client2.query "USE test"
200
+ result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
201
+ result['enum_test'].encoding.should eql(Encoding.find('us-ascii'))
202
+ end
203
+
204
+ it "should use Encoding.default_internal" do
205
+ Encoding.default_internal = Encoding.find('utf-8')
206
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
207
+ result['enum_test'].encoding.should eql(Encoding.default_internal)
208
+ Encoding.default_internal = Encoding.find('us-ascii')
209
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
210
+ result['enum_test'].encoding.should eql(Encoding.default_internal)
211
+ end
212
+ end
213
+ end
214
+
215
+ it "should return String for a SET value" do
216
+ @test_result['set_test'].class.should eql(String)
217
+ @test_result['set_test'].should eql('val1,val2')
218
+ end
219
+
220
+ if defined? Encoding
221
+ context "string encoding for SET values" do
222
+ it "should default to the connection's encoding if Encoding.default_internal is nil" do
223
+ Encoding.default_internal = nil
224
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
225
+ result['set_test'].encoding.should eql(Encoding.find('utf-8'))
226
+
227
+ client2 = Mysql2::Client.new :encoding => 'ascii'
228
+ client2.query "USE test"
229
+ result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
230
+ result['set_test'].encoding.should eql(Encoding.find('us-ascii'))
231
+ end
232
+
233
+ it "should use Encoding.default_internal" do
234
+ Encoding.default_internal = Encoding.find('utf-8')
235
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
236
+ result['set_test'].encoding.should eql(Encoding.default_internal)
237
+ Encoding.default_internal = Encoding.find('us-ascii')
238
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
239
+ result['set_test'].encoding.should eql(Encoding.default_internal)
240
+ end
241
+ end
242
+ end
243
+
244
+ it "should return String for a BINARY value" do
245
+ @test_result['binary_test'].class.should eql(String)
246
+ @test_result['binary_test'].should eql("test#{"\000"*6}")
247
+ end
248
+
249
+ if defined? Encoding
250
+ context "string encoding for BINARY values" do
251
+ it "should default to binary if Encoding.default_internal is nil" do
252
+ Encoding.default_internal = nil
253
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
254
+ result['binary_test'].encoding.should eql(Encoding.find('binary'))
255
+ end
256
+
257
+ it "should not use Encoding.default_internal" do
258
+ Encoding.default_internal = Encoding.find('utf-8')
259
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
260
+ result['binary_test'].encoding.should eql(Encoding.find('binary'))
261
+ Encoding.default_internal = Encoding.find('us-ascii')
262
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
263
+ result['binary_test'].encoding.should eql(Encoding.find('binary'))
264
+ end
265
+ end
266
+ end
267
+
268
+ {
269
+ 'char_test' => 'CHAR',
270
+ 'varchar_test' => 'VARCHAR',
271
+ 'varbinary_test' => 'VARBINARY',
272
+ 'tiny_blob_test' => 'TINYBLOB',
273
+ 'tiny_text_test' => 'TINYTEXT',
274
+ 'blob_test' => 'BLOB',
275
+ 'text_test' => 'TEXT',
276
+ 'medium_blob_test' => 'MEDIUMBLOB',
277
+ 'medium_text_test' => 'MEDIUMTEXT',
278
+ 'long_blob_test' => 'LONGBLOB',
279
+ 'long_text_test' => 'LONGTEXT'
280
+ }.each do |field, type|
281
+ it "should return a String for #{type}" do
282
+ @test_result[field].class.should eql(String)
283
+ @test_result[field].should eql("test")
284
+ end
285
+
286
+ if defined? Encoding
287
+ context "string encoding for #{type} values" do
288
+ if ['VARBINARY', 'TINYBLOB', 'BLOB', 'MEDIUMBLOB', 'LONGBLOB'].include?(type)
289
+ it "should default to binary if Encoding.default_internal is nil" do
290
+ Encoding.default_internal = nil
291
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
292
+ result['binary_test'].encoding.should eql(Encoding.find('binary'))
293
+ end
294
+
295
+ it "should not use Encoding.default_internal" do
296
+ Encoding.default_internal = Encoding.find('utf-8')
297
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
298
+ result['binary_test'].encoding.should eql(Encoding.find('binary'))
299
+ Encoding.default_internal = Encoding.find('us-ascii')
300
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
301
+ result['binary_test'].encoding.should eql(Encoding.find('binary'))
302
+ end
303
+ else
304
+ it "should default to utf-8 if Encoding.default_internal is nil" do
305
+ Encoding.default_internal = nil
306
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
307
+ result[field].encoding.should eql(Encoding.find('utf-8'))
308
+
309
+ client2 = Mysql2::Client.new :encoding => 'ascii'
310
+ client2.query "USE test"
311
+ result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
312
+ result[field].encoding.should eql(Encoding.find('us-ascii'))
313
+ end
314
+
315
+ it "should use Encoding.default_internal" do
316
+ Encoding.default_internal = Encoding.find('utf-8')
317
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
318
+ result[field].encoding.should eql(Encoding.default_internal)
319
+ Encoding.default_internal = Encoding.find('us-ascii')
320
+ result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
321
+ result[field].encoding.should eql(Encoding.default_internal)
322
+ end
323
+ end
324
+ end
325
+ end
326
+ end
327
+ end
328
+ end
data/spec/rcov.opts ADDED
@@ -0,0 +1,3 @@
1
+ --exclude spec,gem
2
+ --text-summary
3
+ --sort coverage --sort-reverse
@@ -0,0 +1,66 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rspec'
4
+ require 'mysql2'
5
+ require 'timeout'
6
+
7
+ RSpec.configure do |config|
8
+ config.before(:all) do
9
+ client = Mysql2::Client.new :host => "localhost", :username => "root", :database => 'test'
10
+ client.query %[
11
+ CREATE TABLE IF NOT EXISTS mysql2_test (
12
+ id MEDIUMINT NOT NULL AUTO_INCREMENT,
13
+ null_test VARCHAR(10),
14
+ bit_test BIT(64),
15
+ tiny_int_test TINYINT,
16
+ bool_cast_test TINYINT(1),
17
+ small_int_test SMALLINT,
18
+ medium_int_test MEDIUMINT,
19
+ int_test INT,
20
+ big_int_test BIGINT,
21
+ float_test FLOAT(10,3),
22
+ float_zero_test FLOAT(10,3),
23
+ double_test DOUBLE(10,3),
24
+ decimal_test DECIMAL(10,3),
25
+ decimal_zero_test DECIMAL(10,3),
26
+ date_test DATE,
27
+ date_time_test DATETIME,
28
+ timestamp_test TIMESTAMP,
29
+ time_test TIME,
30
+ year_test YEAR(4),
31
+ char_test CHAR(10),
32
+ varchar_test VARCHAR(10),
33
+ binary_test BINARY(10),
34
+ varbinary_test VARBINARY(10),
35
+ tiny_blob_test TINYBLOB,
36
+ tiny_text_test TINYTEXT,
37
+ blob_test BLOB,
38
+ text_test TEXT,
39
+ medium_blob_test MEDIUMBLOB,
40
+ medium_text_test MEDIUMTEXT,
41
+ long_blob_test LONGBLOB,
42
+ long_text_test LONGTEXT,
43
+ enum_test ENUM('val1', 'val2'),
44
+ set_test SET('val1', 'val2'),
45
+ PRIMARY KEY (id)
46
+ )
47
+ ]
48
+ client.query %[
49
+ INSERT INTO mysql2_test (
50
+ null_test, bit_test, tiny_int_test, bool_cast_test, small_int_test, medium_int_test, int_test, big_int_test,
51
+ float_test, float_zero_test, double_test, decimal_test, decimal_zero_test, date_test, date_time_test, timestamp_test, time_test,
52
+ year_test, char_test, varchar_test, binary_test, varbinary_test, tiny_blob_test,
53
+ tiny_text_test, blob_test, text_test, medium_blob_test, medium_text_test,
54
+ long_blob_test, long_text_test, enum_test, set_test
55
+ )
56
+
57
+ VALUES (
58
+ NULL, b'101', 1, 1, 10, 10, 10, 10,
59
+ 10.3, 0, 10.3, 10.3, 0, '2010-4-4', '2010-4-4 11:44:00', '2010-4-4 11:44:00', '11:44:00',
60
+ 2009, "test", "test", "test", "test", "test",
61
+ "test", "test", "test", "test", "test",
62
+ "test", "test", 'val1', 'val1,val2'
63
+ )
64
+ ]
65
+ end
66
+ end
@@ -0,0 +1,20 @@
1
+ BENCHMARKS = Dir["#{File.dirname(__FILE__)}/../benchmark/*.rb"].map do |path|
2
+ File.basename(path, '.rb')
3
+ end.select { |x| x != 'setup_db' }
4
+
5
+ namespace :bench do
6
+ BENCHMARKS.each do |feature|
7
+ desc "Run #{feature} benchmarks"
8
+ task(feature){ ruby "benchmark/#{feature}.rb" }
9
+ end
10
+
11
+ task :all do
12
+ BENCHMARKS.each do |feature|
13
+ ruby "benchmark/#{feature}.rb"
14
+ end
15
+ end
16
+
17
+ task :setup do
18
+ ruby 'benchmark/setup_db'
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ require "rake/extensiontask"
2
+
3
+ MYSQL_VERSION = "5.1.51"
4
+ MYSQL_MIRROR = ENV['MYSQL_MIRROR'] || "http://mysql.he.net/"
5
+
6
+ def gemspec
7
+ @clean_gemspec ||= eval(File.read(File.expand_path('../../mysql2.gemspec', __FILE__)))
8
+ end
9
+
10
+ Rake::ExtensionTask.new("mysql2", gemspec) do |ext|
11
+ # reference where the vendored MySQL got extracted
12
+ mysql_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-#{MYSQL_VERSION}-win32"))
13
+
14
+ # DRY options feed into compile or cross-compile process
15
+ windows_options = [
16
+ "--with-mysql-include=#{mysql_lib}/include",
17
+ "--with-mysql-lib=#{mysql_lib}/lib/opt"
18
+ ]
19
+
20
+ # automatically add build options to avoid need of manual input
21
+ if RUBY_PLATFORM =~ /mswin|mingw/ then
22
+ ext.config_options = windows_options
23
+ else
24
+ ext.cross_compile = true
25
+ ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
26
+ ext.cross_config_options = windows_options
27
+
28
+ # inject 1.8/1.9 pure-ruby entry point when cross compiling only
29
+ ext.cross_compiling do |spec|
30
+ spec.files << 'lib/mysql2/mysql2.rb'
31
+ end
32
+ end
33
+
34
+ ext.lib_dir = File.join 'lib', 'mysql2'
35
+
36
+ # clean compiled extension
37
+ CLEAN.include "#{ext.lib_dir}/*.#{RbConfig::CONFIG['DLEXT']}"
38
+ end
39
+ Rake::Task[:spec].prerequisites << :compile
40
+
41
+ file 'lib/mysql2/mysql2.rb' do |t|
42
+ name = gemspec.name
43
+ File.open(t.name, 'wb') do |f|
44
+ f.write <<-eoruby
45
+ RUBY_VERSION =~ /(\\d+.\\d+)/
46
+ require "#{name}/\#{$1}/#{name}"
47
+ eoruby
48
+ end
49
+ end
50
+
51
+ if Rake::Task.task_defined?(:cross)
52
+ Rake::Task[:cross].prerequisites << "lib/mysql2/mysql2.rb"
53
+ end