Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support aliasing subselects in the Oracle adapter

  • Loading branch information...
commit 0c7c893c5093337008f59de6885bd682cf8d327b 1 parent 8b39513
@jeremyevans authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Support aliasing subselects in the Oracle adapter (jeremyevans)
+
* Add a subadapter for the Progress RDBMS to the ODBC adapter (:db_type=>'progress') (groveriffic) (#251)
* Make MySQL and Oracle adapters raise an Error if asked to do a SELECT DISTINCT ON (jeremyevans)
View
6 lib/sequel_core/adapters/shared/oracle.rb
@@ -21,6 +21,12 @@ def empty?
private
+ # Oracle doesn't support the use of AS when aliasing a dataset. It doesn't require
+ # the use of AS anywhere, so this disables it in all cases.
+ def as_sql(expression, aliaz)
+ "#{expression} #{quote_identifier(aliaz)}"
+ end
+
def select_clause_order
SELECT_CLAUSE_ORDER
end
View
22 spec/adapters/oracle_spec.rb
@@ -220,3 +220,25 @@
]
end
end
+
+context "Oracle aliasing" do
+ setup do
+ @d1 = ORACLE_DB[:books]
+ @d1.delete # remove all records
+ @d1 << {:id => 1, :title => 'aaa', :category_id => 100}
+ @d1 << {:id => 2, :title => 'bbb', :category_id => 100}
+ @d1 << {:id => 3, :title => 'bbb', :category_id => 100}
+ end
+
+ specify "should allow columns to be renamed" do
+ @d1.select(:title.as(:name)).order_by(:id).to_a.should == [
+ { :name => 'aaa' },
+ { :name => 'bbb' },
+ { :name => 'bbb' },
+ ]
+ end
+
+ specify "nested queries should work" do
+ @d1.select(:title).group_by(:title).count.should == 2
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.