Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
inherit_from: .rubocop_todo.yml

AllCops:
DisplayCopNames: true
Exclude:
- 'tmp/**/*'

Lint/EndAlignment:
AlignWith: variable

Style/CaseIndentation:
IndentWhenRelativeTo: end

Style/IndentHash:
EnforcedStyle: consistent

Style/TrailingComma:
EnforcedStyleForMultiline: consistent_comma

Style/TrivialAccessors:
AllowPredicates: true

# TODO: remove when we end support for < 1.9.3

Style/HashSyntax:
EnforcedStyle: hash_rockets

Style/Lambda:
Enabled: false
71 changes: 71 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-09-06 13:16:09 -0400 using RuboCop version 0.34.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
Metrics/AbcSize:
Max: 68

# Offense count: 1
Metrics/BlockNesting:
Max: 5

# Offense count: 2
Metrics/CyclomaticComplexity:
Max: 23

# Offense count: 290
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 232

# Offense count: 5
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 43

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 22

# Offense count: 40
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
Style/BlockDelimiters:
Enabled: false

# Offense count: 12
Style/Documentation:
Exclude:
- 'benchmark/active_record.rb'
- 'benchmark/allocations.rb'
- 'benchmark/query_with_mysql_casting.rb'
- 'lib/mysql2.rb'
- 'lib/mysql2/client.rb'
- 'lib/mysql2/em.rb'
- 'lib/mysql2/error.rb'
- 'lib/mysql2/field.rb'
- 'lib/mysql2/result.rb'
- 'lib/mysql2/statement.rb'
- 'lib/mysql2/version.rb'

# Offense count: 9
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
Exclude:
- 'ext/mysql2/extconf.rb'

# Offense count: 14
# Cop supports --auto-correct.
Style/NumericLiterals:
MinDigits: 20

# Offense count: 680
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/StringLiterals:
Enabled: false
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem 'rake-compiler', '~> 0.9.5'
group :test do
gem 'eventmachine' unless RUBY_PLATFORM =~ /mswin|mingw/
gem 'rspec', '~> 3.2'
gem 'rubocop', '~> 0.34.0' unless RUBY_VERSION =~ /1.8/
end

group :benchmarks do
Expand Down
10 changes: 9 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ load 'tasks/compile.rake'
load 'tasks/generate.rake'
load 'tasks/benchmarks.rake'

task :default => :spec
# TODO: remove when we end support for < 1.9.3
if RUBY_VERSION =~ /1.8/
task :default => :spec
else
require 'rubocop/rake_task'
RuboCop::RakeTask.new

task :default => [:spec, :rubocop]
end
2 changes: 0 additions & 2 deletions benchmark/allocations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'rubygems'
require 'active_record'

raise Mysql2::Error.new("GC allocation benchmarks only supported on Ruby 1.9!") unless RUBY_VERSION > '1.9'

ActiveRecord::Base.default_timezone = :local
ActiveRecord::Base.time_zone_aware_attributes = true

Expand Down
18 changes: 8 additions & 10 deletions benchmark/query_with_mysql_casting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ def mysql_cast(type, value)
when Mysql::Field::TYPE_TIME, Mysql::Field::TYPE_DATETIME, Mysql::Field::TYPE_TIMESTAMP
Time.parse(value)
when Mysql::Field::TYPE_BLOB, Mysql::Field::TYPE_BIT, Mysql::Field::TYPE_STRING,
Mysql::Field::TYPE_VAR_STRING, Mysql::Field::TYPE_CHAR, Mysql::Field::TYPE_SET
Mysql::Field::TYPE_ENUM
Mysql::Field::TYPE_VAR_STRING, Mysql::Field::TYPE_CHAR, Mysql::Field::TYPE_SET,
Mysql::Field::TYPE_ENUM
value
else
value
end
end

debug = ENV['DEBUG']

Benchmark.ips do |x|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2.query "USE #{database}"
x.report "Mysql2" do
mysql2_result = mysql2.query sql, :symbolize_keys => true
mysql2_result.each do |res|
# puts res.inspect
end
mysql2_result.each { |res| puts res.inspect if debug }
end

mysql = Mysql.new("localhost", "root")
Expand All @@ -55,19 +55,17 @@ def mysql_cast(type, value)
fields = mysql_result.fetch_fields
mysql_result.each do |row|
row_hash = row.each_with_index.each_with_object({}) do |(f, j), hash|
hash[fields[j].name.to_sym] = mysql_cast(fields[j].type, row[j])
hash[fields[j].name.to_sym] = mysql_cast(fields[j].type, f)
end
# puts row_hash.inspect
puts row_hash.inspect if debug
end
end

do_mysql = DataObjects::Connection.new("mysql://localhost/#{database}")
command = do_mysql.create_command sql
x.report "do_mysql" do
do_result = command.execute_reader
do_result.each do |res|
# puts res.inspect
end
do_result.each { |res| puts res.inspect if debug }
end

x.compare!
Expand Down
18 changes: 6 additions & 12 deletions benchmark/query_without_mysql_casting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,33 @@
database = 'test'
sql = "SELECT * FROM mysql2_test LIMIT 100"

debug = ENV['DEBUG']

Benchmark.ips do |x|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2.query "USE #{database}"
x.report "Mysql2 (cast: true)" do
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => true
mysql2_result.each do |res|
# puts res.inspect
end
mysql2_result.each { |res| puts res.inspect if debug }
end

x.report "Mysql2 (cast: false)" do
mysql2_result = mysql2.query sql, :symbolize_keys => true, :cast => false
mysql2_result.each do |res|
# puts res.inspect
end
mysql2_result.each { |res| puts res.inspect if debug }
end

mysql = Mysql.new("localhost", "root")
mysql.query "USE #{database}"
x.report "Mysql" do
mysql_result = mysql.query sql
mysql_result.each_hash do |res|
# puts res.inspect
end
mysql_result.each_hash { |res| puts res.inspect if debug }
end

do_mysql = DataObjects::Connection.new("mysql://localhost/#{database}")
command = DataObjects::Mysql::Command.new do_mysql, sql
x.report "do_mysql" do
do_result = command.execute_reader
do_result.each do |res|
# puts res.inspect
end
do_result.each { |res| puts res.inspect if debug }
end

x.compare!
Expand Down
10 changes: 5 additions & 5 deletions benchmark/setup_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def insert_record(args)
:medium_int_test => rand(8388607),
:int_test => rand(2147483647),
:big_int_test => rand(9223372036854775807),
:float_test => rand(32767)/1.87,
:float_test => rand(32767) / 1.87,
:float_zero_test => 0.0,
:double_test => rand(8388607)/1.87,
:decimal_test => rand(8388607)/1.87,
:double_test => rand(8388607) / 1.87,
:decimal_test => rand(8388607) / 1.87,
:decimal_zero_test => 0,
:date_test => '2010-4-4',
:date_time_test => '2010-4-4 11:44:00',
Expand All @@ -108,8 +108,8 @@ def insert_record(args)
:medium_text_test => twenty5_paragraphs,
:long_blob_test => twenty5_paragraphs,
:long_text_test => twenty5_paragraphs,
:enum_test => ['val1', 'val2'][rand(2)],
:set_test => ['val1', 'val2', 'val1,val2'][rand(3)]
:enum_test => %w(val1 val2).sample,
:set_test => %w(val1 val2 val1,val2).sample,
)
if n % 100 == 0
$stdout.putc '.'
Expand Down
2 changes: 1 addition & 1 deletion examples/eventmachine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
defer2.callback do |result|
puts "Result: #{result.to_a.inspect}"
end
end
end
2 changes: 1 addition & 1 deletion ext/mysql2/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ static VALUE rb_mysql_client_abandon_results(VALUE self) {
* client.query(sql, options = {})
*
* Query the database with +sql+, with optional +options+. For the possible
* options, see @@default_query_options on the Mysql2::Client class.
* options, see default_query_options on the Mysql2::Client class.
*/
static VALUE rb_query(VALUE self, VALUE sql, VALUE current) {
#ifndef _WIN32
Expand Down
Loading