diff options
author | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2010-02-10 19:50:59 +0200 |
---|---|---|
committer | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2010-03-01 12:02:10 +0200 |
commit | 20a10e5302ce8f912d27c57702b542a019c7f9f9 (patch) | |
tree | 38de3309520244ba6fda99b8d47525852e926491 /spec/arel/engines/sql/unit | |
parent | 98a87e181aed8131797e55db2ca957bc515cdaca (diff) | |
download | rails-20a10e5302ce8f912d27c57702b542a019c7f9f9.tar.gz rails-20a10e5302ce8f912d27c57702b542a019c7f9f9.tar.bz2 rails-20a10e5302ce8f912d27c57702b542a019c7f9f9.zip |
changes for Oracle support - OracleCompiler and corresponding tests with Oracle syntax
Diffstat (limited to 'spec/arel/engines/sql/unit')
22 files changed, 482 insertions, 45 deletions
diff --git a/spec/arel/engines/sql/unit/predicates/binary_spec.rb b/spec/arel/engines/sql/unit/predicates/binary_spec.rb index 08f3310f8e..72c8e44888 100644 --- a/spec/arel/engines/sql/unit/predicates/binary_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/binary_spec.rb @@ -37,6 +37,10 @@ module Arel adapter_is :sqlite3 do sql.should be_like(%Q{("users"."id" <=> 1 OR "users"."name" <=> 'name')}) end + + adapter_is :oracle do + sql.should be_like(%Q{("USERS"."ID" <=> 1 OR "USERS"."NAME" <=> 'name')}) + end end end end @@ -57,6 +61,10 @@ module Arel adapter_is :postgresql do sql.should be_like(%Q{("users"."id" <=> 1 AND "users"."name" <=> E'name')}) end + + adapter_is :oracle do + sql.should be_like(%Q{("USERS"."ID" <=> 1 AND "USERS"."NAME" <=> 'name')}) + end end end end @@ -71,7 +79,11 @@ module Arel sql.should be_like(%Q{`users`.`id` <=> `users`.`name`}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" <=> "USERS"."NAME"}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" <=> "users"."name"}) end end @@ -90,7 +102,11 @@ module Arel sql.should be_like(%Q{`users`.`id` <=> 1}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" <=> 1}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" <=> 1}) end end @@ -111,6 +127,10 @@ module Arel adapter_is :postgresql do sql.should be_like(%Q{"users"."name" <=> E'1-asdf'}) end + + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."NAME" <=> '1-asdf'}) + end end end end diff --git a/spec/arel/engines/sql/unit/predicates/equality_spec.rb b/spec/arel/engines/sql/unit/predicates/equality_spec.rb index 7a5cb42c85..bfd61185f2 100644 --- a/spec/arel/engines/sql/unit/predicates/equality_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/equality_spec.rb @@ -19,7 +19,11 @@ module Arel sql.should be_like(%Q{`users`.`id` = `photos`.`user_id`}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" = "PHOTOS"."USER_ID"}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" = "photos"."user_id"}) end end @@ -37,7 +41,11 @@ module Arel sql.should be_like(%Q{`users`.`id` IS NULL}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" IS NULL}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" IS NULL}) end end @@ -52,7 +60,11 @@ module Arel sql.should be_like(%Q{`users`.`id` IS NULL}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" IS NULL}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" IS NULL}) end end diff --git a/spec/arel/engines/sql/unit/predicates/in_spec.rb b/spec/arel/engines/sql/unit/predicates/in_spec.rb index a1c42f714e..5d9b2cdcaa 100644 --- a/spec/arel/engines/sql/unit/predicates/in_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/in_spec.rb @@ -22,7 +22,11 @@ module Arel sql.should be_like(%Q{`users`.`id` IN (1, 2, 3)}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" IN (1, 2, 3)}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" IN (1, 2, 3)}) end end @@ -40,7 +44,11 @@ module Arel sql.should be_like(%Q{`users`.`id` IN (1, 2, 3)}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" IN (1, 2, 3)}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" IN (1, 2, 3)}) end end @@ -58,7 +66,11 @@ module Arel sql.should be_like(%Q{`users`.`id` IN (NULL)}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" IN (NULL)}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" IN (NULL)}) end end @@ -78,7 +90,11 @@ module Arel sql.should be_like(%Q{`users`.`id` BETWEEN 1 AND 2}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID" BETWEEN 1 AND 2}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id" BETWEEN 1 AND 2}) end end @@ -109,6 +125,10 @@ module Arel adapter_is :postgresql do sql.should be_like(%Q{"developers"."created_at" BETWEEN '2010-01-01 00:00:00.000000' AND '2010-02-01 00:00:00.000000'}) end + + adapter_is :oracle do + sql.should be_like(%Q{"DEVELOPERS"."CREATED_AT" BETWEEN TO_TIMESTAMP('2010-01-01 00:00:00:000000','YYYY-MM-DD HH24:MI:SS:FF6') AND TO_TIMESTAMP('2010-02-01 00:00:00:000000','YYYY-MM-DD HH24:MI:SS:FF6')}) + end end end @@ -122,7 +142,13 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + "USERS"."ID" IN (SELECT "USERS"."ID", "USERS"."NAME" FROM "USERS") + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ "users"."id" IN (SELECT "users"."id", "users"."name" FROM "users") }) diff --git a/spec/arel/engines/sql/unit/predicates/predicates_spec.rb b/spec/arel/engines/sql/unit/predicates/predicates_spec.rb index 81c348357c..e6130cf267 100644 --- a/spec/arel/engines/sql/unit/predicates/predicates_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/predicates_spec.rb @@ -33,6 +33,12 @@ module Arel ("users"."id" = 1 AND "users"."name" = E'name') }) end + + adapter_is :oracle do + sql.should be_like(%Q{ + ("USERS"."ID" = 1 AND "USERS"."NAME" = 'name') + }) + end end end end @@ -59,6 +65,12 @@ module Arel ("users"."id" = 1 OR "users"."name" = E'name') }) end + + adapter_is :oracle do + sql.should be_like(%Q{ + ("USERS"."ID" = 1 OR "USERS"."NAME" = 'name') + }) + end end end end diff --git a/spec/arel/engines/sql/unit/primitives/attribute_spec.rb b/spec/arel/engines/sql/unit/primitives/attribute_spec.rb index d24b6a9d13..9f864dd3a1 100644 --- a/spec/arel/engines/sql/unit/primitives/attribute_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/attribute_spec.rb @@ -22,7 +22,11 @@ module Arel sql.should be_like(%Q{`users`.`id`}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{"USERS"."ID"}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{"users"."id"}) end end diff --git a/spec/arel/engines/sql/unit/primitives/expression_spec.rb b/spec/arel/engines/sql/unit/primitives/expression_spec.rb index d4df4f8d5a..3b6a7314a2 100644 --- a/spec/arel/engines/sql/unit/primitives/expression_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/expression_spec.rb @@ -15,7 +15,11 @@ module Arel sql.should be_like(%Q{COUNT(`users`.`id`) AS `alias`}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{COUNT("USERS"."ID") AS "ALIAS"}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{COUNT("users"."id") AS "alias"}) end end diff --git a/spec/arel/engines/sql/unit/primitives/literal_spec.rb b/spec/arel/engines/sql/unit/primitives/literal_spec.rb index cf66a60be9..3bf60100f1 100644 --- a/spec/arel/engines/sql/unit/primitives/literal_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/literal_spec.rb @@ -14,7 +14,11 @@ module Arel sql.should be_like(%Q{SELECT COUNT(*) AS count_id FROM `users`}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{SELECT COUNT(*) AS count_id FROM "USERS"}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{SELECT COUNT(*) AS count_id FROM "users"}) end end @@ -26,7 +30,11 @@ module Arel sql.should be_like(%Q{SELECT SUM(2 * credit_limit) AS sum_id FROM `users`}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{SELECT SUM(2 * credit_limit) AS sum_id FROM "USERS"}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{SELECT SUM(2 * credit_limit) AS sum_id FROM "users"}) end end diff --git a/spec/arel/engines/sql/unit/relations/alias_spec.rb b/spec/arel/engines/sql/unit/relations/alias_spec.rb index 55d5a9b671..a6fd7ab036 100644 --- a/spec/arel/engines/sql/unit/relations/alias_spec.rb +++ b/spec/arel/engines/sql/unit/relations/alias_spec.rb @@ -27,7 +27,17 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID" + FROM "USERS" + WHERE "USERS"."ID" = 1 + GROUP BY "USERS"."ID" + ORDER BY "USERS"."ID" ASC + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id" FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/delete_spec.rb b/spec/arel/engines/sql/unit/relations/delete_spec.rb index 0b1e2329b6..302a13c688 100644 --- a/spec/arel/engines/sql/unit/relations/delete_spec.rb +++ b/spec/arel/engines/sql/unit/relations/delete_spec.rb @@ -14,7 +14,11 @@ module Arel sql.should be_like(%Q{DELETE FROM `users`}) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{DELETE FROM "USERS"}) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{DELETE FROM "users"}) end end @@ -30,7 +34,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + DELETE + FROM "USERS" + WHERE "USERS"."ID" = 1 + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ DELETE FROM "users" @@ -50,7 +62,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + DELETE + FROM "USERS" + WHERE ROWNUM <= 1 + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ DELETE FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/from_spec.rb b/spec/arel/engines/sql/unit/relations/from_spec.rb index a611cd65f4..0be3ac0f9a 100644 --- a/spec/arel/engines/sql/unit/relations/from_spec.rb +++ b/spec/arel/engines/sql/unit/relations/from_spec.rb @@ -17,7 +17,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM workers + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM workers @@ -37,7 +44,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM users + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM users diff --git a/spec/arel/engines/sql/unit/relations/group_spec.rb b/spec/arel/engines/sql/unit/relations/group_spec.rb index 703dc35be5..72a9f4e99e 100644 --- a/spec/arel/engines/sql/unit/relations/group_spec.rb +++ b/spec/arel/engines/sql/unit/relations/group_spec.rb @@ -20,7 +20,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + GROUP BY "USERS"."ID" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" @@ -42,7 +50,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + GROUP BY asdf + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/having_spec.rb b/spec/arel/engines/sql/unit/relations/having_spec.rb index 915ee3af08..fe6f3cc520 100644 --- a/spec/arel/engines/sql/unit/relations/having_spec.rb +++ b/spec/arel/engines/sql/unit/relations/having_spec.rb @@ -20,7 +20,16 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "DEVELOPERS"."ID", "DEVELOPERS"."NAME", "DEVELOPERS"."SALARY", "DEVELOPERS"."DEPARTMENT", "DEVELOPERS"."CREATED_AT" + FROM "DEVELOPERS" + GROUP BY "DEVELOPERS"."DEPARTMENT" + HAVING MIN(salary) > 1000 + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "developers"."id", "developers"."name", "developers"."salary", "developers"."department", "developers"."created_at" FROM "developers" diff --git a/spec/arel/engines/sql/unit/relations/insert_spec.rb b/spec/arel/engines/sql/unit/relations/insert_spec.rb index 69c5bb052c..4b412093e4 100644 --- a/spec/arel/engines/sql/unit/relations/insert_spec.rb +++ b/spec/arel/engines/sql/unit/relations/insert_spec.rb @@ -46,6 +46,14 @@ module Arel RETURNING "id" }) end + + adapter_is :oracle do + @insertion.to_sql.should be_like(%Q{ + INSERT + INTO "USERS" + ("ID", "NAME") VALUES (1, 'nick') + }) + end end describe 'when given values whose types correspond to the types of the attributes' do @@ -78,6 +86,14 @@ module Arel RETURNING "id" }) end + + adapter_is :oracle do + @insertion.to_sql.should be_like(%Q{ + INSERT + INTO "USERS" + ("NAME") VALUES ('nick') + }) + end end end @@ -111,6 +127,15 @@ module Arel RETURNING "id" }) end + + adapter_is :oracle do + @insertion.to_sql.should be_like(%Q{ + INSERT + INTO "USERS" + ("ID") VALUES (1) + }) + end + end end end diff --git a/spec/arel/engines/sql/unit/relations/join_spec.rb b/spec/arel/engines/sql/unit/relations/join_spec.rb index b926c2aaab..2d23a06397 100644 --- a/spec/arel/engines/sql/unit/relations/join_spec.rb +++ b/spec/arel/engines/sql/unit/relations/join_spec.rb @@ -28,7 +28,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME", "PHOTOS"."ID", "PHOTOS"."USER_ID", "PHOTOS"."CAMERA_ID" + FROM "USERS" + INNER JOIN "PHOTOS" ON "USERS"."ID" = "PHOTOS"."USER_ID" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name", "photos"."id", "photos"."user_id", "photos"."camera_id" FROM "users" @@ -49,7 +57,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "SUPER_USERS"."ID", "SUPER_USERS"."NAME", "PHOTOS"."ID", "PHOTOS"."USER_ID", "PHOTOS"."CAMERA_ID" + FROM "USERS" "SUPER_USERS" + INNER JOIN "PHOTOS" ON "SUPER_USERS"."ID" = "PHOTOS"."USER_ID" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "super_users"."id", "super_users"."name", "photos"."id", "photos"."user_id", "photos"."camera_id" FROM "users" AS "super_users" @@ -71,7 +87,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "SUPER_USERS"."ID", "SUPER_USERS"."NAME", "SUPER_PHOTOS"."ID", "SUPER_PHOTOS"."USER_ID", "SUPER_PHOTOS"."CAMERA_ID" + FROM "USERS" "SUPER_USERS" + INNER JOIN "PHOTOS" "SUPER_PHOTOS" ON "SUPER_USERS"."ID" = "SUPER_PHOTOS"."USER_ID" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "super_users"."id", "super_users"."name", "super_photos"."id", "super_photos"."user_id", "super_photos"."camera_id" FROM "users" AS "super_users" @@ -95,7 +119,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + INNER JOIN asdf ON fdsa + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" @@ -119,7 +151,17 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + INNER JOIN asdf ON fdsa + INNER JOIN lifo ON fifo + INNER JOIN hatful ON hallow + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/lock_spec.rb b/spec/arel/engines/sql/unit/relations/lock_spec.rb index 23f8a9f577..72a8a2e457 100644 --- a/spec/arel/engines/sql/unit/relations/lock_spec.rb +++ b/spec/arel/engines/sql/unit/relations/lock_spec.rb @@ -30,6 +30,24 @@ module Arel FROM "users" }) end + + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" FOR UPDATE + }) + + sql_with_order_by = @relation.order(@relation[:id]).take(1).lock.to_sql + sql_with_order_by.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + WHERE "ID" IN (select * from + (SELECT "ID" FROM "USERS" ORDER BY "USERS"."ID" ASC) + where rownum <= 1) + FOR UPDATE + }) + + end end it "manufactures a select query locking with a given lock" do @@ -55,6 +73,13 @@ module Arel FROM "users" }) end + + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" LOCK IN SHARE MODE + }) + end end end end diff --git a/spec/arel/engines/sql/unit/relations/order_spec.rb b/spec/arel/engines/sql/unit/relations/order_spec.rb index 575e617021..3c9d9ef598 100644 --- a/spec/arel/engines/sql/unit/relations/order_spec.rb +++ b/spec/arel/engines/sql/unit/relations/order_spec.rb @@ -20,7 +20,31 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + ORDER BY "USERS"."ID" ASC + }) + + distinct_attributes = ActiveRecord::Base.connection.distinct('"USERS"."NAME"', '"USERS"."ID"') + @relation.project(distinct_attributes).order(@relation[:id]).to_sql.should be_like(%Q{ + SELECT DISTINCT "USERS"."NAME", + FIRST_VALUE("USERS"."ID") OVER (PARTITION BY "USERS"."NAME" ORDER BY "USERS"."ID") AS alias_0__ + FROM "USERS" + ORDER BY alias_0__ + }) + + distinct_attributes = ActiveRecord::Base.connection.distinct('"USERS"."NAME"', '"USERS"."ID" DESC') + @relation.project(distinct_attributes).order('"USERS"."ID" DESC').to_sql.should be_like(%Q{ + SELECT DISTINCT "USERS"."NAME", + FIRST_VALUE("USERS"."ID") OVER (PARTITION BY "USERS"."NAME" ORDER BY "USERS"."ID" DESC) AS alias_0__ + FROM "USERS" + ORDER BY alias_0__ DESC + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" @@ -46,7 +70,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + ORDER BY "USERS"."ID" ASC, "USERS"."NAME" ASC + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" @@ -72,7 +104,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + ORDER BY asdf + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" @@ -99,7 +139,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + ORDER BY "USERS"."NAME" ASC, "USERS"."ID" ASC + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/project_spec.rb b/spec/arel/engines/sql/unit/relations/project_spec.rb index 70f2dff70a..e73c7775a1 100644 --- a/spec/arel/engines/sql/unit/relations/project_spec.rb +++ b/spec/arel/engines/sql/unit/relations/project_spec.rb @@ -19,7 +19,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID" + FROM "USERS" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id" FROM "users" @@ -42,7 +49,13 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT (SELECT "USERS"."NAME" FROM "USERS") AS "USERS" FROM "USERS" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT (SELECT "users"."name" FROM "users") AS "users" FROM "users" }) @@ -60,7 +73,13 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT asdf FROM "USERS" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT asdf FROM "users" }) @@ -79,7 +98,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT COUNT("USERS"."ID") AS count_id + FROM "USERS" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT COUNT("users"."id") AS count_id FROM "users" @@ -97,7 +123,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT COUNT(DISTINCT "USERS"."ID") AS count_id + FROM "USERS" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT COUNT(DISTINCT "users"."id") AS count_id FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/skip_spec.rb b/spec/arel/engines/sql/unit/relations/skip_spec.rb index 2d606359ee..41b80d12d8 100644 --- a/spec/arel/engines/sql/unit/relations/skip_spec.rb +++ b/spec/arel/engines/sql/unit/relations/skip_spec.rb @@ -19,7 +19,16 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + select * from (select raw_sql_.*, rownum raw_rnum_ from + (SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS") raw_sql_) + where raw_rnum_ > 4 + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/table_spec.rb b/spec/arel/engines/sql/unit/relations/table_spec.rb index d8584ccaec..e497e1b6c2 100644 --- a/spec/arel/engines/sql/unit/relations/table_spec.rb +++ b/spec/arel/engines/sql/unit/relations/table_spec.rb @@ -17,7 +17,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" @@ -37,7 +44,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "SUPER_USERS"."ID", "SUPER_USERS"."NAME" + FROM "USERS" "SUPER_USERS" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "super_users"."id", "super_users"."name" FROM "users" AS "super_users" @@ -55,7 +69,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/take_spec.rb b/spec/arel/engines/sql/unit/relations/take_spec.rb index 2a8aea3d9d..9f2967a0bd 100644 --- a/spec/arel/engines/sql/unit/relations/take_spec.rb +++ b/spec/arel/engines/sql/unit/relations/take_spec.rb @@ -19,7 +19,24 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + WHERE ROWNUM <= 4 + }) + + sql_with_order_by = Take.new(@relation.order(@relation[:id]), @taken).to_sql + sql_with_order_by.should be_like(%Q{ + select * from + (SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + ORDER BY "USERS"."ID" ASC) + where rownum <= 4 + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" diff --git a/spec/arel/engines/sql/unit/relations/update_spec.rb b/spec/arel/engines/sql/unit/relations/update_spec.rb index fd444e27a8..cc2ad9913b 100644 --- a/spec/arel/engines/sql/unit/relations/update_spec.rb +++ b/spec/arel/engines/sql/unit/relations/update_spec.rb @@ -36,6 +36,13 @@ module Arel SET "id" = 1, "name" = E'nick' }) end + + adapter_is :oracle do + sql.should be_like(%Q{ + UPDATE "USERS" + SET "ID" = 1, "NAME" = 'nick' + }) + end end it "manufactures sql updating attributes when given a ranged relation" do @@ -64,6 +71,23 @@ module Arel WHERE "id" IN (SELECT "id" FROM "users" LIMIT 1) }) end + + adapter_is :oracle do + sql.should be_like(%Q{ + UPDATE "USERS" SET + "NAME" = 'nick' + WHERE "ID" IN (SELECT "ID" FROM "USERS" WHERE ROWNUM <= 1) + }) + + sql_with_order_by = Update.new(@relation.order(@relation[:id]).take(1), @relation[:name] => "nick").to_sql + sql_with_order_by.should be_like(%Q{ + UPDATE "USERS" SET + "NAME" = 'nick' + WHERE "ID" IN (select * from + (SELECT "ID" FROM "USERS" ORDER BY "USERS"."ID" ASC) + where rownum <= 1) + }) + end end describe 'when given values whose types correspond to the types of the attributes' do @@ -92,6 +116,13 @@ module Arel SET "name" = E'nick' }) end + + adapter_is :oracle do + @update.to_sql.should be_like(%Q{ + UPDATE "USERS" + SET "NAME" = 'nick' + }) + end end end @@ -108,7 +139,14 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + @update.to_sql.should be_like(%Q{ + UPDATE "USERS" + SET "ID" = 1 + }) + end + + adapter_is_not :mysql, :oracle do @update.to_sql.should be_like(%Q{ UPDATE "users" SET "id" = 1 @@ -149,6 +187,14 @@ module Arel WHERE "users"."id" = 1 }) end + + adapter_is :oracle do + @update.to_sql.should be_like(%Q{ + UPDATE "USERS" + SET "NAME" = 'nick' + WHERE "USERS"."ID" = 1 + }) + end end end end diff --git a/spec/arel/engines/sql/unit/relations/where_spec.rb b/spec/arel/engines/sql/unit/relations/where_spec.rb index 8f9a8db4c7..5f559efad3 100644 --- a/spec/arel/engines/sql/unit/relations/where_spec.rb +++ b/spec/arel/engines/sql/unit/relations/where_spec.rb @@ -20,7 +20,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + WHERE "USERS"."ID" = 1 + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" @@ -42,7 +50,15 @@ module Arel }) end - adapter_is_not :mysql do + adapter_is :oracle do + sql.should be_like(%Q{ + SELECT "USERS"."ID", "USERS"."NAME" + FROM "USERS" + WHERE asdf + }) + end + + adapter_is_not :mysql, :oracle do sql.should be_like(%Q{ SELECT "users"."id", "users"."name" FROM "users" |