Skip to content

Commit be8a727

Browse files
committed
Remove deprecated connection options, raise instead of warn if they are used
1 parent a9b51b1 commit be8a727

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

lib/mysql2/client.rb

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,22 @@ def initialize(opts = {})
4646
ssl_options = opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher)
4747
ssl_set(*ssl_options) if ssl_options.any?
4848

49-
if [:user,:pass,:hostname,:dbname,:db,:sock].any?{|k| @query_options.has_key?(k) }
50-
warn "============= WARNING FROM mysql2 ============="
51-
warn "The options :user, :pass, :hostname, :dbname, :db, and :sock will be deprecated at some point in the future."
52-
warn "Instead, please use :username, :password, :host, :port, :database, :socket, :flags for the options."
53-
warn "============= END WARNING FROM mysql2 ========="
49+
if [:user, :pass, :hostname, :dbname, :db, :sock].any? { |k| @connect_options.has_key? k }
50+
raise <<-DEPR
51+
The options :user, :pass, :hostname, :dbname, :db, :sock are removed.
52+
Please use :username, :password, :host, :port, :database, :socket instead.
53+
DEPR
5454
end
5555

56-
user = opts[:username] || opts[:user]
57-
pass = opts[:password] || opts[:pass]
58-
host = opts[:host] || opts[:hostname]
59-
port = opts[:port]
60-
database = opts[:database] || opts[:dbname] || opts[:db]
61-
socket = opts[:socket] || opts[:sock]
62-
flags = opts[:flags] ? opts[:flags] | @connect_options[:connect_flags] : @connect_options[:connect_flags]
63-
6456
# Correct the data types before passing these values down to the C level
65-
user = user.to_s unless user.nil?
66-
pass = pass.to_s unless pass.nil?
67-
host = host.to_s unless host.nil?
68-
port = port.to_i unless port.nil?
69-
database = database.to_s unless database.nil?
70-
socket = socket.to_s unless socket.nil?
71-
flags = flags.to_i # if nil then 0
57+
user = opts[:username].to_s unless opts[:username].nil?
58+
pass = opts[:password].to_s unless opts[:password].nil?
59+
host = opts[:host].to_s unless opts[:host].nil?
60+
port = opts[:port].to_i unless opts[:port].nil?
61+
database = opts[:database].to_s unless opts[:database].nil?
62+
socket = opts[:socket].to_s unless opts[:socket].nil?
63+
flags = opts[:flags] ? opts[:flags] | @connect_options[:connect_flags] : @connect_options[:connect_flags]
64+
flags ||= 0 # if nil then 0
7265

7366
connect user, pass, host, port, database, socket, flags
7467
end

0 commit comments

Comments
 (0)