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

Function parse_set_command

nodedb/src/control/server/pgwire/session/params.rs:40–82  ·  view source on GitHub ↗

Parse a SET command: `SET [SESSION|LOCAL] key = value` or `SET key TO value`. Returns (key, value) on success, or None if not a valid SET command.

(sql: &str)

Source from the content-addressed store, hash-verified

38///
39/// Returns (key, value) on success, or None if not a valid SET command.
40pub fn parse_set_command(sql: &str) -> Option<(String, String)> {
41 let trimmed = sql.trim();
42 let upper = trimmed.to_uppercase();
43
44 // Strip SET prefix.
45 let rest = if upper.starts_with("SET SESSION ") {
46 &trimmed[12..]
47 } else if upper.starts_with("SET LOCAL ") {
48 &trimmed[10..]
49 } else if upper.starts_with("SET ") {
50 &trimmed[4..]
51 } else {
52 return None;
53 };
54
55 let rest = rest.trim();
56
57 // Split on = or TO.
58 let (key, value) = if let Some(eq_pos) = rest.find('=') {
59 let k = rest[..eq_pos].trim();
60 let v = rest[eq_pos + 1..].trim();
61 (k, v)
62 } else {
63 // Try TO separator.
64 let upper_rest = rest.to_uppercase();
65 if let Some(to_pos) = upper_rest.find(" TO ") {
66 let k = rest[..to_pos].trim();
67 let v = rest[to_pos + 4..].trim();
68 (k, v)
69 } else {
70 return None;
71 }
72 };
73
74 if key.is_empty() {
75 return None;
76 }
77
78 // Strip quotes from value.
79 let value = value.trim_matches('\'').trim_matches('"').to_string();
80
81 Some((key.to_lowercase(), value))
82}
83
84/// Known PostgreSQL runtime parameters that `SHOW <name>` is allowed to
85/// resolve through the session-parameter fallback.

Callers 5

parse_set_equalsFunction · 0.70
parse_set_toFunction · 0.70
parse_set_sessionFunction · 0.70
parse_set_nodedb_tenantFunction · 0.70
handle_setMethod · 0.50

Calls 3

to_stringMethod · 0.80
findMethod · 0.45
is_emptyMethod · 0.45

Tested by 4

parse_set_equalsFunction · 0.56
parse_set_toFunction · 0.56
parse_set_sessionFunction · 0.56
parse_set_nodedb_tenantFunction · 0.56