ruby-mysql 2.9.8 → 2.9.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-mysql might be problematic. Click here for more details.

data/lib/mysql.rb CHANGED
@@ -14,13 +14,13 @@ class Mysql
14
14
  require "mysql/error"
15
15
  require "mysql/charset"
16
16
  require "mysql/protocol"
17
+ require "mysql/packet.rb"
17
18
  begin
18
- require "mysql/packet.so"
19
+ require "mysql/ext.so"
19
20
  rescue LoadError
20
- require "mysql/packet.rb"
21
21
  end
22
22
 
23
- VERSION = 20908 # Version number of this library
23
+ VERSION = 20909 # Version number of this library
24
24
  MYSQL_UNIX_PORT = "/tmp/mysql.sock" # UNIX domain socket filename
25
25
  MYSQL_TCP_PORT = 3306 # TCP socket port number
26
26
 
@@ -1054,6 +1054,7 @@ class Mysql
1054
1054
  # @param [Boolean] neg negative flag
1055
1055
  # @param [Integer] second_part
1056
1056
  def initialize(year=0, month=0, day=0, hour=0, minute=0, second=0, neg=false, second_part=0)
1057
+ @date_flag = !(hour && minute && second)
1057
1058
  @year, @month, @day, @hour, @minute, @second, @neg, @second_part =
1058
1059
  year.to_i, month.to_i, day.to_i, hour.to_i, minute.to_i, second.to_i, neg, second_part.to_i
1059
1060
  end
@@ -1077,7 +1078,9 @@ class Mysql
1077
1078
 
1078
1079
  # @return [String] "yyyy-mm-dd HH:MM:SS"
1079
1080
  def to_s
1080
- if year == 0 and mon == 0 and day == 0
1081
+ if @date_flag
1082
+ sprintf "%04d-%02d-%02d", year, mon, day
1083
+ elsif year == 0 and mon == 0 and day == 0
1081
1084
  h = neg ? hour * -1 : hour
1082
1085
  sprintf "%02d:%02d:%02d", h, min, sec
1083
1086
  else
@@ -44,15 +44,12 @@ class Mysql
44
44
  when Field::TYPE_DATE
45
45
  len = pkt.utiny
46
46
  y, m, d = pkt.read(len).unpack("vCC")
47
- t = Mysql::Time.new(y, m, d)
48
- def t.to_s
49
- sprintf "%04d-%02d-%02d", year, mon ,day
50
- end
47
+ t = Mysql::Time.new(y, m, d, nil, nil, nil)
51
48
  return t
52
49
  when Field::TYPE_DATETIME, Field::TYPE_TIMESTAMP
53
50
  len = pkt.utiny
54
- y, m, d, h, mi, s, bs = pkt.read(len).unpack("vCCCCCV")
55
- return Mysql::Time.new(y, m, d, h, mi, s, bs)
51
+ y, m, d, h, mi, s, sp = pkt.read(len).unpack("vCCCCCV")
52
+ return Mysql::Time.new(y, m, d, h, mi, s, false, sp)
56
53
  when Field::TYPE_TIME
57
54
  len = pkt.utiny
58
55
  sign, d, h, mi, s, sp = pkt.read(len).unpack("CVCCCV")
@@ -423,10 +420,11 @@ class Mysql
423
420
  # [Array of Array of Object] all records
424
421
  def stmt_retr_all_records(fields, charset)
425
422
  check_state :RESULT
423
+ enc = charset.encoding
426
424
  begin
427
425
  all_recs = []
428
- until (data = read).eof?
429
- all_recs.push StmtRawRecord.new(data, fields, charset.encoding)
426
+ until (pkt = read).eof?
427
+ all_recs.push StmtRawRecord.new(pkt, fields, enc)
430
428
  end
431
429
  all_recs
432
430
  ensure
@@ -494,13 +492,13 @@ class Mysql
494
492
  begin
495
493
  Timeout.timeout @read_timeout do
496
494
  header = @sock.read(4)
497
- raise EOFError unless header.length == 4
495
+ raise EOFError unless header && header.length == 4
498
496
  len1, len2, seq = header.unpack("CvC")
499
497
  len = (len2 << 8) + len1
500
498
  raise ProtocolError, "invalid packet: sequence number mismatch(#{seq} != #{@seq}(expected))" if @seq != seq
501
499
  @seq = (@seq + 1) % 256
502
500
  ret = @sock.read(len)
503
- raise EOFError unless ret.length == len
501
+ raise EOFError unless ret && ret.length == len
504
502
  end
505
503
  rescue EOFError
506
504
  raise ClientError::ServerGoneError, 'The MySQL server has gone away'
data/spec/mysql_spec.rb CHANGED
@@ -13,7 +13,7 @@ MYSQL_SOCKET = ENV['MYSQL_SOCKET']
13
13
 
14
14
  describe 'Mysql::VERSION' do
15
15
  it 'returns client version' do
16
- Mysql::VERSION.should == 20908
16
+ Mysql::VERSION.should == 20909
17
17
  end
18
18
  end
19
19
 
@@ -649,6 +649,7 @@ end
649
649
  describe 'Mysql::Result' do
650
650
  before do
651
651
  @m = Mysql.new(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
652
+ @m.charset = 'latin1'
652
653
  @m.query 'create temporary table t (id int, str char(10), primary key (id))'
653
654
  @m.query "insert into t values (1,'abc'),(2,'defg'),(3,'hi'),(4,null)"
654
655
  @res = @m.query 'select * from t'
@@ -808,6 +809,7 @@ end
808
809
  describe 'Mysql::Field' do
809
810
  before do
810
811
  @m = Mysql.new(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)
812
+ @m.charset = 'latin1'
811
813
  @m.query 'create temporary table t (id int default 0, str char(10), primary key (id))'
812
814
  @m.query "insert into t values (1,'abc'),(2,'defg'),(3,'hi'),(4,null)"
813
815
  @res = @m.query 'select * from t'
@@ -1065,6 +1067,99 @@ describe 'Mysql::Stmt' do
1065
1067
  end
1066
1068
  end
1067
1069
 
1070
+ describe '#execute with various integer value:' do
1071
+ before do
1072
+ @m.query('create temporary table t (i bigint)')
1073
+ end
1074
+ [
1075
+ -9223372036854775808,
1076
+ -9223372036854775807,
1077
+ -4294967297,
1078
+ -4294967296,
1079
+ -4294967295,
1080
+ -2147483649,
1081
+ -2147483648,
1082
+ -2147483647,
1083
+ -65537,
1084
+ -65536,
1085
+ -65535,
1086
+ -32769,
1087
+ -32768,
1088
+ -32767,
1089
+ -257,
1090
+ -256,
1091
+ -255,
1092
+ -129,
1093
+ -128,
1094
+ -127,
1095
+ 0,
1096
+ 126,
1097
+ 127,
1098
+ 128,
1099
+ 254,
1100
+ 255,
1101
+ 256,
1102
+ 32766,
1103
+ 32767,
1104
+ 32768,
1105
+ 65534,
1106
+ 65535,
1107
+ 65536,
1108
+ 2147483646,
1109
+ 2147483647,
1110
+ 2147483648,
1111
+ 4294967294,
1112
+ 4294967295,
1113
+ 4294967296,
1114
+ 9223372036854775806,
1115
+ 9223372036854775807,
1116
+ ].each do |n|
1117
+ it "#{n} is #{n}" do
1118
+ @s.prepare 'insert into t values (?)'
1119
+ @s.execute n
1120
+ @m.query('select i from t').fetch.should == ["#{n}"]
1121
+ end
1122
+ end
1123
+ end
1124
+
1125
+ describe '#execute with various unsigned integer value:' do
1126
+ before do
1127
+ @m.query('create temporary table t (i bigint unsigned)')
1128
+ end
1129
+ [
1130
+ 0,
1131
+ 126,
1132
+ 127,
1133
+ 128,
1134
+ 254,
1135
+ 255,
1136
+ 256,
1137
+ 32766,
1138
+ 32767,
1139
+ 32768,
1140
+ 65534,
1141
+ 65535,
1142
+ 65536,
1143
+ 2147483646,
1144
+ 2147483647,
1145
+ 2147483648,
1146
+ 4294967294,
1147
+ 4294967295,
1148
+ 4294967296,
1149
+ 9223372036854775806,
1150
+ 9223372036854775807,
1151
+ 9223372036854775808,
1152
+ 18446744073709551614,
1153
+ 18446744073709551615,
1154
+ ].each do |n|
1155
+ it "#{n} is #{n}" do
1156
+ @s.prepare 'insert into t values (?)'
1157
+ @s.execute n
1158
+ @m.query('select i from t').fetch.should == ["#{n}"]
1159
+ end
1160
+ end
1161
+ end
1162
+
1068
1163
  it '#fetch returns result-record' do
1069
1164
  @s.prepare 'select 123, "abc", null'
1070
1165
  @s.execute
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.8
4
+ version: 2.9.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-08 00:00:00.000000000 Z
12
+ date: 2012-06-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: This is MySQL connector. pure Ruby version
15
15
  email: tommy@tmtm.org