MCPcopy Create free account
hub / github.com/erans/pgsqlite / execute_with_session

Method execute_with_session

src/session/db_handler.rs:1988–2143  ·  view source on GitHub ↗

Execute with session-specific connection

(&self, query: &str, session_id: &Uuid)

Source from the content-addressed store, hash-verified

1986
1987 /// Execute with session-specific connection
1988 pub async fn execute_with_session(&self, query: &str, session_id: &Uuid) -> Result<DbResponse, PgSqliteError> {
1989 // Validate SQL security first
1990 self.validate_sql_security(query)?;
1991 // Handle COMMENT DDL statements (need mutable connection)
1992 if CommentDdlHandler::is_comment_ddl(query) {
1993 return self.connection_manager.execute_with_session_mut(session_id, |conn| {
1994 match CommentDdlHandler::handle_comment_ddl(conn, query) {
1995 Ok(()) => Ok(DbResponse {
1996 columns: vec![],
1997 rows: vec![],
1998 rows_affected: 0,
1999 }),
2000 Err(PgSqliteError::Sqlite(e)) => Err(e),
2001 Err(PgSqliteError::Protocol(msg)) => Err(rusqlite::Error::SqliteFailure(
2002 rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_ERROR),
2003 Some(msg)
2004 )),
2005 Err(_) => Err(rusqlite::Error::SqliteFailure(
2006 rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_ERROR),
2007 Some("Comment operation failed".to_string())
2008 )),
2009 }
2010 });
2011 }
2012
2013 self.connection_manager.execute_with_session(session_id, |conn| {
2014 // Check if this is a CREATE TABLE statement that needs special handling
2015 let (processed_query, type_mappings, _array_columns, _enum_columns) =
2016 if query.trim_start().to_uppercase().starts_with("CREATE TABLE") {
2017 debug!("Processing CREATE TABLE statement with translation...");
2018 // Use CREATE TABLE translator with full metadata capture
2019 use crate::translator::CreateTableTranslator;
2020 match CreateTableTranslator::translate_with_connection_full(query, Some(conn)) {
2021 Ok(result) => {
2022 debug!("CREATE TABLE translated with {} type mappings and {} array columns",
2023 result.type_mappings.len(), result.array_columns.len());
2024 (result.sql, result.type_mappings, result.array_columns, result.enum_columns)
2025 }
2026 Err(e) => {
2027 return Err(rusqlite::Error::SqliteFailure(
2028 rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_ERROR),
2029 Some(format!("CREATE TABLE translation failed: {}", e))
2030 ));
2031 }
2032 }
2033 } else {
2034 // Process query with fast path optimization for non-CREATE TABLE statements
2035 let processed = process_query(query, conn, &self.schema_cache)?;
2036 (processed, std::collections::HashMap::new(), Vec::new(), Vec::new())
2037 };
2038
2039 let rows_affected = conn.execute(&processed_query, [])?;
2040
2041 // Handle CREATE TABLE metadata storage and constraints
2042 if query.trim_start().to_uppercase().starts_with("CREATE TABLE")
2043 && let Some(table_name) = extract_table_name_from_create(query) {
2044
2045 // Store type mappings in schema metadata table

Callers 15

execute_with_paramsMethod · 0.45
query_with_sessionMethod · 0.45
executeMethod · 0.45
begin_with_sessionMethod · 0.45
commitMethod · 0.45
rollbackMethod · 0.45
handle_catalog_queryMethod · 0.45

Calls 8

validate_sql_securityMethod · 0.80
process_queryFunction · 0.50
executeMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45