-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Mysql2::Client#query return value to be uniquely determined (#564)
The return value of `Mysql2::Client#query` is determined by the combination of the `as` argument of the `self.new` method and the `query` method. Fixed it so that it can be expressed using Generics.
- Loading branch information
1 parent
b9c1383
commit f6ddbae
Showing
4 changed files
with
55 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "mysql2" | ||
|
||
as = :array | ||
Mysql2::Client.new(as: as).query("SELECT * FROM users").each do |row| | ||
if row.is_a?(Array) | ||
row[0] # Array | ||
elsif row.is_a?(Hash) | ||
row[:id] # Hash | ||
end | ||
end | ||
|
||
Mysql2::Client.new.query("SELECT * FROM users").each do |row| | ||
row[:id] # Hash | ||
end | ||
|
||
Mysql2::Client.new.query("SELECT * FROM users", as: :hash).each do |row| | ||
row[:id] # Hash | ||
end | ||
|
||
Mysql2::Client.new.query("SELECT * FROM users", as: :array).each do |row| | ||
row[0] # Array | ||
end | ||
|
||
Mysql2::Client.new(as: :hash).query("SELECT * FROM users").each do |row| | ||
row[:id] # Hash | ||
end | ||
|
||
Mysql2::Client.new(as: :hash).query("SELECT * FROM users", as: :hash).each do |row| | ||
row[:id] # Hash | ||
end | ||
|
||
Mysql2::Client.new(as: :hash).query("SELECT * FROM users", as: :array).each do |row| | ||
row[0] # Array | ||
end | ||
|
||
Mysql2::Client.new(as: :array).query("SELECT * FROM users").each do |row| | ||
row[0] # Array | ||
end | ||
|
||
Mysql2::Client.new(as: :array).query("SELECT * FROM users", as: :hash).each do |row| | ||
row[:id] # Hash | ||
end | ||
|
||
Mysql2::Client.new(as: :array).query("SELECT * FROM users", as: :array).each do |row| | ||
row[0] # Array | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters