ruby-mysql 2.9.3 → 2.9.4
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/ChangeLog +27 -0
- data/README.rdoc +2 -2
- data/lib/mysql/charset.rb +151 -129
- data/lib/mysql/error.rb +794 -490
- data/lib/mysql/protocol.rb +6 -3
- data/lib/mysql.rb +30 -2
- metadata +16 -5
data/lib/mysql/protocol.rb
CHANGED
@@ -563,13 +563,15 @@ class Mysql
|
|
563
563
|
len = nil
|
564
564
|
begin
|
565
565
|
Timeout.timeout @read_timeout do
|
566
|
-
header = @sock.
|
566
|
+
header = @sock.sysread(4)
|
567
567
|
len1, len2, seq = header.unpack("CvC")
|
568
568
|
len = (len2 << 8) + len1
|
569
569
|
raise ProtocolError, "invalid packet: sequence number mismatch(#{seq} != #{@seq}(expected))" if @seq != seq
|
570
570
|
@seq = (@seq + 1) % 256
|
571
|
-
ret.concat @sock.
|
571
|
+
ret.concat @sock.sysread(len)
|
572
572
|
end
|
573
|
+
rescue EOFError
|
574
|
+
raise ClientError::ServerGoneError, 'The MySQL server has gone away'
|
573
575
|
rescue Timeout::Error
|
574
576
|
raise ClientError, "read timeout"
|
575
577
|
end while len == MAX_PACKET_LENGTH
|
@@ -616,6 +618,8 @@ class Mysql
|
|
616
618
|
Timeout.timeout @write_timeout do
|
617
619
|
@sock.flush
|
618
620
|
end
|
621
|
+
rescue Errno::EPIPE
|
622
|
+
raise ClientError::ServerGoneError, 'The MySQL server has gone away'
|
619
623
|
rescue Timeout::Error
|
620
624
|
raise ClientError, "write timeout"
|
621
625
|
end
|
@@ -663,7 +667,6 @@ class Mysql
|
|
663
667
|
rest_scramble_buff = data.unpack("CZ*Va8CvCva13Z13")
|
664
668
|
raise ProtocolError, "unsupported version: #{protocol_version}" unless protocol_version == VERSION
|
665
669
|
raise ProtocolError, "invalid packet: f0=#{f0}" unless f0 == 0
|
666
|
-
raise ProtocolError, "invalid packet: f1=#{f1.inspect}" unless f1 == "\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
667
670
|
scramble_buff.concat rest_scramble_buff
|
668
671
|
self.new protocol_version, server_version, thread_id, server_capabilities, server_charset, server_status, scramble_buff
|
669
672
|
end
|
data/lib/mysql.rb
CHANGED
@@ -16,7 +16,7 @@ class Mysql
|
|
16
16
|
require "#{dir}/mysql/charset"
|
17
17
|
require "#{dir}/mysql/protocol"
|
18
18
|
|
19
|
-
VERSION =
|
19
|
+
VERSION = 20904 # Version number of this library
|
20
20
|
MYSQL_UNIX_PORT = "/tmp/mysql.sock" # UNIX domain socket filename
|
21
21
|
MYSQL_TCP_PORT = 3306 # TCP socket port number
|
22
22
|
|
@@ -125,6 +125,15 @@ class Mysql
|
|
125
125
|
return self
|
126
126
|
end
|
127
127
|
|
128
|
+
# Disconnect from mysql without QUIT packet.
|
129
|
+
def close!
|
130
|
+
if @protocol
|
131
|
+
@protocol.close
|
132
|
+
@protocol = nil
|
133
|
+
end
|
134
|
+
return self
|
135
|
+
end
|
136
|
+
|
128
137
|
# Set option for connection.
|
129
138
|
#
|
130
139
|
# Available options:
|
@@ -258,6 +267,7 @@ class Mysql
|
|
258
267
|
# === Return
|
259
268
|
# [String] server version
|
260
269
|
def server_info
|
270
|
+
check_connection
|
261
271
|
@protocol.server_info
|
262
272
|
end
|
263
273
|
alias get_server_info server_info
|
@@ -265,6 +275,7 @@ class Mysql
|
|
265
275
|
# === Return
|
266
276
|
# [Integer] server version
|
267
277
|
def server_version
|
278
|
+
check_connection
|
268
279
|
@protocol.server_version
|
269
280
|
end
|
270
281
|
alias get_server_version server_version
|
@@ -287,6 +298,7 @@ class Mysql
|
|
287
298
|
# === Return
|
288
299
|
# self
|
289
300
|
def kill(pid)
|
301
|
+
check_connection
|
290
302
|
@protocol.kill_command pid
|
291
303
|
self
|
292
304
|
end
|
@@ -314,6 +326,7 @@ class Mysql
|
|
314
326
|
# === Example
|
315
327
|
# my.query("select 1,NULL,'abc'").fetch # => [1, nil, "abc"]
|
316
328
|
def query(str, &block)
|
329
|
+
check_connection
|
317
330
|
@fields = nil
|
318
331
|
begin
|
319
332
|
nfields = @protocol.query_command str
|
@@ -348,6 +361,7 @@ class Mysql
|
|
348
361
|
# === Return
|
349
362
|
# [Mysql::Result]
|
350
363
|
def store_result
|
364
|
+
check_connection
|
351
365
|
raise ClientError, 'invalid usage' unless @result_exist
|
352
366
|
res = Result.new @fields, @protocol
|
353
367
|
@server_status = @protocol.server_status
|
@@ -359,6 +373,7 @@ class Mysql
|
|
359
373
|
# === Return
|
360
374
|
# [Integer] Thread ID
|
361
375
|
def thread_id
|
376
|
+
check_connection
|
362
377
|
@protocol.thread_id
|
363
378
|
end
|
364
379
|
|
@@ -373,6 +388,7 @@ class Mysql
|
|
373
388
|
# === Return
|
374
389
|
# self
|
375
390
|
def set_server_option(opt)
|
391
|
+
check_connection
|
376
392
|
@protocol.set_option_command opt
|
377
393
|
self
|
378
394
|
end
|
@@ -388,6 +404,7 @@ class Mysql
|
|
388
404
|
# true if next query exists.
|
389
405
|
def next_result
|
390
406
|
return false unless more_results
|
407
|
+
check_connection
|
391
408
|
@fields = nil
|
392
409
|
nfields = @protocol.get_result
|
393
410
|
if nfields
|
@@ -423,6 +440,7 @@ class Mysql
|
|
423
440
|
# === Return
|
424
441
|
# [Mysql::Result]
|
425
442
|
def list_fields(table, field=nil)
|
443
|
+
check_connection
|
426
444
|
begin
|
427
445
|
fields = @protocol.field_list_command table, field
|
428
446
|
return Result.new fields
|
@@ -437,6 +455,7 @@ class Mysql
|
|
437
455
|
# === Return
|
438
456
|
# [Mysql::Result]
|
439
457
|
def list_processes
|
458
|
+
check_connection
|
440
459
|
@fields = @protocol.process_info_command
|
441
460
|
@result_exist = true
|
442
461
|
store_result
|
@@ -459,6 +478,7 @@ class Mysql
|
|
459
478
|
# === Return
|
460
479
|
# self
|
461
480
|
def ping
|
481
|
+
check_connection
|
462
482
|
@protocol.ping_command
|
463
483
|
self
|
464
484
|
end
|
@@ -469,6 +489,7 @@ class Mysql
|
|
469
489
|
# === Return
|
470
490
|
# self
|
471
491
|
def refresh(op)
|
492
|
+
check_connection
|
472
493
|
@protocol.refresh_command op
|
473
494
|
self
|
474
495
|
end
|
@@ -492,6 +513,7 @@ class Mysql
|
|
492
513
|
# === Return
|
493
514
|
# self
|
494
515
|
def shutdown(level=0)
|
516
|
+
check_connection
|
495
517
|
@protocol.shutdown_command level
|
496
518
|
self
|
497
519
|
end
|
@@ -499,7 +521,7 @@ class Mysql
|
|
499
521
|
# === Return
|
500
522
|
# [String] statistics message
|
501
523
|
def stat
|
502
|
-
@protocol.statistics_command
|
524
|
+
@protocol ? @protocol.statistics_command : 'MySQL server has gone away'
|
503
525
|
end
|
504
526
|
|
505
527
|
# Commit transaction
|
@@ -528,6 +550,12 @@ class Mysql
|
|
528
550
|
self
|
529
551
|
end
|
530
552
|
|
553
|
+
private
|
554
|
+
|
555
|
+
def check_connection
|
556
|
+
raise ClientError::ServerGoneError, 'The MySQL server has gone away' unless @protocol
|
557
|
+
end
|
558
|
+
|
531
559
|
# Field class
|
532
560
|
class Field
|
533
561
|
attr_reader :db # database name
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 2
|
7
|
+
- 9
|
8
|
+
- 4
|
9
|
+
version: 2.9.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- tommy
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-12-29 00:00:00 +09:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -51,21 +56,27 @@ rdoc_options:
|
|
51
56
|
require_paths:
|
52
57
|
- lib
|
53
58
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
54
60
|
requirements:
|
55
61
|
- - ">="
|
56
62
|
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 8
|
66
|
+
- 7
|
57
67
|
version: 1.8.7
|
58
|
-
version:
|
59
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
60
70
|
requirements:
|
61
71
|
- - ">="
|
62
72
|
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
63
75
|
version: "0"
|
64
|
-
version:
|
65
76
|
requirements: []
|
66
77
|
|
67
78
|
rubyforge_project: rubymysql
|
68
|
-
rubygems_version: 1.3.
|
79
|
+
rubygems_version: 1.3.7
|
69
80
|
signing_key:
|
70
81
|
specification_version: 2
|
71
82
|
summary: MySQL connector for Ruby
|