Skip to content

Table/Column alias maximum length in schema_statements #1

@mikewoodhouse

Description

@mikewoodhouse

I just came across an obscure little bug in AR - I ran something like this:

SomeModel.count(:group => 'foofoofoofoo, barbarbarbar, bazbazbazbaz')

which generates a (unnecessary) column alias longer than the 30 characters allowed by Oracle:

SELECT 1 AS foofoofoofoo_barbarbarbar_bazbazbazbaz FROM dual;
ORA-00972: identifier is too long

This seems to have been addressed to some extent between AR2.1.2 (where I'm stuck at present) and 2.3.4, which has

module ActiveRecord
module ConnectionAdapters # :nodoc:
module SchemaStatements
# Returns a Hash of mappings from the abstract data types to the native
# database types. See TableDefinition#column for details on the recognized
# abstract data types.
def native_database_types
{}
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)
    table_name[0..table_alias_length-1].gsub(/\./, '_')
  end

For Oracle, we need table_alias_length to return 30.

Not that I can actually use it, of course (I had to hack calculations.rb, grrr) but it would be nice to see it in the adapter if I ever get to update...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions