From 263479b5a344e5882f4941e3f18faf9f027b0615 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sat, 18 Mar 2006 05:43:35 +0000 Subject: Add AbstractAdapter#table_alias_for to create table aliases according to the rules of the current adapter. [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3916 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../connection_adapters/abstract/schema_statements.rb | 14 ++++++++++++++ .../lib/active_record/connection_adapters/db2_adapter.rb | 4 ++++ .../active_record/connection_adapters/oracle_adapter.rb | 3 +++ .../connection_adapters/postgresql_adapter.rb | 3 +++ .../active_record/connection_adapters/sybase_adapter.rb | 4 ++++ 5 files changed, 28 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 76967c0fe0..d0b8a1ba1c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -8,6 +8,20 @@ module ActiveRecord {} end + # This is the maximum length a table alias can be + def table_alias_length + 255 + end + + # Truncates a table alias according to the limits of the current adapter. + def table_alias_for(table_name, index = 1) + if index > 1 + "#{table_name[0..table_alias_length-3]}_#{index}" + else + table_name[0..table_alias_length-1] + end + end + # def tables(name = nil) end # Returns an array of indexes for the given table. diff --git a/activerecord/lib/active_record/connection_adapters/db2_adapter.rb b/activerecord/lib/active_record/connection_adapters/db2_adapter.rb index 06c13c39ad..9819c5a92a 100644 --- a/activerecord/lib/active_record/connection_adapters/db2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/db2_adapter.rb @@ -188,6 +188,10 @@ begin def reconnect! end + def table_alias_length + 128 + end + private def with_statement diff --git a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb index 3291fac455..c34b3596df 100644 --- a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb @@ -191,6 +191,9 @@ begin } end + def table_alias_length + 30 + end # QUOTING ================================================== # diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 354df9a42e..53f47b2ad6 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -101,6 +101,9 @@ module ActiveRecord true end + def table_alias_length + 63 + end # QUOTING ================================================== diff --git a/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb b/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb index 67d1c368eb..75a0b4ed18 100644 --- a/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sybase_adapter.rb @@ -150,6 +150,10 @@ module ActiveRecord # connect! # Not yet implemented end + def table_alias_length + 30 + end + # Check for a limit statement and parse out the limit and # offset if specified. Remove the limit from the sql statement # and call select. -- cgit v1.2.3