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

Statement Cache Does Not Work Correctly With Switching Databases #359

Open
winstonewert opened this issue Sep 27, 2023 · 2 comments
Open

Comments

@winstonewert
Copy link

I have a case where I need to run the exact same query against a number of different databases within one MySQL instance. I did this by running "use database_name" follow by my actual query in a loop. Sadly, I just get the results from the first query back over and over. It looks like this is because the statement is cached after the first query and then reused. Using the select_db function does not solve the problem. I was able to solve it by manually preparing and closing my statement.

@blackbeam
Copy link
Owner

Hi. I believe the statement is bound to the database at the server side. I believe the only reasonable thing we can do is to add a note in the docs.

I was able to solve it by manually preparing and closing my statement.

Another option is to invoke Conn::reset after use another_db is executed.

@winstonewert
Copy link
Author

Perhaps select_db could reset the statement cache? You could also possibly identify "USE" statements and clear the cache if they are detected? I'm not sure either of those is worthwhile.

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

No branches or pull requests

2 participants