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

Method handle_execute

nodedb/src/control/server/pgwire/handler/sql_prepared.rs:60–100  ·  view source on GitHub ↗

Handle `EXECUTE name [(value, ...)]`. Retrieves the prepared statement, substitutes parameter values into the SQL body, and executes through the standard pipeline. Uses `Box::pin` because this creates async recursion: `execute_sql` → `handle_execute` → `execute_sql` (with the substituted body). The substituted SQL is the PREPARE body (e.g., a SELECT), not another EXECUTE, so the recursion termin

(
        &'a self,
        identity: &'a AuthenticatedIdentity,
        addr: &'a std::net::SocketAddr,
        sql: &'a str,
    )

Source from the content-addressed store, hash-verified

58 /// The substituted SQL is the PREPARE body (e.g., a SELECT), not another EXECUTE,
59 /// so the recursion terminates in one level.
60 pub(super) fn handle_execute<'a>(
61 &'a self,
62 identity: &'a AuthenticatedIdentity,
63 addr: &'a std::net::SocketAddr,
64 sql: &'a str,
65 ) -> std::pin::Pin<Box<dyn std::future::Future<Output = PgWireResult<Vec<Response>>> + Send + 'a>>
66 {
67 Box::pin(async move {
68 let (name, param_values) = parse_execute_statement(sql)?;
69
70 let stmt = self.sessions.get_sql_prepared(addr, &name).ok_or_else(|| {
71 PgWireError::UserError(Box::new(ErrorInfo::new(
72 "ERROR".to_owned(),
73 "26000".to_owned(),
74 format!("prepared statement \"{name}\" does not exist"),
75 )))
76 })?;
77
78 // Validate parameter count.
79 let expected_count = count_placeholders(&stmt.sql);
80 if !param_values.is_empty() && param_values.len() != expected_count {
81 return Err(PgWireError::UserError(Box::new(ErrorInfo::new(
82 "ERROR".to_owned(),
83 "08P01".to_owned(),
84 format!(
85 "wrong number of parameters for prepared statement \"{name}\": \
86 expected {expected_count}, got {}",
87 param_values.len()
88 ),
89 ))));
90 }
91
92 // Substitute parameters into the SQL body.
93 let final_sql = substitute_sql_params(&stmt.sql, &param_values);
94
95 // Execute through the standard pipeline. The substituted SQL is the
96 // PREPARE body (e.g., SELECT/INSERT), never another EXECUTE statement,
97 // so this does not recurse further.
98 self.execute_sql(identity, addr, &final_sql).await
99 })
100 }
101
102 /// Handle `DEALLOCATE name` or `DEALLOCATE ALL`.
103 pub(super) fn handle_deallocate(

Callers 1

execute_single_sqlMethod · 0.80

Calls 7

parse_execute_statementFunction · 0.85
substitute_sql_paramsFunction · 0.85
get_sql_preparedMethod · 0.80
count_placeholdersFunction · 0.70
is_emptyMethod · 0.45
lenMethod · 0.45
execute_sqlMethod · 0.45

Tested by

no test coverage detected