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

Function extract_when_condition

nodedb-sql/src/ddl_ast/parse/trigger.rs:254–293  ·  view source on GitHub ↗
(
    header_upper: &str,
    header_original: &str,
    tokens_upper: &[String],
    i: &mut usize,
)

Source from the content-addressed store, hash-verified

252}
253
254fn extract_when_condition(
255 header_upper: &str,
256 header_original: &str,
257 tokens_upper: &[String],
258 i: &mut usize,
259) -> Option<String> {
260 if *i >= tokens_upper.len() || tokens_upper[*i] != "WHEN" {
261 return None;
262 }
263 *i += 1;
264
265 let when_pos = header_upper.find("WHEN")?;
266 let after_when = header_original[when_pos + 4..].trim_start();
267 if !after_when.starts_with('(') {
268 return None;
269 }
270 let mut depth = 0i32;
271 let mut end = 0usize;
272 for (j, ch) in after_when.char_indices() {
273 match ch {
274 '(' => depth += 1,
275 ')' => {
276 depth -= 1;
277 if depth == 0 {
278 end = j;
279 break;
280 }
281 }
282 _ => {}
283 }
284 }
285 if depth != 0 {
286 return None;
287 }
288 let condition = after_when[1..end].trim().to_string();
289 while *i < tokens_upper.len() && tokens_upper[*i] != "PRIORITY" {
290 *i += 1;
291 }
292 Some(condition)
293}
294
295fn parse_priority_token(tokens_orig: &[&str], tokens_upper: &[String], i: &mut usize) -> i32 {
296 if *i >= tokens_upper.len() || tokens_upper[*i] != "PRIORITY" {

Callers 1

parse_create_triggerFunction · 0.85

Calls 3

to_stringMethod · 0.80
lenMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected