Permalink
Browse files

Remove " AS " keyword from table aliasing.

  • Loading branch information...
miloops committed Mar 1, 2010
1 parent 52b9eb1 commit 1994d3e61dd841ad1367922c5c608c9f5f277161
@@ -93,24 +93,17 @@ def select(select_sql, table)
class TableReference < Formatter
def select(select_sql, table)
- "(#{select_sql})#{as_keyword}#{quote_table_name(name_for(table))}"
+ "(#{select_sql}) #{quote_table_name(name_for(table))}"
end
def table(table)
if table.name =~ /\s/
table.name
else
quote_table_name(table.name) +
- (table.name != name_for(table) ? as_keyword + quote_table_name(name_for(table)) : '')
+ (table.name != name_for(table) ? " #{quote_table_name(name_for(table))}" : '')
end
end
-
- private
-
- def as_keyword
- # AS keyword should not be used before table alias in Oracle
- as_keyword = engine.adapter_name == "Oracle" ? " " : " AS "
- end
end
class Attribute < WhereCondition
@@ -17,7 +17,7 @@ module Arel
sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
FROM `users`
- INNER JOIN `users` AS `users_2`
+ INNER JOIN `users` `users_2`
ON `users`.`id` = `users_2`.`id`
})
end
@@ -35,7 +35,7 @@ module Arel
sql.should be_like(%Q{
SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name"
FROM "users"
- INNER JOIN "users" AS "users_2"
+ INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
})
end
@@ -52,7 +52,7 @@ module Arel
sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
FROM `users`
- INNER JOIN `users` AS `users_2`
+ INNER JOIN `users` `users_2`
ON `users`.`id` = `users_2`.`id` AND `users_2`.`id` = 1
})
end
@@ -70,7 +70,7 @@ module Arel
sql.should be_like(%Q{
SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name"
FROM "users"
- INNER JOIN "users" AS "users_2"
+ INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id" AND "users_2"."id" = 1
})
end
@@ -89,7 +89,7 @@ module Arel
sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`
FROM `users`
- INNER JOIN `users` AS `users_2`
+ INNER JOIN `users` `users_2`
ON `users_2`.`id` = `users`.`id` AND `users_2`.`id` = 1
})
end
@@ -107,7 +107,7 @@ module Arel
sql.should be_like(%Q{
SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name"
FROM "users"
- INNER JOIN "users" AS "users_2"
+ INNER JOIN "users" "users_2"
ON "users_2"."id" = "users"."id" AND "users_2"."id" = 1
})
end
@@ -133,9 +133,9 @@ module Arel
sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
FROM `users`
- INNER JOIN `users` AS `users_2`
+ INNER JOIN `users` `users_2`
ON `users`.`id` = `users_2`.`id`
- INNER JOIN `users` AS `users_3`
+ INNER JOIN `users` `users_3`
ON `users_2`.`id` = `users_3`.`id`
})
end
@@ -155,9 +155,9 @@ module Arel
sql.should be_like(%Q{
SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name", "users_3"."id", "users_3"."name"
FROM "users"
- INNER JOIN "users" AS "users_2"
+ INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
- INNER JOIN "users" AS "users_3"
+ INNER JOIN "users" "users_3"
ON "users_2"."id" = "users_3"."id"
})
end
@@ -175,9 +175,9 @@ module Arel
sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `users_2`.`id`, `users_2`.`name`, `users_3`.`id`, `users_3`.`name`
FROM `users`
- INNER JOIN `users` AS `users_2`
+ INNER JOIN `users` `users_2`
ON `users`.`id` = `users_2`.`id`
- INNER JOIN `users` AS `users_3`
+ INNER JOIN `users` `users_3`
ON `users_2`.`id` = `users_3`.`id`
})
end
@@ -197,9 +197,9 @@ module Arel
sql.should be_like(%Q{
SELECT "users"."id", "users"."name", "users_2"."id", "users_2"."name", "users_3"."id", "users_3"."name"
FROM "users"
- INNER JOIN "users" AS "users_2"
+ INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
- INNER JOIN "users" AS "users_3"
+ INNER JOIN "users" "users_3"
ON "users_2"."id" = "users_3"."id"
})
end
@@ -24,7 +24,7 @@ module Arel
sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `photos_external`.`id`, `photos_external`.`user_id`, `photos_external`.`camera_id`
FROM `users`
- INNER JOIN (SELECT `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id` FROM `photos` LIMIT 3) AS `photos_external`
+ INNER JOIN (SELECT `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id` FROM `photos` LIMIT 3) `photos_external`
ON `users`.`id` = `photos_external`.`user_id`
})
end
@@ -42,7 +42,7 @@ module Arel
sql.should be_like(%Q{
SELECT "users"."id", "users"."name", "photos_external"."id", "photos_external"."user_id", "photos_external"."camera_id"
FROM "users"
- INNER JOIN (SELECT "photos"."id", "photos"."user_id", "photos"."camera_id" FROM "photos" LIMIT 3) AS "photos_external"
+ INNER JOIN (SELECT "photos"."id", "photos"."user_id", "photos"."camera_id" FROM "photos" LIMIT 3) "photos_external"
ON "users"."id" = "photos_external"."user_id"
})
end
@@ -56,7 +56,7 @@ module Arel
sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `photos_external`.`user_id`, `photos_external`.`cnt`
FROM `users`
- INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_external`
+ INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) `photos_external`
ON `users`.`id` = `photos_external`.`user_id`
})
end
@@ -74,7 +74,7 @@ module Arel
sql.should be_like(%Q{
SELECT "users"."id", "users"."name", "photos_external"."user_id", "photos_external"."cnt"
FROM "users"
- INNER JOIN (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" GROUP BY "photos"."user_id") AS "photos_external"
+ INNER JOIN (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" GROUP BY "photos"."user_id") "photos_external"
ON "users"."id" = "photos_external"."user_id"
})
end
@@ -88,7 +88,7 @@ module Arel
adapter_is :mysql do
sql.should be_like(%Q{
SELECT `photos_external`.`user_id`, `photos_external`.`cnt`, `users`.`id`, `users`.`name`
- FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_external`
+ FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) `photos_external`
INNER JOIN `users`
ON `users`.`id` = `photos_external`.`user_id`
})
@@ -106,7 +106,7 @@ module Arel
adapter_is_not :mysql, :oracle do
sql.should be_like(%Q{
SELECT "photos_external"."user_id", "photos_external"."cnt", "users"."id", "users"."name"
- FROM (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" GROUP BY "photos"."user_id") AS "photos_external"
+ FROM (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" GROUP BY "photos"."user_id") "photos_external"
INNER JOIN "users"
ON "users"."id" = "photos_external"."user_id"
})
@@ -122,8 +122,8 @@ module Arel
adapter_is :mysql do
sql.should be_like(%Q{
SELECT `photos_external`.`user_id`, `photos_external`.`cnt`, `photos_external_2`.`user_id`, `photos_external_2`.`cnt`
- FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_external`
- INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) AS `photos_external_2`
+ FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) `photos_external`
+ INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` GROUP BY `photos`.`user_id`) `photos_external_2`
ON `photos_external_2`.`user_id` = `photos_external`.`user_id`
})
end
@@ -140,8 +140,8 @@ module Arel
adapter_is_not :mysql, :oracle do
sql.should be_like(%Q{
SELECT "photos_external"."user_id", "photos_external"."cnt", "photos_external_2"."user_id", "photos_external_2"."cnt"
- FROM (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" GROUP BY "photos"."user_id") AS "photos_external"
- INNER JOIN (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" GROUP BY "photos"."user_id") AS "photos_external_2"
+ FROM (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" GROUP BY "photos"."user_id") "photos_external"
+ INNER JOIN (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" GROUP BY "photos"."user_id") "photos_external_2"
ON "photos_external_2"."user_id" = "photos_external"."user_id"
})
end
@@ -157,7 +157,7 @@ module Arel
sql.should be_like(%Q{
SELECT `users`.`id`, `users`.`name`, `photos_external`.`user_id`, `photos_external`.`cnt`
FROM `users`
- INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) AS `photos_external`
+ INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) `photos_external`
ON `users`.`id` = `photos_external`.`user_id`
})
end
@@ -175,7 +175,7 @@ module Arel
sql.should be_like(%Q{
SELECT "users"."id", "users"."name", "photos_external"."user_id", "photos_external"."cnt"
FROM "users"
- INNER JOIN (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" WHERE "photos"."user_id" = 1 GROUP BY "photos"."user_id") AS "photos_external"
+ INNER JOIN (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" WHERE "photos"."user_id" = 1 GROUP BY "photos"."user_id") "photos_external"
ON "users"."id" = "photos_external"."user_id"
})
end
@@ -189,7 +189,7 @@ module Arel
adapter_is :mysql do
sql.should be_like(%Q{
SELECT `photos_external`.`user_id`, `photos_external`.`cnt`, `users`.`id`, `users`.`name`
- FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) AS `photos_external`
+ FROM (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) `photos_external`
INNER JOIN `users`
ON `users`.`id` = `photos_external`.`user_id`
})
@@ -207,7 +207,7 @@ module Arel
adapter_is_not :mysql, :oracle do
sql.should be_like(%Q{
SELECT "photos_external"."user_id", "photos_external"."cnt", "users"."id", "users"."name"
- FROM (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" WHERE "photos"."user_id" = 1 GROUP BY "photos"."user_id") AS "photos_external"
+ FROM (SELECT "photos"."user_id", COUNT("photos"."id") AS "cnt" FROM "photos" WHERE "photos"."user_id" = 1 GROUP BY "photos"."user_id") "photos_external"
INNER JOIN "users"
ON "users"."id" = "photos_external"."user_id"
})
@@ -52,7 +52,7 @@ module Arel
adapter_is :mysql 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`
+ FROM `users` `super_users`
INNER JOIN `photos` ON `super_users`.`id` = `photos`.`user_id`
})
end
@@ -68,7 +68,7 @@ module Arel
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"
+ FROM "users" "super_users"
INNER JOIN "photos" ON "super_users"."id" = "photos"."user_id"
})
end
@@ -82,8 +82,8 @@ module Arel
adapter_is :mysql 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`
- INNER JOIN `photos` AS `super_photos` ON `super_users`.`id` = `super_photos`.`user_id`
+ FROM `users` `super_users`
+ INNER JOIN `photos` `super_photos` ON `super_users`.`id` = `super_photos`.`user_id`
})
end
@@ -98,8 +98,8 @@ module Arel
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"
- INNER JOIN "photos" AS "super_photos" ON "super_users"."id" = "super_photos"."user_id"
+ FROM "users" "super_users"
+ INNER JOIN "photos" "super_photos" ON "super_users"."id" = "super_photos"."user_id"
})
end
end
@@ -40,7 +40,7 @@ module Arel
adapter_is :mysql do
sql.should be_like(%Q{
SELECT `super_users`.`id`, `super_users`.`name`
- FROM `users` AS `super_users`
+ FROM `users` `super_users`
})
end
@@ -54,7 +54,7 @@ module Arel
adapter_is_not :mysql, :oracle do
sql.should be_like(%Q{
SELECT "super_users"."id", "super_users"."name"
- FROM "users" AS "super_users"
+ FROM "users" "super_users"
})
end
end

0 comments on commit 1994d3e

Please sign in to comment.