ruby-mysql 2.9.11 → 2.9.12

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.

@@ -21,7 +21,7 @@ class Mysql
21
21
  rescue LoadError
22
22
  end
23
23
 
24
- VERSION = 20911 # Version number of this library
24
+ VERSION = 20912 # Version number of this library
25
25
  MYSQL_UNIX_PORT = "/tmp/mysql.sock" # UNIX domain socket filename
26
26
  MYSQL_TCP_PORT = 3306 # TCP socket port number
27
27
 
@@ -109,7 +109,7 @@ class Mysql
109
109
  # @return self
110
110
  def connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, socket=nil, flag=0)
111
111
  if flag & CLIENT_COMPRESS != 0
112
- warn 'unsupported flag: CLIENT_COMPRESS'
112
+ warn 'unsupported flag: CLIENT_COMPRESS' if $VERBOSE
113
113
  flag &= ~CLIENT_COMPRESS
114
114
  end
115
115
  @protocol = Protocol.new host, port, socket, @connect_timeout, @read_timeout, @write_timeout
@@ -179,7 +179,7 @@ class Mysql
179
179
  @charset = Charset.by_name value.to_s
180
180
  # when Mysql::SHARED_MEMORY_BASE_NAME
181
181
  else
182
- warn "option not implemented: #{opt}"
182
+ warn "option not implemented: #{opt}" if $VERBOSE
183
183
  end
184
184
  self
185
185
  end
@@ -33,11 +33,11 @@ class Mysql
33
33
  return unsigned ? v : v < 32768 ? v : v-65536
34
34
  when Field::TYPE_INT24, Field::TYPE_LONG
35
35
  v = pkt.ulong
36
- return unsigned ? v : v < 2**32/2 ? v : v-2**32
36
+ return unsigned ? v : v < 0x8000_0000 ? v : v-0x10000_0000
37
37
  when Field::TYPE_LONGLONG
38
38
  n1, n2 = pkt.ulong, pkt.ulong
39
39
  v = (n2 << 32) | n1
40
- return unsigned ? v : v < 2**64/2 ? v : v-2**64
40
+ return unsigned ? v : v < 0x8000_0000_0000_0000 ? v : v-0x10000_0000_0000_0000
41
41
  when Field::TYPE_FLOAT
42
42
  return pkt.read(4).unpack('e').first
43
43
  when Field::TYPE_DOUBLE
@@ -79,38 +79,17 @@ class Mysql
79
79
  type = Field::TYPE_NULL
80
80
  val = ""
81
81
  when Integer
82
- if v >= 0
83
- if v < 256
84
- type = Field::TYPE_TINY | 0x8000
85
- val = [v].pack("C")
86
- elsif v < 256**2
87
- type = Field::TYPE_SHORT | 0x8000
88
- val = [v].pack("v")
89
- elsif v < 256**4
90
- type = Field::TYPE_LONG | 0x8000
91
- val = [v].pack("V")
92
- elsif v < 256**8
93
- type = Field::TYPE_LONGLONG | 0x8000
94
- val = [v&0xffffffff, v>>32].pack("VV")
95
- else
96
- raise ProtocolError, "value too large: #{v}"
97
- end
82
+ if -0x8000_0000 <= v && v < 0x8000_0000
83
+ type = Field::TYPE_LONG
84
+ val = [v].pack('V')
85
+ elsif -0x8000_0000_0000_0000 <= v && v < 0x8000_0000_0000_0000
86
+ type = Field::TYPE_LONGLONG
87
+ val = [v&0xffffffff, v>>32].pack("VV")
88
+ elsif 0x8000_0000_0000_0000 <= v && v <= 0xffff_ffff_ffff_ffff
89
+ type = Field::TYPE_LONGLONG | 0x8000
90
+ val = [v&0xffffffff, v>>32].pack("VV")
98
91
  else
99
- if -v <= 256/2
100
- type = Field::TYPE_TINY
101
- val = [v].pack("C")
102
- elsif -v <= 256**2/2
103
- type = Field::TYPE_SHORT
104
- val = [v].pack("v")
105
- elsif -v <= 256**4/2
106
- type = Field::TYPE_LONG
107
- val = [v].pack("V")
108
- elsif -v <= 256**8/2
109
- type = Field::TYPE_LONGLONG
110
- val = [v&0xffffffff, v>>32].pack("VV")
111
- else
112
- raise ProtocolError, "value too large: #{v}"
113
- end
92
+ raise ProtocolError, "value too large: #{v}"
114
93
  end
115
94
  when Float
116
95
  type = Field::TYPE_DOUBLE
@@ -118,9 +97,12 @@ class Mysql
118
97
  when String
119
98
  type = Field::TYPE_STRING
120
99
  val = Packet.lcs(v)
121
- when Mysql::Time, ::Time
100
+ when ::Time
101
+ type = Field::TYPE_DATETIME
102
+ val = [11, v.year, v.month, v.day, v.hour, v.min, v.sec, v.usec].pack("CvCCCCCV")
103
+ when Mysql::Time
122
104
  type = Field::TYPE_DATETIME
123
- val = [7, v.year, v.month, v.day, v.hour, v.min, v.sec].pack("CvCCCCC")
105
+ val = [11, v.year, v.month, v.day, v.hour, v.min, v.sec, v.second_part].pack("CvCCCCCV")
124
106
  else
125
107
  raise ProtocolError, "class #{v.class} is not supported"
126
108
  end
@@ -488,7 +470,7 @@ class Mysql
488
470
  # === Exception
489
471
  # [ProtocolError] invalid packet sequence number
490
472
  def read
491
- ret = ""
473
+ data = ''
492
474
  len = nil
493
475
  begin
494
476
  Timeout.timeout @read_timeout do
@@ -500,6 +482,7 @@ class Mysql
500
482
  @seq = (@seq + 1) % 256
501
483
  ret = @sock.read(len)
502
484
  raise EOFError unless ret && ret.length == len
485
+ data.concat ret
503
486
  end
504
487
  rescue EOFError
505
488
  raise ClientError::ServerGoneError, 'MySQL server has gone away'
@@ -510,18 +493,19 @@ class Mysql
510
493
  @sqlstate = "00000"
511
494
 
512
495
  # Error packet
513
- if ret[0] == ?\xff
514
- f, errno, marker, @sqlstate, message = ret.unpack("Cvaa5a*")
496
+ if data[0] == ?\xff
497
+ f, errno, marker, @sqlstate, message = data.unpack("Cvaa5a*")
515
498
  unless marker == "#"
516
- f, errno, message = ret.unpack("Cva*") # Version 4.0 Error
499
+ f, errno, message = data.unpack("Cva*") # Version 4.0 Error
517
500
  @sqlstate = ""
518
501
  end
502
+ message.force_encoding(@charset.encoding)
519
503
  if Mysql::ServerError::ERROR_MAP.key? errno
520
504
  raise Mysql::ServerError::ERROR_MAP[errno].new(message, @sqlstate)
521
505
  end
522
506
  raise Mysql::ServerError.new(message, @sqlstate)
523
507
  end
524
- Packet.new(ret)
508
+ Packet.new(data)
525
509
  end
526
510
 
527
511
  # Write one packet data
@@ -1,4 +1,6 @@
1
1
  # coding: binary
2
+ require 'mysql/packet'
3
+
2
4
  describe Mysql::Packet do
3
5
  def self._(s)
4
6
  s.unpack('H*').first
@@ -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 == 20911
16
+ Mysql::VERSION.should == 20912
17
17
  end
18
18
  end
19
19
 
@@ -130,8 +130,8 @@ describe 'Mysql#options' do
130
130
  end
131
131
  it 'OPT_CONNECT_TIMEOUT: set timeout for connecting' do
132
132
  @m.options(Mysql::OPT_CONNECT_TIMEOUT, 0.1).should == @m
133
- UNIXSocket.stub!(:new).and_return{sleep 1}
134
- TCPSocket.stub!(:new).and_return{sleep 1}
133
+ UNIXSocket.stub(:new).and_return{sleep 1}
134
+ TCPSocket.stub(:new).and_return{sleep 1}
135
135
  proc{@m.connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT, MYSQL_SOCKET)}.should raise_error Mysql::ClientError, 'connection timeout'
136
136
  proc{@m.connect}.should raise_error Mysql::ClientError, 'connection timeout'
137
137
  end
@@ -1442,66 +1442,66 @@ describe 'Mysql::Stmt' do
1442
1442
 
1443
1443
  it '#fetch tinyblob column' do
1444
1444
  @m.query 'create temporary table t (i tinyblob)'
1445
- @m.query "insert into t values (null),('abc')"
1445
+ @m.query "insert into t values (null),('#{"a"*255}')"
1446
1446
  @s.prepare 'select i from t'
1447
1447
  @s.execute
1448
- @s.entries.should == [[nil], ["abc"]]
1448
+ @s.entries.should == [[nil], ["a"*255]]
1449
1449
  end
1450
1450
 
1451
1451
  it '#fetch tinytext column' do
1452
1452
  @m.query 'create temporary table t (i tinytext)'
1453
- @m.query "insert into t values (null),('abc')"
1453
+ @m.query "insert into t values (null),('#{"a"*255}')"
1454
1454
  @s.prepare 'select i from t'
1455
1455
  @s.execute
1456
- @s.entries.should == [[nil], ["abc"]]
1456
+ @s.entries.should == [[nil], ["a"*255]]
1457
1457
  end
1458
1458
 
1459
1459
  it '#fetch blob column' do
1460
1460
  @m.query 'create temporary table t (i blob)'
1461
- @m.query "insert into t values (null),('abc')"
1461
+ @m.query "insert into t values (null),('#{"a"*65535}')"
1462
1462
  @s.prepare 'select i from t'
1463
1463
  @s.execute
1464
- @s.entries.should == [[nil], ["abc"]]
1464
+ @s.entries.should == [[nil], ["a"*65535]]
1465
1465
  end
1466
1466
 
1467
1467
  it '#fetch text column' do
1468
1468
  @m.query 'create temporary table t (i text)'
1469
- @m.query "insert into t values (null),('abc')"
1469
+ @m.query "insert into t values (null),('#{"a"*65535}')"
1470
1470
  @s.prepare 'select i from t'
1471
1471
  @s.execute
1472
- @s.entries.should == [[nil], ["abc"]]
1472
+ @s.entries.should == [[nil], ["a"*65535]]
1473
1473
  end
1474
1474
 
1475
1475
  it '#fetch mediumblob column' do
1476
1476
  @m.query 'create temporary table t (i mediumblob)'
1477
- @m.query "insert into t values (null),('abc')"
1477
+ @m.query "insert into t values (null),('#{"a"*16777215}')"
1478
1478
  @s.prepare 'select i from t'
1479
1479
  @s.execute
1480
- @s.entries.should == [[nil], ["abc"]]
1480
+ @s.entries.should == [[nil], ['a'*16777215]]
1481
1481
  end
1482
1482
 
1483
1483
  it '#fetch mediumtext column' do
1484
1484
  @m.query 'create temporary table t (i mediumtext)'
1485
- @m.query "insert into t values (null),('abc')"
1485
+ @m.query "insert into t values (null),('#{"a"*16777215}')"
1486
1486
  @s.prepare 'select i from t'
1487
1487
  @s.execute
1488
- @s.entries.should == [[nil], ["abc"]]
1488
+ @s.entries.should == [[nil], ['a'*16777215]]
1489
1489
  end
1490
1490
 
1491
1491
  it '#fetch longblob column' do
1492
1492
  @m.query 'create temporary table t (i longblob)'
1493
- @m.query "insert into t values (null),('abc')"
1493
+ @m.query "insert into t values (null),('#{"a"*16777216}')"
1494
1494
  @s.prepare 'select i from t'
1495
1495
  @s.execute
1496
- @s.entries.should == [[nil], ["abc"]]
1496
+ @s.entries.should == [[nil], ["a"*16777216]]
1497
1497
  end
1498
1498
 
1499
1499
  it '#fetch longtext column' do
1500
1500
  @m.query 'create temporary table t (i longtext)'
1501
- @m.query "insert into t values (null),('abc')"
1501
+ @m.query "insert into t values (null),('#{"a"*16777216}')"
1502
1502
  @s.prepare 'select i from t'
1503
1503
  @s.execute
1504
- @s.entries.should == [[nil], ["abc"]]
1504
+ @s.entries.should == [[nil], ["a"*16777216]]
1505
1505
  end
1506
1506
 
1507
1507
  it '#fetch enum column' do
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.11
4
+ version: 2.9.12
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Tomita Masahiro
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-04-09 00:00:00.000000000 Z
12
+ date: 2013-12-17 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: This is MySQL connector. pure Ruby version
14
15
  email: tommy@tmtm.org
@@ -29,28 +30,28 @@ files:
29
30
  homepage: http://github.com/tmtm/ruby-mysql
30
31
  licenses:
31
32
  - Ruby's
32
- metadata: {}
33
33
  post_install_message:
34
34
  rdoc_options: []
35
35
  require_paths:
36
36
  - lib
37
37
  required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
38
39
  requirements:
39
- - - '>='
40
+ - - ! '>='
40
41
  - !ruby/object:Gem::Version
41
42
  version: '0'
42
43
  required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
43
45
  requirements:
44
- - - '>='
46
+ - - ! '>='
45
47
  - !ruby/object:Gem::Version
46
48
  version: '0'
47
49
  requirements: []
48
50
  rubyforge_project:
49
- rubygems_version: 2.0.0
51
+ rubygems_version: 1.8.23
50
52
  signing_key:
51
- specification_version: 4
53
+ specification_version: 3
52
54
  summary: MySQL connector
53
55
  test_files:
54
56
  - spec/mysql_spec.rb
55
57
  - spec/mysql/packet_spec.rb
56
- has_rdoc: true
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 7021fb12fc21daf12ea89138b4b10f9f95a68dd0
4
- data.tar.gz: 71ab24b33c3eec96baeb7d242175a1591aa3952b
5
- SHA512:
6
- metadata.gz: 85760ac7c8b6357ab21baf9a38fab0ade85c654f2375a038dda0c7a8052216eb6e3d0c8ce248bca660cca712e6b82548b5cb0539382939525f17c714a27a8602
7
- data.tar.gz: bcac0ca18511fe52460591511559cda8c242815d5fa7844a559cc0a05c3a93db6c4cde5cf93bd7ed2f7e837f303926ecb10226dbc224f100a16f0ec5e28b7758