lib/github/sql.rb in github-ds-0.2.8 vs lib/github/sql.rb in github-ds-0.2.9
- old
+ new
@@ -19,15 +19,22 @@
# Things to be aware of:
#
# * `nil` is always considered an error and not a usable value. If you need a
# SQL NULL, use the NULL constant instead.
#
- # * Identical column names in SELECTs will be overridden:
- # `SELECT t1.id, t2.id FROM...` will only return one value for `id`. To get
- # more than one column of the same name, use aliases:
+ # * Identical column names in SELECTs will be overridden for hash_results:
+ # `SELECT t1.id, t2.id FROM...` will only return one value for `id`. The
+ # second ID colum won't be included in the hash:
+ #
+ # [{ "id" => "1" }]
+ #
+ # To get more than one column of the same name, use aliases:
# `SELECT t1.id t1_id, t2.id t2_id FROM ...`
#
+ # Calling `results` however will return an array with all the values:
+ # [[1, 1]]
+ #
# * Arrays are escaped as `(item, item, item)`. If you need to insert multiple
# rows (Arrays of Arrays), you must specify the bind value using
# GitHub::SQL::ROWS(array_of_arrays).
#
class SQL
@@ -230,12 +237,12 @@
when /\AUPDATE/i
@affected_rows = connection.update(query, "#{self.class.name} Update")
when /\ASELECT/i
# Why not execute or select_rows? Because select_all hits the query cache.
- @hash_results = connection.select_all(query, "#{self.class.name} Select").to_ary
- @results = @hash_results.map(&:values)
-
+ ar_results = connection.select_all(query, "#{self.class.name} Select")
+ @hash_results = ar_results.to_ary
+ @results = ar_results.rows
else
@results = connection.execute(query, "#{self.class.name} Execute").to_a
end
@results ||= []