Skip to content

Commit 8e46e5c

Browse files
committed
Merge pull request #544 from seuros/master
change sql_state to attr_reader to avoid ruby warning
2 parents 3f93699 + c047e82 commit 8e46e5c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/mysql2/error.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class Error < StandardError
55
REPLACEMENT_CHAR = '?'
66
ENCODE_OPTS = {:undef => :replace, :invalid => :replace, :replace => REPLACEMENT_CHAR}
77

8-
attr_accessor :error_number, :sql_state
8+
attr_accessor :error_number
9+
attr_reader :sql_state
910
attr_writer :server_version
1011

1112
# Mysql gem compatibility
@@ -18,10 +19,8 @@ def initialize(msg, server_version=nil)
1819
super(clean_message(msg))
1920
end
2021

21-
if "".respond_to? :encode
22-
def sql_state=(state)
23-
@sql_state = state.encode(ENCODE_OPTS)
24-
end
22+
def sql_state=(state)
23+
@sql_state = ''.respond_to?(:encode) ? state.encode(ENCODE_OPTS) : state
2524
end
2625

2726
private

0 commit comments

Comments
 (0)