mysql2 0.3.10 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
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
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2010-2011 Brian Lopez - http://github.com/brianmario
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,5 +0,0 @@
1
- # encoding: UTF-8
2
- require 'rake'
3
-
4
- # Load custom tasks
5
- Dir['tasks/*.rake'].sort.each { |f| load f }
@@ -1,51 +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
- ActiveRecord::Base.default_timezone = :local
9
- ActiveRecord::Base.time_zone_aware_attributes = true
10
-
11
- number_of = 10
12
- mysql2_opts = {
13
- :adapter => 'mysql2',
14
- :database => 'test'
15
- }
16
- mysql_opts = {
17
- :adapter => 'mysql',
18
- :database => 'test'
19
- }
20
-
21
- class Mysql2Model < ActiveRecord::Base
22
- set_table_name :mysql2_test
23
- end
24
-
25
- class MysqlModel < ActiveRecord::Base
26
- set_table_name :mysql2_test
27
- end
28
-
29
- Benchmark.bmbm do |x|
30
- x.report "Mysql2" do
31
- Mysql2Model.establish_connection(mysql2_opts)
32
- number_of.times do
33
- Mysql2Model.all(:limit => 1000).each{ |r|
34
- r.attributes.keys.each{ |k|
35
- r.send(k.to_sym)
36
- }
37
- }
38
- end
39
- end
40
-
41
- x.report "Mysql" do
42
- MysqlModel.establish_connection(mysql_opts)
43
- number_of.times do
44
- MysqlModel.all(:limit => 1000).each{ |r|
45
- r.attributes.keys.each{ |k|
46
- r.send(k.to_sym)
47
- }
48
- }
49
- end
50
- end
51
- end
@@ -1,42 +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
- times = 25
9
-
10
-
11
- # mysql2
12
- mysql2_opts = {
13
- :adapter => 'mysql2',
14
- :database => 'test',
15
- :pool => times
16
- }
17
- ActiveRecord::Base.establish_connection(mysql2_opts)
18
- x = Benchmark.realtime do
19
- threads = []
20
- times.times do
21
- threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
22
- end
23
- threads.each {|t| t.join }
24
- end
25
- puts "mysql2: #{x} seconds"
26
-
27
-
28
- # mysql
29
- mysql2_opts = {
30
- :adapter => 'mysql',
31
- :database => 'test',
32
- :pool => times
33
- }
34
- ActiveRecord::Base.establish_connection(mysql2_opts)
35
- x = Benchmark.realtime do
36
- threads = []
37
- times.times do
38
- threads << Thread.new { ActiveRecord::Base.connection.execute("select sleep(1)") }
39
- end
40
- threads.each {|t| t.join }
41
- end
42
- puts "mysql: #{x} seconds"
@@ -1,33 +0,0 @@
1
- # encoding: UTF-8
2
- $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
-
4
- raise Mysql2::Mysql2Error.new("GC allocation benchmarks only supported on Ruby 1.9!") unless RUBY_VERSION =~ /1\.9/
5
-
6
- require 'rubygems'
7
- require 'benchmark'
8
- require 'active_record'
9
-
10
- ActiveRecord::Base.default_timezone = :local
11
- ActiveRecord::Base.time_zone_aware_attributes = true
12
-
13
- class Mysql2Model < ActiveRecord::Base
14
- set_table_name :mysql2_test
15
- end
16
-
17
- def bench_allocations(feature, iterations = 10, &blk)
18
- puts "GC overhead for #{feature}"
19
- Mysql2Model.establish_connection(:adapter => 'mysql2', :database => 'test')
20
- GC::Profiler.clear
21
- GC::Profiler.enable
22
- iterations.times{ blk.call }
23
- GC::Profiler.report(STDOUT)
24
- GC::Profiler.disable
25
- end
26
-
27
- bench_allocations('coercion') do
28
- Mysql2Model.all(:limit => 1000).each{ |r|
29
- r.attributes.keys.each{ |k|
30
- r.send(k.to_sym)
31
- }
32
- }
33
- end
data/benchmark/escape.rb DELETED
@@ -1,36 +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
- def run_escape_benchmarks(str, number_of = 1000)
11
- Benchmark.bmbm do |x|
12
- mysql = Mysql.new("localhost", "root")
13
- x.report "Mysql #{str.inspect}" do
14
- number_of.times do
15
- mysql.quote str
16
- end
17
- end
18
-
19
- mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
20
- x.report "Mysql2 #{str.inspect}" do
21
- number_of.times do
22
- mysql2.escape str
23
- end
24
- end
25
-
26
- do_mysql = DataObjects::Connection.new("mysql://localhost/test")
27
- x.report "do_mysql #{str.inspect}" do
28
- number_of.times do
29
- do_mysql.quote_string str
30
- end
31
- end
32
- end
33
- end
34
-
35
- run_escape_benchmarks "abc'def\"ghi\0jkl%mno"
36
- run_escape_benchmarks "clean string"
@@ -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
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $LOAD_PATH.unshift 'lib'
4
-
5
- require 'rubygems'
6
- require 'eventmachine'
7
- require 'mysql2/em'
8
-
9
- EM.run do
10
- client1 = Mysql2::EM::Client.new
11
- defer1 = client1.query "SELECT sleep(3) as first_query"
12
- defer1.callback do |result|
13
- puts "Result: #{result.to_a.inspect}"
14
- end
15
-
16
- client2 = Mysql2::EM::Client.new
17
- defer2 = client2.query "SELECT sleep(1) second_query"
18
- defer2.callback do |result|
19
- puts "Result: #{result.to_a.inspect}"
20
- end
21
- end
data/examples/threaded.rb DELETED
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $LOAD_PATH.unshift 'lib'
4
- require 'mysql2'
5
- require 'timeout'
6
-
7
- threads = []
8
- # Should never exceed worst case 3.5 secs across all 20 threads
9
- Timeout.timeout(3.5) do
10
- 20.times do
11
- threads << Thread.new do
12
- overhead = rand(3)
13
- puts ">> thread #{Thread.current.object_id} query, #{overhead} sec overhead"
14
- # 3 second overhead per query
15
- Mysql2::Client.new(:host => "localhost", :username => "root").query("SELECT sleep(#{overhead}) as result")
16
- puts "<< thread #{Thread.current.object_id} result, #{overhead} sec overhead"
17
- end
18
- end
19
- threads.each{|t| t.join }
20
- end
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
data/spec/em/em_spec.rb DELETED
@@ -1,50 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
- begin
4
- require 'eventmachine'
5
- require 'mysql2/em'
6
-
7
- describe Mysql2::EM::Client do
8
- it "should support async queries" do
9
- results = []
10
- EM.run do
11
- client1 = Mysql2::EM::Client.new
12
- defer1 = client1.query "SELECT sleep(0.1) as first_query"
13
- defer1.callback do |result|
14
- results << result.first
15
- EM.stop_event_loop
16
- end
17
-
18
- client2 = Mysql2::EM::Client.new
19
- defer2 = client2.query "SELECT sleep(0.025) second_query"
20
- defer2.callback do |result|
21
- results << result.first
22
- end
23
- end
24
-
25
- results[0].keys.should include("second_query")
26
- results[1].keys.should include("first_query")
27
- end
28
-
29
- it "should support queries in callbacks" do
30
- results = []
31
- EM.run do
32
- client = Mysql2::EM::Client.new
33
- defer1 = client.query "SELECT sleep(0.025) as first_query"
34
- defer1.callback do |result|
35
- results << result.first
36
- defer2 = client.query "SELECT sleep(0.025) as second_query"
37
- defer2.callback do |result|
38
- results << result.first
39
- EM.stop_event_loop
40
- end
41
- end
42
- end
43
-
44
- results[0].keys.should include("first_query")
45
- results[1].keys.should include("second_query")
46
- end
47
- end
48
- rescue LoadError
49
- puts "EventMachine not installed, skipping the specs that use it"
50
- end