Check if a SQL query is read-only
(sql: &str)
| 163 | |
| 164 | /// Check if a SQL query is read-only |
| 165 | fn is_read_only_query(sql: &str) -> bool { |
| 166 | let sql_upper = sql.trim().to_uppercase(); |
| 167 | |
| 168 | // Allow only SELECT statements and certain pragmas |
| 169 | sql_upper.starts_with("SELECT") |
| 170 | || sql_upper.starts_with("WITH") // CTEs |
| 171 | || sql_upper.starts_with("EXPLAIN") |
| 172 | || sql_upper.starts_with("PRAGMA TABLE_INFO") |
| 173 | || sql_upper.starts_with("PRAGMA INDEX_LIST") |
| 174 | || sql_upper.starts_with("PRAGMA FOREIGN_KEY_LIST") |
| 175 | // Add other read-only pragmas as needed |
| 176 | } |
| 177 | |
| 178 | |
| 179 | #[cfg(test)] |
no outgoing calls
no test coverage detected