Checks if the given SQL query string is read-only. Returns True if the query is read-only, False otherwise.
(sql_query: str)
| 98 | |
| 99 | |
| 100 | def is_read_only_query(sql_query: str): |
| 101 | """ |
| 102 | Checks if the given SQL query string is read-only. |
| 103 | Returns True if the query is read-only, False otherwise. |
| 104 | """ |
| 105 | # List of SQL statements that modify data in the database |
| 106 | modifying_statements = ["INSERT", "UPDATE", "DELETE", "DROP", "CREATE", "ALTER", "GRANT", "TRUNCATE", "LOCK TABLES", "UNLOCK TABLES"] |
| 107 | |
| 108 | # Check if the query contains any modifying statements |
| 109 | for statement in modifying_statements: |
| 110 | if not sql_query or statement in sql_query.upper(): |
| 111 | return False |
| 112 | |
| 113 | # If no modifying statements are found, the query is read-only |
| 114 | return True |