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

Function handle_set_sql

nodedb/src/control/server/native/dispatch/sql.rs:303–332  ·  view source on GitHub ↗
(ctx: &DispatchCtx<'_>, seq: u64, sql: &str)

Source from the content-addressed store, hash-verified

301// ─── SET / SHOW / RESET (SQL form) ─────────────────────────────────
302
303fn handle_set_sql(ctx: &DispatchCtx<'_>, seq: u64, sql: &str) -> NativeResponse {
304 let after_set = sql[4..].trim();
305 let after_set = after_set
306 .strip_prefix("SESSION ")
307 .or_else(|| after_set.strip_prefix("LOCAL "))
308 .unwrap_or(after_set);
309
310 let (key, value) = if let Some(eq_pos) = after_set.find('=') {
311 (
312 after_set[..eq_pos].trim().to_lowercase(),
313 after_set[eq_pos + 1..]
314 .trim()
315 .trim_matches('\'')
316 .to_string(),
317 )
318 } else if let Some(to_pos) = after_set.to_uppercase().find(" TO ") {
319 (
320 after_set[..to_pos].trim().to_lowercase(),
321 after_set[to_pos + 4..]
322 .trim()
323 .trim_matches('\'')
324 .to_string(),
325 )
326 } else {
327 return NativeResponse::error(seq, "42601", "invalid SET syntax");
328 };
329
330 ctx.sessions.set_parameter(ctx.peer_addr, key, value);
331 NativeResponse::status_row(seq, "SET")
332}
333
334fn is_session_show(upper: &str) -> bool {
335 !upper.starts_with("SHOW USERS")

Callers 1

handle_sqlFunction · 0.85

Calls 3

to_stringMethod · 0.80
findMethod · 0.45
set_parameterMethod · 0.45

Tested by

no test coverage detected