Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adamors opened this issue Apr 3, 2018 · 3 comments
Open

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

adamors opened this issue Apr 3, 2018 · 3 comments

Comments

@adamors
Copy link

adamors commented Apr 3, 2018

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.

@cainlevy
Copy link
Contributor

cainlevy commented Apr 3, 2018

Ah! Yep. I'll circle back to this when I'm available if someone hasn't already taken care of it.

@adamors
Copy link
Author

adamors commented Apr 3, 2018

I've added a small PR, please let me know if I should add anything else.

@adamors
Copy link
Author

adamors commented Apr 3, 2018

BTW this behaviour of adding the database name as a prefix is not consistent, because it's a bug: https://bugs.mysql.com/bug.php?id=85176. Fixed here: https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-3.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants