'How to make sure the query run with read-only action on MySQL/PostgreSQL database?

Precondition: The database is running at somewhere without of my control, but I have the authorization account to connect the database.

I need to make sure all queries running through my application connection to database should be read-only. Such as SELECT in DML.

Using regex to judge the SQL query? Is there any reusable Function/Class in SQLAlchemy or other Python packages?

Any suggestion will be helpful! Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source