Checks if the given SQL query string is read-only. Returns True if the query is read-only, False otherwise.
(sql_query: str)
| 69 | ) |
| 70 | |
| 71 | def is_read_only_query(sql_query: str) -> bool: |
| 72 | """ |
| 73 | Checks if the given SQL query string is read-only. |
| 74 | Returns True if the query is read-only, False otherwise. |
| 75 | """ |
| 76 | # List of SQL statements that modify data in the database |
| 77 | modifying_statements = ["INSERT", "UPDATE", "DELETE", "DROP", "CREATE", "ALTER", "GRANT", "TRUNCATE", "LOCK TABLES", "UNLOCK TABLES"] |
| 78 | |
| 79 | # Check if the query contains any modifying statements |
| 80 | for statement in modifying_statements: |
| 81 | if statement in sql_query.upper(): |
| 82 | return False |
| 83 | |
| 84 | # If no modifying statements are found, the query is read-only |
| 85 | return True |
| 86 | |
| 87 | |
| 88 | class NotReadOnlyException(Exception): |