MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / check_identifier

Function check_identifier

nodedb-sql/src/reserved.rs:57–73  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

55/// * A clean identifier is returned as `Ok(name.to_lowercase())` to match
56/// the existing `parse_col_token` behaviour.
57pub 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)]
76mod tests {

Callers 3

bare_reserved_is_errFunction · 0.85
parse_col_tokenFunction · 0.85

Calls 5

reason_forFunction · 0.85
to_stringMethod · 0.80
lenMethod · 0.45
containsMethod · 0.45
as_strMethod · 0.45

Tested by 1

bare_reserved_is_errFunction · 0.68