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

Function second_sql_word

nodedb-sql/src/parser/preprocess/lex.rs:191–218  ·  view source on GitHub ↗

Return the second SQL keyword/word in `sql`, skipping leading whitespace, line comments, and block comments, then skipping the first word. Returns `None` if there is no second word. The returned slice is a sub-slice of `sql` in its original case.

(sql: &str)

Source from the content-addressed store, hash-verified

189///
190/// The returned slice is a sub-slice of `sql` in its original case.
191pub fn second_sql_word(sql: &str) -> Option<&str> {
192 let mut found_first = false;
193 for seg in segments(sql) {
194 if let SqlSegment::Text(t) = seg {
195 let mut remaining = t;
196 loop {
197 let trimmed = remaining.trim_start();
198 if trimmed.is_empty() {
199 break;
200 }
201 let end = trimmed
202 .find(|c: char| c.is_ascii_whitespace() || c == '(' || c == ';')
203 .unwrap_or(trimmed.len());
204 if end == 0 {
205 break;
206 }
207 if !found_first {
208 found_first = true;
209 // advance past this word
210 remaining = &trimmed[end..];
211 } else {
212 return Some(&trimmed[..end]);
213 }
214 }
215 }
216 }
217 None
218}
219
220/// Return `true` if `op` appears verbatim inside any `Text` segment of `sql`.
221/// The comparison is byte-exact (case-sensitive). Occurrences inside string

Callers 1

parseFunction · 0.85

Calls 4

segmentsFunction · 0.85
is_emptyMethod · 0.45
findMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected