Skip to content

Wrong SQL created if a table shares its name with the database #3

@adamors

Description

@adamors

If I have a database called students and inside that database I have a table also called students then

private def view_definition(name)
  execute("SHOW CREATE VIEW #{quote_table_name(name)}")
    .first[1]
    .sub(/\A.*#{quote_table_name(name)} AS /i, '')
    .gsub(/#{quote_table_name(@connectable.connection.current_database)}\./, '')
  end

will replace the name of the table, leading to errors such as Mysql2::Error: Column 'id' in field list is ambiguous.

It should replace only the very first match, not all of them.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions