Validate a raw identifier token extracted from SQL. If `raw_name` is surrounded by double-quotes (standard SQL quoting), the quotes are stripped and the inner text is returned unchanged as `Ok(inner)` — the user has opted in to the reserved word. Otherwise, the token is normalised to upper case and compared against [`RESERVED_KEYWORDS`]. A match returns `Err(SqlError::ReservedIdentifier { .. })`
(raw_name: &str)
| 55 | /// * A clean identifier is returned as `Ok(name.to_lowercase())` to match |
| 56 | /// the existing `parse_col_token` behaviour. |
| 57 | pub fn check_identifier(raw_name: &str) -> Result<String, SqlError> { |
| 58 | if raw_name.starts_with('"') && raw_name.ends_with('"') && raw_name.len() >= 2 { |
| 59 | // Standard SQL quoted identifier: strip the surrounding quotes. |
| 60 | return Ok(raw_name[1..raw_name.len() - 1].to_string()); |
| 61 | } |
| 62 | |
| 63 | let upper = raw_name.to_uppercase(); |
| 64 | if RESERVED_KEYWORDS.contains(&upper.as_str()) { |
| 65 | let reason = reason_for(&upper); |
| 66 | return Err(SqlError::ReservedIdentifier { |
| 67 | name: raw_name.to_string(), |
| 68 | reason, |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | Ok(raw_name.to_lowercase()) |
| 73 | } |
| 74 | |
| 75 | #[cfg(test)] |
| 76 | mod tests { |