mysql2 0.2.24 → 0.3.0

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 (57) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/CHANGELOG.md +148 -0
  5. data/Gemfile +3 -0
  6. data/README.rdoc +257 -0
  7. data/Rakefile +5 -0
  8. data/benchmark/active_record.rb +51 -0
  9. data/benchmark/active_record_threaded.rb +42 -0
  10. data/benchmark/allocations.rb +33 -0
  11. data/benchmark/escape.rb +36 -0
  12. data/benchmark/query_with_mysql_casting.rb +80 -0
  13. data/benchmark/query_without_mysql_casting.rb +47 -0
  14. data/benchmark/sequel.rb +37 -0
  15. data/benchmark/setup_db.rb +119 -0
  16. data/benchmark/threaded.rb +44 -0
  17. data/ext/mysql2/client.c +272 -849
  18. data/ext/mysql2/client.h +12 -27
  19. data/ext/mysql2/extconf.rb +14 -72
  20. data/ext/mysql2/mysql2_ext.h +4 -7
  21. data/ext/mysql2/result.c +123 -319
  22. data/ext/mysql2/result.h +1 -4
  23. data/lib/active_record/connection_adapters/em_mysql2_adapter.rb +64 -0
  24. data/lib/active_record/fiber_patches.rb +104 -0
  25. data/lib/mysql2.rb +5 -20
  26. data/lib/mysql2/client.rb +200 -50
  27. data/lib/mysql2/em.rb +3 -13
  28. data/lib/mysql2/em_fiber.rb +31 -0
  29. data/lib/mysql2/error.rb +6 -71
  30. data/lib/mysql2/version.rb +2 -2
  31. data/mysql2.gemspec +32 -0
  32. data/spec/em/em_fiber_spec.rb +22 -0
  33. data/spec/em/em_spec.rb +9 -74
  34. data/spec/mysql2/client_spec.rb +126 -593
  35. data/spec/mysql2/error_spec.rb +44 -58
  36. data/spec/mysql2/result_spec.rb +85 -257
  37. data/spec/spec_helper.rb +3 -24
  38. data/tasks/benchmarks.rake +20 -0
  39. data/tasks/compile.rake +71 -0
  40. data/tasks/rspec.rake +16 -0
  41. data/tasks/vendor_mysql.rake +40 -0
  42. metadata +179 -92
  43. checksums.yaml +0 -7
  44. data/README.md +0 -524
  45. data/ext/mysql2/infile.c +0 -122
  46. data/ext/mysql2/infile.h +0 -1
  47. data/ext/mysql2/mysql_enc_name_to_ruby.h +0 -168
  48. data/ext/mysql2/mysql_enc_to_ruby.h +0 -246
  49. data/ext/mysql2/wait_for_single_fd.h +0 -36
  50. data/lib/active_record/connection_adapters/mysql2_adapter.rb +0 -635
  51. data/lib/arel/engines/sql/compilers/mysql2_compiler.rb +0 -11
  52. data/lib/mysql2/console.rb +0 -5
  53. data/spec/configuration.yml.example +0 -17
  54. data/spec/my.cnf.example +0 -9
  55. data/spec/test_data +0 -1
  56. data/support/mysql_enc_to_ruby.rb +0 -82
  57. data/support/ruby_enc_to_mysql.rb +0 -61
data/spec/spec_helper.rb CHANGED
@@ -3,35 +3,15 @@
3
3
  require 'rspec'
4
4
  require 'mysql2'
5
5
  require 'timeout'
6
- require 'yaml'
7
- DatabaseCredentials = YAML.load_file('spec/configuration.yml')
8
6
 
9
7
  RSpec.configure do |config|
10
- def with_internal_encoding(encoding)
11
- old_enc = Encoding.default_internal
12
- Encoding.default_internal = encoding
13
-
14
- yield
15
- ensure
16
- Encoding.default_internal = old_enc
17
- end
18
-
19
- config.before :each do
20
- @client = Mysql2::Client.new DatabaseCredentials['root']
21
- end
22
-
23
- config.after :each do
24
- @client.close
25
- end
26
-
27
8
  config.before(:all) do
28
- client = Mysql2::Client.new DatabaseCredentials['root']
9
+ client = Mysql2::Client.new :host => "localhost", :username => "root", :database => 'test'
29
10
  client.query %[
30
11
  CREATE TABLE IF NOT EXISTS mysql2_test (
31
12
  id MEDIUMINT NOT NULL AUTO_INCREMENT,
32
13
  null_test VARCHAR(10),
33
14
  bit_test BIT(64),
34
- single_bit_test BIT(1),
35
15
  tiny_int_test TINYINT,
36
16
  bool_cast_test TINYINT(1),
37
17
  small_int_test SMALLINT,
@@ -65,10 +45,9 @@ RSpec.configure do |config|
65
45
  PRIMARY KEY (id)
66
46
  )
67
47
  ]
68
- client.query "DELETE FROM mysql2_test;"
69
48
  client.query %[
70
49
  INSERT INTO mysql2_test (
71
- null_test, bit_test, single_bit_test, tiny_int_test, bool_cast_test, small_int_test, medium_int_test, int_test, big_int_test,
50
+ null_test, bit_test, tiny_int_test, bool_cast_test, small_int_test, medium_int_test, int_test, big_int_test,
72
51
  float_test, float_zero_test, double_test, decimal_test, decimal_zero_test, date_test, date_time_test, timestamp_test, time_test,
73
52
  year_test, char_test, varchar_test, binary_test, varbinary_test, tiny_blob_test,
74
53
  tiny_text_test, blob_test, text_test, medium_blob_test, medium_text_test,
@@ -76,7 +55,7 @@ RSpec.configure do |config|
76
55
  )
77
56
 
78
57
  VALUES (
79
- NULL, b'101', b'1', 1, 1, 10, 10, 10, 10,
58
+ NULL, b'101', 1, 1, 10, 10, 10, 10,
80
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',
81
60
  2009, "test", "test", "test", "test", "test",
82
61
  "test", "test", "test", "test", "test",
@@ -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,71 @@
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 ADDED
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,40 @@
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
metadata CHANGED
@@ -1,148 +1,235 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mysql2
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.24
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Brian Lopez
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2011-04-27 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
14
22
  name: eventmachine
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
23
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
28
36
  name: rake-compiler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
31
41
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 0.8.1
42
+ - !ruby/object:Gem::Version
43
+ hash: 13
44
+ segments:
45
+ - 0
46
+ - 7
47
+ - 7
48
+ version: 0.7.7
34
49
  type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rspec
35
53
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: 0.8.1
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: 0.9.3
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
48
63
  type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: activerecord
49
67
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 0.9.3
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 2.8.0
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
62
77
  type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: mysql
63
81
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: 2.8.0
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: do_mysql
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :development
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: sequel
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ type: :development
120
+ version_requirements: *id007
121
+ - !ruby/object:Gem::Dependency
122
+ name: faker
123
+ prerelease: false
124
+ requirement: &id008 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ type: :development
134
+ version_requirements: *id008
69
135
  description:
70
136
  email: seniorlopez@gmail.com
71
137
  executables: []
72
- extensions:
138
+
139
+ extensions:
73
140
  - ext/mysql2/extconf.rb
74
- extra_rdoc_files: []
75
- files:
141
+ extra_rdoc_files:
142
+ - README.rdoc
143
+ files:
144
+ - .gitignore
145
+ - .rspec
146
+ - .rvmrc
147
+ - CHANGELOG.md
148
+ - Gemfile
76
149
  - MIT-LICENSE
77
- - README.md
150
+ - README.rdoc
151
+ - Rakefile
152
+ - benchmark/active_record.rb
153
+ - benchmark/active_record_threaded.rb
154
+ - benchmark/allocations.rb
155
+ - benchmark/escape.rb
156
+ - benchmark/query_with_mysql_casting.rb
157
+ - benchmark/query_without_mysql_casting.rb
158
+ - benchmark/sequel.rb
159
+ - benchmark/setup_db.rb
160
+ - benchmark/threaded.rb
161
+ - examples/eventmachine.rb
162
+ - examples/threaded.rb
78
163
  - ext/mysql2/client.c
79
164
  - ext/mysql2/client.h
80
165
  - ext/mysql2/extconf.rb
81
- - ext/mysql2/infile.c
82
- - ext/mysql2/infile.h
83
166
  - ext/mysql2/mysql2_ext.c
84
167
  - ext/mysql2/mysql2_ext.h
85
- - ext/mysql2/mysql_enc_name_to_ruby.h
86
- - ext/mysql2/mysql_enc_to_ruby.h
87
168
  - ext/mysql2/result.c
88
169
  - ext/mysql2/result.h
89
- - ext/mysql2/wait_for_single_fd.h
90
- - lib/active_record/connection_adapters/mysql2_adapter.rb
91
- - lib/arel/engines/sql/compilers/mysql2_compiler.rb
170
+ - lib/active_record/connection_adapters/em_mysql2_adapter.rb
171
+ - lib/active_record/fiber_patches.rb
92
172
  - lib/mysql2.rb
93
173
  - lib/mysql2/client.rb
94
- - lib/mysql2/console.rb
95
174
  - lib/mysql2/em.rb
175
+ - lib/mysql2/em_fiber.rb
96
176
  - lib/mysql2/error.rb
97
177
  - lib/mysql2/result.rb
98
178
  - lib/mysql2/version.rb
99
- - support/mysql_enc_to_ruby.rb
100
- - support/ruby_enc_to_mysql.rb
101
- - examples/eventmachine.rb
102
- - examples/threaded.rb
103
- - spec/configuration.yml.example
179
+ - mysql2.gemspec
180
+ - spec/em/em_fiber_spec.rb
104
181
  - spec/em/em_spec.rb
105
- - spec/my.cnf.example
106
182
  - spec/mysql2/client_spec.rb
107
183
  - spec/mysql2/error_spec.rb
108
184
  - spec/mysql2/result_spec.rb
109
185
  - spec/rcov.opts
110
186
  - spec/spec_helper.rb
111
- - spec/test_data
187
+ - tasks/benchmarks.rake
188
+ - tasks/compile.rake
189
+ - tasks/rspec.rake
190
+ - tasks/vendor_mysql.rake
191
+ has_rdoc: true
112
192
  homepage: http://github.com/brianmario/mysql2
113
- licenses:
114
- - MIT
115
- metadata: {}
193
+ licenses: []
194
+
116
195
  post_install_message:
117
- rdoc_options:
196
+ rdoc_options:
118
197
  - --charset=UTF-8
119
- require_paths:
198
+ require_paths:
120
199
  - lib
121
- required_ruby_version: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- required_rubygems_version: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - '>='
129
- - !ruby/object:Gem::Version
130
- version: '0'
200
+ - ext
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ none: false
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ hash: 3
207
+ segments:
208
+ - 0
209
+ version: "0"
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ none: false
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ hash: 3
216
+ segments:
217
+ - 0
218
+ version: "0"
131
219
  requirements: []
220
+
132
221
  rubyforge_project:
133
- rubygems_version: 2.0.14
222
+ rubygems_version: 1.6.2
134
223
  signing_key:
135
- specification_version: 4
224
+ specification_version: 3
136
225
  summary: A simple, fast Mysql library for Ruby, binding to libmysql
137
- test_files:
226
+ test_files:
138
227
  - examples/eventmachine.rb
139
228
  - examples/threaded.rb
140
- - spec/configuration.yml.example
229
+ - spec/em/em_fiber_spec.rb
141
230
  - spec/em/em_spec.rb
142
- - spec/my.cnf.example
143
231
  - spec/mysql2/client_spec.rb
144
232
  - spec/mysql2/error_spec.rb
145
233
  - spec/mysql2/result_spec.rb
146
234
  - spec/rcov.opts
147
235
  - spec/spec_helper.rb
148
- - spec/test_data