mysql2 0.3.10 → 0.5.3

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 (61) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -230
  3. data/LICENSE +21 -0
  4. data/README.md +405 -80
  5. data/ext/mysql2/client.c +1110 -335
  6. data/ext/mysql2/client.h +18 -32
  7. data/ext/mysql2/extconf.rb +228 -37
  8. data/ext/mysql2/infile.c +122 -0
  9. data/ext/mysql2/infile.h +1 -0
  10. data/ext/mysql2/mysql2_ext.c +3 -1
  11. data/ext/mysql2/mysql2_ext.h +18 -16
  12. data/ext/mysql2/mysql_enc_name_to_ruby.h +172 -0
  13. data/ext/mysql2/mysql_enc_to_ruby.h +310 -0
  14. data/ext/mysql2/result.c +671 -226
  15. data/ext/mysql2/result.h +15 -6
  16. data/ext/mysql2/statement.c +604 -0
  17. data/ext/mysql2/statement.h +17 -0
  18. data/ext/mysql2/wait_for_single_fd.h +2 -1
  19. data/lib/mysql2/client.rb +125 -212
  20. data/lib/mysql2/console.rb +5 -0
  21. data/lib/mysql2/em.rb +24 -8
  22. data/lib/mysql2/error.rb +93 -8
  23. data/lib/mysql2/field.rb +3 -0
  24. data/lib/mysql2/result.rb +2 -0
  25. data/lib/mysql2/statement.rb +11 -0
  26. data/lib/mysql2/version.rb +1 -1
  27. data/lib/mysql2.rb +70 -5
  28. data/support/5072E1F5.asc +432 -0
  29. data/support/libmysql.def +219 -0
  30. data/support/mysql_enc_to_ruby.rb +86 -0
  31. data/support/ruby_enc_to_mysql.rb +63 -0
  32. metadata +45 -214
  33. data/.gitignore +0 -12
  34. data/.rspec +0 -3
  35. data/.rvmrc +0 -1
  36. data/.travis.yml +0 -7
  37. data/Gemfile +0 -3
  38. data/MIT-LICENSE +0 -20
  39. data/Rakefile +0 -5
  40. data/benchmark/active_record.rb +0 -51
  41. data/benchmark/active_record_threaded.rb +0 -42
  42. data/benchmark/allocations.rb +0 -33
  43. data/benchmark/escape.rb +0 -36
  44. data/benchmark/query_with_mysql_casting.rb +0 -80
  45. data/benchmark/query_without_mysql_casting.rb +0 -56
  46. data/benchmark/sequel.rb +0 -37
  47. data/benchmark/setup_db.rb +0 -119
  48. data/benchmark/threaded.rb +0 -44
  49. data/examples/eventmachine.rb +0 -21
  50. data/examples/threaded.rb +0 -20
  51. data/mysql2.gemspec +0 -29
  52. data/spec/em/em_spec.rb +0 -50
  53. data/spec/mysql2/client_spec.rb +0 -465
  54. data/spec/mysql2/error_spec.rb +0 -69
  55. data/spec/mysql2/result_spec.rb +0 -388
  56. data/spec/rcov.opts +0 -3
  57. data/spec/spec_helper.rb +0 -67
  58. data/tasks/benchmarks.rake +0 -20
  59. data/tasks/compile.rake +0 -71
  60. data/tasks/rspec.rake +0 -16
  61. data/tasks/vendor_mysql.rake +0 -40
@@ -1,388 +0,0 @@
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
- it "should respond to #count, which is aliased as #size" do
32
- r = @client.query "SELECT 1"
33
- r.should respond_to :count
34
- r.should respond_to :size
35
- end
36
-
37
- it "should be able to return the number of rows in the result set" do
38
- r = @client.query "SELECT 1"
39
- r.count.should eql(1)
40
- r.size.should eql(1)
41
- end
42
-
43
- context "metadata queries" do
44
- it "should show tables" do
45
- @result = @client.query "SHOW TABLES"
46
- end
47
- end
48
-
49
- context "#each" do
50
- it "should yield rows as hash's" do
51
- @result.each do |row|
52
- row.class.should eql(Hash)
53
- end
54
- end
55
-
56
- it "should yield rows as hash's with symbol keys if :symbolize_keys was set to true" do
57
- @result.each(:symbolize_keys => true) do |row|
58
- row.keys.first.class.should eql(Symbol)
59
- end
60
- end
61
-
62
- it "should be able to return results as an array" do
63
- @result.each(:as => :array) do |row|
64
- row.class.should eql(Array)
65
- end
66
- end
67
-
68
- it "should cache previously yielded results by default" do
69
- @result.first.object_id.should eql(@result.first.object_id)
70
- end
71
-
72
- it "should not cache previously yielded results if cache_rows is disabled" do
73
- result = @client.query "SELECT 1", :cache_rows => false
74
- result.first.object_id.should_not eql(result.first.object_id)
75
- end
76
- end
77
-
78
- context "#fields" do
79
- before(:each) do
80
- @client.query "USE test"
81
- @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1")
82
- end
83
-
84
- it "method should exist" do
85
- @test_result.should respond_to(:fields)
86
- end
87
-
88
- it "should return an array of field names in proper order" do
89
- result = @client.query "SELECT 'a', 'b', 'c'"
90
- result.fields.should eql(['a', 'b', 'c'])
91
- end
92
- end
93
-
94
- context "row data type mapping" do
95
- before(:each) do
96
- @client.query "USE test"
97
- @test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
98
- end
99
-
100
- it "should return nil values for NULL and strings for everything else when :cast is false" do
101
- result = @client.query('SELECT null_test, tiny_int_test, bool_cast_test, int_test, date_test, enum_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast => false).first
102
- result["null_test"].should be_nil
103
- result["tiny_int_test"].should == "1"
104
- result["bool_cast_test"].should == "1"
105
- result["int_test"].should == "10"
106
- result["date_test"].should == "2010-04-04"
107
- result["enum_test"].should == "val1"
108
- end
109
-
110
- it "should return nil for a NULL value" do
111
- @test_result['null_test'].class.should eql(NilClass)
112
- @test_result['null_test'].should eql(nil)
113
- end
114
-
115
- it "should return Fixnum for a BIT value" do
116
- @test_result['bit_test'].class.should eql(String)
117
- @test_result['bit_test'].should eql("\000\000\000\000\000\000\000\005")
118
- end
119
-
120
- it "should return Fixnum for a TINYINT value" do
121
- [Fixnum, Bignum].should include(@test_result['tiny_int_test'].class)
122
- @test_result['tiny_int_test'].should eql(1)
123
- end
124
-
125
- it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
126
- @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (1)'
127
- id1 = @client.last_id
128
- @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (0)'
129
- id2 = @client.last_id
130
-
131
- result1 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast_booleans => true
132
- result2 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1', :cast_booleans => true
133
- result1.first['bool_cast_test'].should be_true
134
- result2.first['bool_cast_test'].should be_false
135
-
136
- @client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
137
- end
138
-
139
- it "should return Fixnum for a SMALLINT value" do
140
- [Fixnum, Bignum].should include(@test_result['small_int_test'].class)
141
- @test_result['small_int_test'].should eql(10)
142
- end
143
-
144
- it "should return Fixnum for a MEDIUMINT value" do
145
- [Fixnum, Bignum].should include(@test_result['medium_int_test'].class)
146
- @test_result['medium_int_test'].should eql(10)
147
- end
148
-
149
- it "should return Fixnum for an INT value" do
150
- [Fixnum, Bignum].should include(@test_result['int_test'].class)
151
- @test_result['int_test'].should eql(10)
152
- end
153
-
154
- it "should return Fixnum for a BIGINT value" do
155
- [Fixnum, Bignum].should include(@test_result['big_int_test'].class)
156
- @test_result['big_int_test'].should eql(10)
157
- end
158
-
159
- it "should return Fixnum for a YEAR value" do
160
- [Fixnum, Bignum].should include(@test_result['year_test'].class)
161
- @test_result['year_test'].should eql(2009)
162
- end
163
-
164
- it "should return BigDecimal for a DECIMAL value" do
165
- @test_result['decimal_test'].class.should eql(BigDecimal)
166
- @test_result['decimal_test'].should eql(10.3)
167
- end
168
-
169
- it "should return Float for a FLOAT value" do
170
- @test_result['float_test'].class.should eql(Float)
171
- @test_result['float_test'].should eql(10.3)
172
- end
173
-
174
- it "should return Float for a DOUBLE value" do
175
- @test_result['double_test'].class.should eql(Float)
176
- @test_result['double_test'].should eql(10.3)
177
- end
178
-
179
- it "should return Time for a DATETIME value when within the supported range" do
180
- @test_result['date_time_test'].class.should eql(Time)
181
- @test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2010-04-04 11:44:00')
182
- end
183
-
184
- if 1.size == 4 # 32bit
185
- if RUBY_VERSION =~ /1.9/
186
- klass = Time
187
- else
188
- klass = DateTime
189
- end
190
-
191
- it "should return DateTime when timestamp is < 1901-12-13 20:45:52" do
192
- # 1901-12-13T20:45:52 is the min for 32bit Ruby 1.8
193
- r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
194
- r.first['test'].class.should eql(klass)
195
- end
196
-
197
- it "should return DateTime when timestamp is > 2038-01-19T03:14:07" do
198
- # 2038-01-19T03:14:07 is the max for 32bit Ruby 1.8
199
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
200
- r.first['test'].class.should eql(klass)
201
- end
202
- elsif 1.size == 8 # 64bit
203
- if RUBY_VERSION =~ /1.9/
204
- it "should return Time when timestamp is < 1901-12-13 20:45:52" do
205
- r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
206
- r.first['test'].class.should eql(Time)
207
- end
208
-
209
- it "should return Time when timestamp is > 2038-01-19T03:14:07" do
210
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
211
- r.first['test'].class.should eql(Time)
212
- end
213
- else
214
- it "should return Time when timestamp is > 0138-12-31 11:59:59" do
215
- r = @client.query("SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test")
216
- r.first['test'].class.should eql(Time)
217
- end
218
-
219
- it "should return DateTime when timestamp is < 0139-1-1T00:00:00" do
220
- r = @client.query("SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test")
221
- r.first['test'].class.should eql(DateTime)
222
- end
223
-
224
- it "should return Time when timestamp is > 2038-01-19T03:14:07" do
225
- r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
226
- r.first['test'].class.should eql(Time)
227
- end
228
- end
229
- end
230
-
231
- it "should return Time for a TIMESTAMP value when within the supported range" do
232
- @test_result['timestamp_test'].class.should eql(Time)
233
- @test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2010-04-04 11:44:00')
234
- end
235
-
236
- it "should return Time for a TIME value" do
237
- @test_result['time_test'].class.should eql(Time)
238
- @test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S").should eql('2000-01-01 11:44:00')
239
- end
240
-
241
- it "should return Date for a DATE value" do
242
- @test_result['date_test'].class.should eql(Date)
243
- @test_result['date_test'].strftime("%Y-%m-%d").should eql('2010-04-04')
244
- end
245
-
246
- it "should return String for an ENUM value" do
247
- @test_result['enum_test'].class.should eql(String)
248
- @test_result['enum_test'].should eql('val1')
249
- end
250
-
251
- if defined? Encoding
252
- context "string encoding for ENUM values" do
253
- it "should default to the connection's encoding if Encoding.default_internal is nil" do
254
- Encoding.default_internal = nil
255
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
256
- result['enum_test'].encoding.should eql(Encoding.find('utf-8'))
257
-
258
- client2 = Mysql2::Client.new :encoding => 'ascii'
259
- client2.query "USE test"
260
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
261
- result['enum_test'].encoding.should eql(Encoding.find('us-ascii'))
262
- end
263
-
264
- it "should use Encoding.default_internal" do
265
- Encoding.default_internal = Encoding.find('utf-8')
266
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
267
- result['enum_test'].encoding.should eql(Encoding.default_internal)
268
- Encoding.default_internal = Encoding.find('us-ascii')
269
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
270
- result['enum_test'].encoding.should eql(Encoding.default_internal)
271
- end
272
- end
273
- end
274
-
275
- it "should return String for a SET value" do
276
- @test_result['set_test'].class.should eql(String)
277
- @test_result['set_test'].should eql('val1,val2')
278
- end
279
-
280
- if defined? Encoding
281
- context "string encoding for SET values" do
282
- it "should default to the connection's encoding if Encoding.default_internal is nil" do
283
- Encoding.default_internal = nil
284
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
285
- result['set_test'].encoding.should eql(Encoding.find('utf-8'))
286
-
287
- client2 = Mysql2::Client.new :encoding => 'ascii'
288
- client2.query "USE test"
289
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
290
- result['set_test'].encoding.should eql(Encoding.find('us-ascii'))
291
- end
292
-
293
- it "should use Encoding.default_internal" do
294
- Encoding.default_internal = Encoding.find('utf-8')
295
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
296
- result['set_test'].encoding.should eql(Encoding.default_internal)
297
- Encoding.default_internal = Encoding.find('us-ascii')
298
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
299
- result['set_test'].encoding.should eql(Encoding.default_internal)
300
- end
301
- end
302
- end
303
-
304
- it "should return String for a BINARY value" do
305
- @test_result['binary_test'].class.should eql(String)
306
- @test_result['binary_test'].should eql("test#{"\000"*6}")
307
- end
308
-
309
- if defined? Encoding
310
- context "string encoding for BINARY values" do
311
- it "should default to binary if Encoding.default_internal is nil" do
312
- Encoding.default_internal = nil
313
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
314
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
315
- end
316
-
317
- it "should not use Encoding.default_internal" do
318
- Encoding.default_internal = Encoding.find('utf-8')
319
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
320
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
321
- Encoding.default_internal = Encoding.find('us-ascii')
322
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
323
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
324
- end
325
- end
326
- end
327
-
328
- {
329
- 'char_test' => 'CHAR',
330
- 'varchar_test' => 'VARCHAR',
331
- 'varbinary_test' => 'VARBINARY',
332
- 'tiny_blob_test' => 'TINYBLOB',
333
- 'tiny_text_test' => 'TINYTEXT',
334
- 'blob_test' => 'BLOB',
335
- 'text_test' => 'TEXT',
336
- 'medium_blob_test' => 'MEDIUMBLOB',
337
- 'medium_text_test' => 'MEDIUMTEXT',
338
- 'long_blob_test' => 'LONGBLOB',
339
- 'long_text_test' => 'LONGTEXT'
340
- }.each do |field, type|
341
- it "should return a String for #{type}" do
342
- @test_result[field].class.should eql(String)
343
- @test_result[field].should eql("test")
344
- end
345
-
346
- if defined? Encoding
347
- context "string encoding for #{type} values" do
348
- if ['VARBINARY', 'TINYBLOB', 'BLOB', 'MEDIUMBLOB', 'LONGBLOB'].include?(type)
349
- it "should default to binary if Encoding.default_internal is nil" do
350
- Encoding.default_internal = nil
351
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
352
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
353
- end
354
-
355
- it "should not use Encoding.default_internal" do
356
- Encoding.default_internal = Encoding.find('utf-8')
357
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
358
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
359
- Encoding.default_internal = Encoding.find('us-ascii')
360
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
361
- result['binary_test'].encoding.should eql(Encoding.find('binary'))
362
- end
363
- else
364
- it "should default to utf-8 if Encoding.default_internal is nil" do
365
- Encoding.default_internal = nil
366
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
367
- result[field].encoding.should eql(Encoding.find('utf-8'))
368
-
369
- client2 = Mysql2::Client.new :encoding => 'ascii'
370
- client2.query "USE test"
371
- result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
372
- result[field].encoding.should eql(Encoding.find('us-ascii'))
373
- end
374
-
375
- it "should use Encoding.default_internal" do
376
- Encoding.default_internal = Encoding.find('utf-8')
377
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
378
- result[field].encoding.should eql(Encoding.default_internal)
379
- Encoding.default_internal = Encoding.find('us-ascii')
380
- result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
381
- result[field].encoding.should eql(Encoding.default_internal)
382
- end
383
- end
384
- end
385
- end
386
- end
387
- end
388
- end
data/spec/rcov.opts DELETED
@@ -1,3 +0,0 @@
1
- --exclude spec,gem
2
- --text-summary
3
- --sort coverage --sort-reverse
data/spec/spec_helper.rb DELETED
@@ -1,67 +0,0 @@
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 "DELETE FROM mysql2_test;"
49
- client.query %[
50
- INSERT INTO mysql2_test (
51
- null_test, bit_test, tiny_int_test, bool_cast_test, small_int_test, medium_int_test, int_test, big_int_test,
52
- float_test, float_zero_test, double_test, decimal_test, decimal_zero_test, date_test, date_time_test, timestamp_test, time_test,
53
- year_test, char_test, varchar_test, binary_test, varbinary_test, tiny_blob_test,
54
- tiny_text_test, blob_test, text_test, medium_blob_test, medium_text_test,
55
- long_blob_test, long_text_test, enum_test, set_test
56
- )
57
-
58
- VALUES (
59
- NULL, b'101', 1, 1, 10, 10, 10, 10,
60
- 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',
61
- 2009, "test", "test", "test", "test", "test",
62
- "test", "test", "test", "test", "test",
63
- "test", "test", 'val1', 'val1,val2'
64
- )
65
- ]
66
- end
67
- end
@@ -1,20 +0,0 @@
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
data/tasks/compile.rake DELETED
@@ -1,71 +0,0 @@
1
- require "rake/extensiontask"
2
-
3
- CONNECTOR_VERSION = "6.0.2" #"mysql-connector-c-noinstall-6.0.2-win32.zip"
4
- CONNECTOR_MIRROR = ENV['CONNECTOR_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
- connector_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32"))
13
-
14
- # DRY options feed into compile or cross-compile process
15
- windows_options = [
16
- "--with-mysql-include=#{connector_lib}/include",
17
- "--with-mysql-lib=#{connector_lib}/lib"
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
- spec.post_install_message = <<-POST_INSTALL_MESSAGE
32
-
33
- ======================================================================================================
34
-
35
- You've installed the binary version of #{spec.name}.
36
- It was built using MySQL Connector/C version #{CONNECTOR_VERSION}.
37
- It's recommended to use the exact same version to avoid potential issues.
38
-
39
- At the time of building this gem, the necessary DLL files where available
40
- in the following download:
41
-
42
- http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip/from/pick
43
-
44
- And put lib\\libmysql.dll file in your Ruby bin directory, for example C:\\Ruby\\bin
45
-
46
- ======================================================================================================
47
-
48
- POST_INSTALL_MESSAGE
49
- end
50
- end
51
-
52
- ext.lib_dir = File.join 'lib', 'mysql2'
53
-
54
- # clean compiled extension
55
- CLEAN.include "#{ext.lib_dir}/*.#{RbConfig::CONFIG['DLEXT']}"
56
- end
57
- Rake::Task[:spec].prerequisites << :compile
58
-
59
- file 'lib/mysql2/mysql2.rb' do |t|
60
- name = gemspec.name
61
- File.open(t.name, 'wb') do |f|
62
- f.write <<-eoruby
63
- RUBY_VERSION =~ /(\\d+.\\d+)/
64
- require "#{name}/\#{$1}/#{name}"
65
- eoruby
66
- end
67
- end
68
-
69
- if Rake::Task.task_defined?(:cross)
70
- Rake::Task[:cross].prerequisites << "lib/mysql2/mysql2.rb"
71
- end
data/tasks/rspec.rake DELETED
@@ -1,16 +0,0 @@
1
- begin
2
- require 'rspec'
3
- require 'rspec/core/rake_task'
4
-
5
- desc "Run all examples with RCov"
6
- RSpec::Core::RakeTask.new('spec:rcov') do |t|
7
- t.rcov = true
8
- end
9
- RSpec::Core::RakeTask.new('spec') do |t|
10
- t.verbose = true
11
- end
12
-
13
- task :default => :spec
14
- rescue LoadError
15
- puts "rspec, or one of its dependencies, is not available. Install it with: sudo gem install rspec"
16
- end
@@ -1,40 +0,0 @@
1
- require 'rake/clean'
2
- require 'rake/extensioncompiler'
3
-
4
- # download mysql library and headers
5
- directory "vendor"
6
-
7
- file "vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip" => ["vendor"] do |t|
8
- url = "http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip/from/#{CONNECTOR_MIRROR}/"
9
- when_writing "downloading #{t.name}" do
10
- cd File.dirname(t.name) do
11
- sh "wget -c #{url} || curl -C - -O #{url}"
12
- end
13
- end
14
- end
15
-
16
- file "vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/include/mysql.h" => ["vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip"] do |t|
17
- full_file = File.expand_path(t.prerequisites.last)
18
- when_writing "creating #{t.name}" do
19
- cd "vendor" do
20
- sh "unzip #{full_file} mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/bin/** mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/include/** mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/lib/**"
21
- end
22
- # update file timestamp to avoid Rake perform this extraction again.
23
- touch t.name
24
- end
25
- end
26
-
27
- # clobber expanded packages
28
- CLOBBER.include("vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32")
29
-
30
- # vendor:mysql
31
- task 'vendor:mysql' => ["vendor/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32/include/mysql.h"]
32
-
33
- # hook into cross compilation vendored mysql dependency
34
- if RUBY_PLATFORM =~ /mingw|mswin/ then
35
- Rake::Task['compile'].prerequisites.unshift 'vendor:mysql'
36
- else
37
- if Rake::Task.tasks.map {|t| t.name }.include? 'cross'
38
- Rake::Task['cross'].prerequisites.unshift 'vendor:mysql'
39
- end
40
- end