Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 6 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Showing with 40 additions and 118 deletions.
  1. +0 −75 ChangeLog
  2. +18 −13 lib/mysql.rb
  3. +9 −2 lib/mysql/protocol.rb
  4. +12 −27 ruby-mysql.gemspec
  5. +1 −1 spec/mysql_spec.rb
View
75 ChangeLog
@@ -1,75 +0,0 @@
-2011-08-04 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql/protocol.rb (Mysql::Protocol#authenticate): Raise
- ProtocolError when user with old password attempts to login.
-
-2011-02-11 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql/protocol.rb (Mysql::Protocol#stmt_parse_record_packet):
- Fix encoding of retrieved data when the field has binary
- collation. Thanks MATSUYAMA Kengo.
-
-2011-02-05 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql/error.rb: avoid warning when ruby -w.
-
- * lib/mysql.rb (Mysql#connect): warn if CLIENT_COMPRESS flag is specified.
-
-2011-01-02 TOMITA Masahiro <tommy@tmtm.org>
-
- * .autotest, .rspec: for autotest.
-
-2010-12-31 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql.rb: add Mysql#close! method.
-
-2010-12-30 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql/protocol.rb: raise ClientError::ServerGoneError when
- connection is disconnected.
-
-2010-12-29 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql/error.rb: add Mysql::ServerError::<Error> and
- Mysql::ClientError::<Error> class.
-
- * spec/mysql_spec.rb: for RSpec 2
-
- * lib/mysql/charset.rb: add utf8mb4 charset.
-
-2010-12-19 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql/protocol.rb: Fix: error 'Mysql::ProtocolError Invalid
- packet: f1...' occurred on MySQL 5.5
-
-2010-06-06 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql/charset.rb: support tis620 charset.
-
- * lib/mysql/charset.rb, lib/mysql/protocol.rb: convert encoding to
- Encoding.default_internal.
-
-2010-05-06 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql.rb (Mysql#connect): Fix: Mysql.connect ignore flag.
-
- * spec/mysql_spec.rb: use environment variables for MySQL
- connection.
-
-2010-01-17 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql.rb (Mysql#errno): Fix: Mysql#errno's default value
- should be 0.
-
-2010-01-16 TOMITA Masahiro <tommy@tmtm.org>
-
- * lib/mysql.rb (Mysql#escape_string): raise error for unsafe
- multibyte charset
-
-2010-01-15 TOMITA Masahiro <tommy@tmtm.org>
-
- * Fix: When GC destroy Mysql::Stmt object, protocol error occurred
-
-2010-01-10 TOMITA Masahiro <tommy@tmtm.org>
-
- * Version 2.9.0-beta
View
31 lib/mysql.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2008-2011 TOMITA Masahiro
+# Copyright (C) 2008-2012 TOMITA Masahiro
# mailto:tommy@tmtm.org
# MySQL connection class.
@@ -21,8 +21,6 @@ class Mysql
MYSQL_TCP_PORT = 3306 # TCP socket port number
attr_reader :charset # character set of MySQL connection
- attr_reader :affected_rows # number of affected records by insert/update/delete.
- attr_reader :warning_count # number of warnings for previous query
attr_reader :protocol # :nodoc:
attr_accessor :query_with_result
@@ -84,12 +82,9 @@ def initialize # :nodoc:
@read_timeout = nil
@write_timeout = nil
@init_command = nil
- @affected_rows = nil
- @warning_count = 0
@sqlstate = "00000"
@query_with_result = true
@host_info = nil
- @info = nil
@last_error = nil
@result_exist = false
@local_infile = nil
@@ -287,13 +282,25 @@ def server_version
# === Return
# [String] information for last query
def info
- @info
+ @protocol && @protocol.message
+ end
+
+ # === Return
+ # [Integer] number of affected records by insert/update/delete.
+ def affected_rows
+ @protocol ? @protocol.affected_rows : 0
end
# === Return
# [Integer] latest auto_increment value
def insert_id
- @insert_id
+ @protocol ? @protocol.insert_id : 0
+ end
+
+ # === Return
+ # [Integer] number of warnings for previous query
+ def warning_count
+ @protocol ? @protocol.warning_count : 0
end
# Kill query.
@@ -337,9 +344,6 @@ def query(str, &block)
if nfields
@fields = @protocol.retr_fields nfields
@result_exist = true
- else
- @affected_rows, @insert_id, @server_status, @warning_count, @info =
- @protocol.affected_rows, @protocol.insert_id, @protocol.server_status, @protocol.warning_count, @protocol.message
end
if block
while true
@@ -368,7 +372,6 @@ def store_result
check_connection
raise ClientError, 'invalid usage' unless @result_exist
res = Result.new @fields, @protocol
- @server_status = @protocol.server_status
@result_exist = false
res
end
@@ -399,7 +402,7 @@ def set_server_option(opt)
# true if multiple queries are specified and unexecuted queries exists.
def more_results
- @server_status & SERVER_MORE_RESULTS_EXISTS != 0
+ @protocol.server_status & SERVER_MORE_RESULTS_EXISTS != 0
end
alias more_results? more_results
@@ -638,6 +641,7 @@ def initialize(fields)
@records = [] # all records
@index = 0 # index of record
@fieldname_with_table = nil
+ @fetched_record = nil
end
# ignore
@@ -843,6 +847,7 @@ def initialize(protocol, charset)
@affected_rows = @insert_id = @server_status = @warning_count = 0
@sqlstate = "00000"
@param_count = nil
+ @bind_result = nil
end
# parse prepared-statement and return Mysql::Statement object
View
11 lib/mysql/protocol.rb
@@ -1,4 +1,4 @@
-# Copyright (C) 2008-2010 TOMITA Masahiro
+# Copyright (C) 2008-2012 TOMITA Masahiro
# mailto:tommy@tmtm.org
require "socket"
@@ -201,6 +201,8 @@ def self.value2net(v)
# === Exception
# [ClientError] :: connection timeout
def initialize(host, port, socket, conn_timeout, read_timeout, write_timeout)
+ @insert_id = 0
+ @warning_count = 0
@gc_stmt_queue = [] # stmt id list which GC destroy.
set_state :INIT
@read_timeout = read_timeout
@@ -570,7 +572,12 @@ def read
len = (len2 << 8) + len1
raise ProtocolError, "invalid packet: sequence number mismatch(#{seq} != #{@seq}(expected))" if @seq != seq
@seq = (@seq + 1) % 256
- ret.concat @sock.sysread(len)
+ buf = ''.force_encoding('ASCII-8BIT')
+ l = len
+ while l > 0
+ ret.concat @sock.sysread(l, buf)
+ l -= buf.bytesize
+ end
end
rescue EOFError
raise ClientError::ServerGoneError, 'The MySQL server has gone away'
View
39 ruby-mysql.gemspec
@@ -1,30 +1,15 @@
Gem::Specification.new do |s|
- s.name = %q{ruby-mysql}
- s.version = "2.9.4"
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["tommy"]
- s.date = %q{2010-12-29}
- s.description = %q{MySQL connector for Ruby}
- s.email = %q{tommy@tmtm.org}
- s.extra_rdoc_files = ["README.rdoc", "ChangeLog"]
- s.files = ["README.rdoc", "ChangeLog", "lib/mysql.rb", "lib/mysql/constants.rb", "lib/mysql/protocol.rb", "lib/mysql/charset.rb", "lib/mysql/error.rb"]
+ s.name = 'ruby-mysql'
+ s.version = '2.9.5'
+ s.summary = 'pure Ruby MySQL connector'
+ s.authors = ['Tomita Masahiro']
+ s.date = '2012-04-16'
+ s.description = 'This is pure Ruby MySQL connector.'
+ s.email = 'tommy@tmtm.org'
+ s.homepage = 'http://github.com/tmtm/ruby-mysql'
+ s.files = ['README.rdoc', 'lib/mysql.rb', 'lib/mysql/constants.rb', 'lib/mysql/protocol.rb', 'lib/mysql/charset.rb', 'lib/mysql/error.rb']
+ s.extra_rdoc_files = ['README.rdoc']
+ s.test_files = ['spec/mysql_spec.rb']
s.has_rdoc = true
- s.homepage = %q{http://github.com/tmtm/ruby-mysql}
- s.rdoc_options = ["--title", "ruby-mysql documentation", "--charset", "utf-8", "--opname", "index.html", "--line-numbers", "--main", "README", "--inline-source", "--exclude", "^(examples|extras)/"]
- s.require_paths = ["lib"]
- s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
- s.rubyforge_project = %q{rubymysql}
- s.rubygems_version = %q{1.2.0}
- s.summary = %q{MySQL connector for Ruby}
-
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 2
-
- if current_version >= 3 then
- else
- end
- else
- end
+ s.license = 'Ruby\'s'
end
View
2 spec/mysql_spec.rb
@@ -704,7 +704,7 @@
f.name.should == 'id'
f = @res.fetch_field_direct 1
f.name.should == 'str'
- proc{@res.fetch_field_direct -1}.should raise_error Mysql::ClientError, 'invalid argument: -1'
+ proc{@res.fetch_field_direct(-1)}.should raise_error Mysql::ClientError, 'invalid argument: -1'
proc{@res.fetch_field_direct 2}.should raise_error Mysql::ClientError, 'invalid argument: 2'
end

No commit comments for this range

Something went wrong with that request. Please try again.