Skip to content

Changing database in query options hash has no effect #437

@gstaubli

Description

@gstaubli

Table:

prod.final_product

Re-creating bug:

client = Mysql2::Client.new(
{
  :host => "127.0.0.1", 
  :username => "username", 
  :password => "password", 
  :database => ""
}) # => #<Mysql2::Client ... :database => ""}, @read_timeout=nil>
client.query("SELECT * FROM final_product") # => Mysql2::Error: No database selected
client.query_options[:database] = "prod" # => "prod"
client # => #<Mysql2::Client ... @query_options = { ... :database => "prod"}, @read_timeout=nil>
client.query("SELECT * FROM final_product") # => Mysql2::Error: No database selected

Workarounds to manipulating query_options hash

Using #select_db

client = Mysql2::Client.new(
{
  :host => "127.0.0.1", 
  :username => "username", 
  :password => "password", 
  :database => ""
}) # => #<Mysql2::Client ... :database => ""}, @read_timeout=nil>
client.select_db("prod") # => "prod"
client.query("SELECT * FROM final_product") # => #<Mysql2::Result ... :database => "prod"}>

Using options hash on client initialization

client = Mysql2::Client.new(
{
  :host => "127.0.0.1", 
  :username => "username", 
  :password => "password", 
  :database => "prod"
}) # => #<Mysql2::Client ... :database => ""}, @read_timeout=nil>
client.query("SELECT * FROM final_product") # => #<Mysql2::Result ... :database => "prod"}>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions