mysql2 0.3.8 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -220
  3. data/LICENSE +21 -0
  4. data/README.md +370 -79
  5. data/examples/eventmachine.rb +1 -1
  6. data/examples/threaded.rb +4 -6
  7. data/ext/mysql2/client.c +1017 -305
  8. data/ext/mysql2/client.h +35 -11
  9. data/ext/mysql2/extconf.rb +222 -34
  10. data/ext/mysql2/infile.c +122 -0
  11. data/ext/mysql2/infile.h +1 -0
  12. data/ext/mysql2/mysql2_ext.c +1 -0
  13. data/ext/mysql2/mysql2_ext.h +12 -14
  14. data/ext/mysql2/mysql_enc_name_to_ruby.h +168 -0
  15. data/ext/mysql2/mysql_enc_to_ruby.h +249 -0
  16. data/ext/mysql2/result.c +664 -166
  17. data/ext/mysql2/result.h +16 -6
  18. data/ext/mysql2/statement.c +595 -0
  19. data/ext/mysql2/statement.h +19 -0
  20. data/lib/mysql2/client.rb +118 -211
  21. data/lib/mysql2/console.rb +5 -0
  22. data/lib/mysql2/em.rb +23 -5
  23. data/lib/mysql2/error.rb +62 -6
  24. data/lib/mysql2/field.rb +3 -0
  25. data/lib/mysql2/statement.rb +17 -0
  26. data/lib/mysql2/version.rb +1 -1
  27. data/lib/mysql2.rb +66 -3
  28. data/spec/configuration.yml.example +11 -0
  29. data/spec/em/em_spec.rb +96 -10
  30. data/spec/my.cnf.example +9 -0
  31. data/spec/mysql2/client_spec.rb +779 -205
  32. data/spec/mysql2/error_spec.rb +58 -45
  33. data/spec/mysql2/result_spec.rb +316 -159
  34. data/spec/mysql2/statement_spec.rb +776 -0
  35. data/spec/spec_helper.rb +97 -56
  36. data/spec/ssl/ca-cert.pem +17 -0
  37. data/spec/ssl/ca-key.pem +27 -0
  38. data/spec/ssl/ca.cnf +22 -0
  39. data/spec/ssl/cert.cnf +22 -0
  40. data/spec/ssl/client-cert.pem +17 -0
  41. data/spec/ssl/client-key.pem +27 -0
  42. data/spec/ssl/client-req.pem +15 -0
  43. data/spec/ssl/gen_certs.sh +48 -0
  44. data/spec/ssl/pkcs8-client-key.pem +28 -0
  45. data/spec/ssl/pkcs8-server-key.pem +28 -0
  46. data/spec/ssl/server-cert.pem +17 -0
  47. data/spec/ssl/server-key.pem +27 -0
  48. data/spec/ssl/server-req.pem +15 -0
  49. data/spec/test_data +1 -0
  50. data/support/5072E1F5.asc +432 -0
  51. data/support/libmysql.def +219 -0
  52. data/support/mysql_enc_to_ruby.rb +81 -0
  53. data/support/ruby_enc_to_mysql.rb +61 -0
  54. metadata +77 -196
  55. data/.gitignore +0 -12
  56. data/.rspec +0 -3
  57. data/.rvmrc +0 -1
  58. data/.travis.yml +0 -7
  59. data/Gemfile +0 -3
  60. data/MIT-LICENSE +0 -20
  61. data/Rakefile +0 -5
  62. data/benchmark/active_record.rb +0 -51
  63. data/benchmark/active_record_threaded.rb +0 -42
  64. data/benchmark/allocations.rb +0 -33
  65. data/benchmark/escape.rb +0 -36
  66. data/benchmark/query_with_mysql_casting.rb +0 -80
  67. data/benchmark/query_without_mysql_casting.rb +0 -56
  68. data/benchmark/sequel.rb +0 -37
  69. data/benchmark/setup_db.rb +0 -119
  70. data/benchmark/threaded.rb +0 -44
  71. data/mysql2.gemspec +0 -29
  72. data/tasks/benchmarks.rake +0 -20
  73. data/tasks/compile.rake +0 -71
  74. data/tasks/rspec.rake +0 -16
  75. data/tasks/vendor_mysql.rake +0 -40
@@ -1,80 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- require 'rubygems'
5
- require 'benchmark'
6
- require 'mysql'
7
- require 'mysql2'
8
- require 'do_mysql'
9
-
10
- number_of = 100
11
- database = 'test'
12
- sql = "SELECT * FROM mysql2_test LIMIT 100"
13
-
14
- class Mysql
15
- include Enumerable
16
- end
17
-
18
- def mysql_cast(type, value)
19
- case type
20
- when Mysql::Field::TYPE_NULL
21
- nil
22
- when Mysql::Field::TYPE_TINY, Mysql::Field::TYPE_SHORT, Mysql::Field::TYPE_LONG,
23
- Mysql::Field::TYPE_INT24, Mysql::Field::TYPE_LONGLONG, Mysql::Field::TYPE_YEAR
24
- value.to_i
25
- when Mysql::Field::TYPE_DECIMAL, Mysql::Field::TYPE_NEWDECIMAL
26
- BigDecimal.new(value)
27
- when Mysql::Field::TYPE_DOUBLE, Mysql::Field::TYPE_FLOAT
28
- value.to_f
29
- when Mysql::Field::TYPE_DATE
30
- Date.parse(value)
31
- when Mysql::Field::TYPE_TIME, Mysql::Field::TYPE_DATETIME, Mysql::Field::TYPE_TIMESTAMP
32
- Time.parse(value)
33
- when Mysql::Field::TYPE_BLOB, Mysql::Field::TYPE_BIT, Mysql::Field::TYPE_STRING,
34
- Mysql::Field::TYPE_VAR_STRING, Mysql::Field::TYPE_CHAR, Mysql::Field::TYPE_SET
35
- Mysql::Field::TYPE_ENUM
36
- value
37
- else
38
- value
39
- end
40
- end
41
-
42
- Benchmark.bmbm do |x|
43
- mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
44
- mysql2.query "USE #{database}"
45
- x.report "Mysql2" do
46
- number_of.times do
47
- mysql2_result = mysql2.query sql, :symbolize_keys => true
48
- mysql2_result.each do |res|
49
- # puts res.inspect
50
- end
51
- end
52
- end
53
-
54
- mysql = Mysql.new("localhost", "root")
55
- mysql.query "USE #{database}"
56
- x.report "Mysql" do
57
- number_of.times do
58
- mysql_result = mysql.query sql
59
- fields = mysql_result.fetch_fields
60
- mysql_result.each do |row|
61
- row_hash = {}
62
- row.each_with_index do |f, j|
63
- row_hash[fields[j].name.to_sym] = mysql_cast(fields[j].type, row[j])
64
- end
65
- # puts row_hash.inspect
66
- end
67
- end
68
- end
69
-
70
- do_mysql = DataObjects::Connection.new("mysql://localhost/#{database}")
71
- command = do_mysql.create_command sql
72
- x.report "do_mysql" do
73
- number_of.times do
74
- do_result = command.execute_reader
75
- do_result.each do |res|
76
- # puts res.inspect
77
- end
78
- end
79
- end
80
- end
@@ -1,56 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- require 'rubygems'
5
- require 'benchmark'
6
- require 'mysql'
7
- require 'mysql2'
8
- require 'do_mysql'
9
-
10
- number_of = 100
11
- database = 'test'
12
- sql = "SELECT * FROM mysql2_test LIMIT 100"
13
-
14
- Benchmark.bmbm do |x|
15
- mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
16
- mysql2.query "USE #{database}"
17
- x.report "Mysql2 (cast: true)" do
18
- number_of.times do
19
- mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => true
20
- mysql2_result.each do |res|
21
- # puts res.inspect
22
- end
23
- end
24
- end
25
-
26
- x.report "Mysql2 (cast: false)" do
27
- number_of.times do
28
- mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => false
29
- mysql2_result.each do |res|
30
- # puts res.inspect
31
- end
32
- end
33
- end
34
-
35
- mysql = Mysql.new("localhost", "root")
36
- mysql.query "USE #{database}"
37
- x.report "Mysql" do
38
- number_of.times do
39
- mysql_result = mysql.query sql
40
- mysql_result.each_hash do |res|
41
- # puts res.inspect
42
- end
43
- end
44
- end
45
-
46
- do_mysql = DataObjects::Connection.new("mysql://localhost/#{database}")
47
- command = DataObjects::Mysql::Command.new do_mysql, sql
48
- x.report "do_mysql" do
49
- number_of.times do
50
- do_result = command.execute_reader
51
- do_result.each do |res|
52
- # puts res.inspect
53
- end
54
- end
55
- end
56
- end
data/benchmark/sequel.rb DELETED
@@ -1,37 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- require 'rubygems'
5
- require 'benchmark'
6
- require 'mysql2'
7
- require 'sequel'
8
- require 'sequel/adapters/do'
9
-
10
- number_of = 10
11
- mysql2_opts = "mysql2://localhost/test"
12
- mysql_opts = "mysql://localhost/test"
13
- do_mysql_opts = "do:mysql://localhost/test"
14
-
15
- class Mysql2Model < Sequel::Model(Sequel.connect(mysql2_opts)[:mysql2_test]); end
16
- class MysqlModel < Sequel::Model(Sequel.connect(mysql_opts)[:mysql2_test]); end
17
- class DOMysqlModel < Sequel::Model(Sequel.connect(do_mysql_opts)[:mysql2_test]); end
18
-
19
- Benchmark.bmbm do |x|
20
- x.report "Mysql2" do
21
- number_of.times do
22
- Mysql2Model.limit(1000).all
23
- end
24
- end
25
-
26
- x.report "do:mysql" do
27
- number_of.times do
28
- DOMysqlModel.limit(1000).all
29
- end
30
- end
31
-
32
- x.report "Mysql" do
33
- number_of.times do
34
- MysqlModel.limit(1000).all
35
- end
36
- end
37
- end
@@ -1,119 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- # This script is for generating psudo-random data into a single table consisting of nearly every
5
- # data type MySQL 5.1 supports.
6
- #
7
- # It's meant to be used with the query.rb benchmark script (or others in the future)
8
-
9
- require 'mysql2'
10
- require 'rubygems'
11
- require 'faker'
12
-
13
- num = ENV['NUM'] && ENV['NUM'].to_i || 10_000
14
-
15
- create_table_sql = %[
16
- CREATE TABLE IF NOT EXISTS mysql2_test (
17
- null_test VARCHAR(10),
18
- bit_test BIT,
19
- tiny_int_test TINYINT,
20
- small_int_test SMALLINT,
21
- medium_int_test MEDIUMINT,
22
- int_test INT,
23
- big_int_test BIGINT,
24
- float_test FLOAT(10,3),
25
- float_zero_test FLOAT(10,3),
26
- double_test DOUBLE(10,3),
27
- decimal_test DECIMAL(10,3),
28
- decimal_zero_test DECIMAL(10,3),
29
- date_test DATE,
30
- date_time_test DATETIME,
31
- timestamp_test TIMESTAMP,
32
- time_test TIME,
33
- year_test YEAR(4),
34
- char_test CHAR(10),
35
- varchar_test VARCHAR(10),
36
- binary_test BINARY(10),
37
- varbinary_test VARBINARY(10),
38
- tiny_blob_test TINYBLOB,
39
- tiny_text_test TINYTEXT,
40
- blob_test BLOB,
41
- text_test TEXT,
42
- medium_blob_test MEDIUMBLOB,
43
- medium_text_test MEDIUMTEXT,
44
- long_blob_test LONGBLOB,
45
- long_text_test LONGTEXT,
46
- enum_test ENUM('val1', 'val2'),
47
- set_test SET('val1', 'val2')
48
- ) DEFAULT CHARSET=utf8
49
- ]
50
-
51
- # connect to localhost by default, pass options as needed
52
- @client = Mysql2::Client.new :host => "localhost", :username => "root", :database => "test"
53
-
54
- @client.query create_table_sql
55
-
56
- def insert_record(args)
57
- insert_sql = "
58
- INSERT INTO mysql2_test (
59
- null_test, bit_test, tiny_int_test, small_int_test, medium_int_test, int_test, big_int_test,
60
- float_test, float_zero_test, double_test, decimal_test, decimal_zero_test, date_test, date_time_test, timestamp_test, time_test,
61
- year_test, char_test, varchar_test, binary_test, varbinary_test, tiny_blob_test,
62
- tiny_text_test, blob_test, text_test, medium_blob_test, medium_text_test,
63
- long_blob_test, long_text_test, enum_test, set_test
64
- )
65
-
66
- VALUES (
67
- NULL, #{args[:bit_test]}, #{args[:tiny_int_test]}, #{args[:small_int_test]}, #{args[:medium_int_test]}, #{args[:int_test]}, #{args[:big_int_test]},
68
- #{args[:float_test]}, #{args[:float_zero_test]}, #{args[:double_test]}, #{args[:decimal_test]}, #{args[:decimal_zero_test]}, '#{args[:date_test]}', '#{args[:date_time_test]}', '#{args[:timestamp_test]}', '#{args[:time_test]}',
69
- #{args[:year_test]}, '#{args[:char_test]}', '#{args[:varchar_test]}', '#{args[:binary_test]}', '#{args[:varbinary_test]}', '#{args[:tiny_blob_test]}',
70
- '#{args[:tiny_text_test]}', '#{args[:blob_test]}', '#{args[:text_test]}', '#{args[:medium_blob_test]}', '#{args[:medium_text_test]}',
71
- '#{args[:long_blob_test]}', '#{args[:long_text_test]}', '#{args[:enum_test]}', '#{args[:set_test]}'
72
- )
73
- "
74
- @client.query insert_sql
75
- end
76
-
77
- puts "Creating #{num} records"
78
- num.times do |n|
79
- five_words = Faker::Lorem.words(rand(5))
80
- twenty5_paragraphs = Faker::Lorem.paragraphs(rand(25))
81
- insert_record(
82
- :bit_test => 1,
83
- :tiny_int_test => rand(128),
84
- :small_int_test => rand(32767),
85
- :medium_int_test => rand(8388607),
86
- :int_test => rand(2147483647),
87
- :big_int_test => rand(9223372036854775807),
88
- :float_test => rand(32767)/1.87,
89
- :float_zero_test => 0.0,
90
- :double_test => rand(8388607)/1.87,
91
- :decimal_test => rand(8388607)/1.87,
92
- :decimal_zero_test => 0,
93
- :date_test => '2010-4-4',
94
- :date_time_test => '2010-4-4 11:44:00',
95
- :timestamp_test => '2010-4-4 11:44:00',
96
- :time_test => '11:44:00',
97
- :year_test => Time.now.year,
98
- :char_test => five_words,
99
- :varchar_test => five_words,
100
- :binary_test => five_words,
101
- :varbinary_test => five_words,
102
- :tiny_blob_test => five_words,
103
- :tiny_text_test => Faker::Lorem.paragraph(rand(5)),
104
- :blob_test => twenty5_paragraphs,
105
- :text_test => twenty5_paragraphs,
106
- :medium_blob_test => twenty5_paragraphs,
107
- :medium_text_test => twenty5_paragraphs,
108
- :long_blob_test => twenty5_paragraphs,
109
- :long_text_test => twenty5_paragraphs,
110
- :enum_test => ['val1', 'val2'].rand,
111
- :set_test => ['val1', 'val2', 'val1,val2'].rand
112
- )
113
- if n % 100 == 0
114
- $stdout.putc '.'
115
- $stdout.flush
116
- end
117
- end
118
- puts
119
- puts "Done"
@@ -1,44 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- require 'rubygems'
5
- require 'benchmark'
6
- require 'active_record'
7
-
8
- mysql2_opts = {
9
- :adapter => 'mysql2',
10
- :database => 'test',
11
- :pool => 25
12
- }
13
- ActiveRecord::Base.establish_connection(mysql2_opts)
14
- x = Benchmark.realtime do
15
- threads = []
16
- 25.times do
17
- threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
18
- end
19
- threads.each {|t| t.join }
20
- end
21
- puts x
22
-
23
- mysql2_opts = {
24
- :adapter => 'mysql',
25
- :database => 'test',
26
- :pool => 25
27
- }
28
- ActiveRecord::Base.establish_connection(mysql2_opts)
29
- x = Benchmark.realtime do
30
- threads = []
31
- 25.times do
32
- threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
33
- end
34
- threads.each {|t| t.join }
35
- end
36
- puts x
37
-
38
- # these results are similar on 1.8.7, 1.9.2 and rbx-head
39
- #
40
- # $ bundle exec ruby benchmarks/threaded.rb
41
- # 1.0774750709533691
42
- #
43
- # and using the mysql gem
44
- # 25.099437952041626
data/mysql2.gemspec DELETED
@@ -1,29 +0,0 @@
1
- require File.expand_path('../lib/mysql2/version', __FILE__)
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{mysql2}
5
- s.version = Mysql2::VERSION
6
- s.authors = ["Brian Lopez"]
7
- s.date = Time.now.utc.strftime("%Y-%m-%d")
8
- s.email = %q{seniorlopez@gmail.com}
9
- s.extensions = ["ext/mysql2/extconf.rb"]
10
- s.files = `git ls-files`.split("\n")
11
- s.homepage = %q{http://github.com/brianmario/mysql2}
12
- s.rdoc_options = ["--charset=UTF-8"]
13
- s.require_paths = ["lib"]
14
- s.rubygems_version = %q{1.4.2}
15
- s.summary = %q{A simple, fast Mysql library for Ruby, binding to libmysql}
16
- s.test_files = `git ls-files spec examples`.split("\n")
17
-
18
- # tests
19
- s.add_development_dependency 'eventmachine'
20
- s.add_development_dependency 'rake-compiler', "~> 0.7.7"
21
- s.add_development_dependency 'rake', '0.8.7' # NB: 0.8.7 required by rake-compiler 0.7.9
22
- s.add_development_dependency 'rspec'
23
- # benchmarks
24
- s.add_development_dependency 'activerecord'
25
- s.add_development_dependency 'mysql'
26
- s.add_development_dependency 'do_mysql'
27
- s.add_development_dependency 'sequel'
28
- s.add_development_dependency 'faker'
29
- 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