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

Method execute

src/session/db_handler.rs:1750–1932  ·  view source on GitHub ↗

Execute without session (compatibility - creates temporary connection)

(&self, query: &str)

Source from the content-addressed store, hash-verified

1748
1749 /// Execute without session (compatibility - creates temporary connection)
1750 pub async fn execute(&self, query: &str) -> Result<DbResponse, rusqlite::Error> {
1751 // For compatibility with tests, use shared connection if available
1752 // Check if it's any form of memory database (including named shared memory)
1753 debug!("DbHandler::execute - db_path: {}, query: {}", self.db_path, query);
1754 if self.db_path == ":memory:" || self.db_path.contains("mode=memory") {
1755 // For memory databases, we need to use a session connection
1756 // Create a temporary session for backward compatibility
1757 let temp_session = Uuid::new_v4();
1758 if let Err(e) = self.create_session_connection(temp_session).await {
1759 return Err(rusqlite::Error::SqliteFailure(
1760 rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_ERROR),
1761 Some(format!("Failed to create temporary session: {e}"))
1762 ));
1763 }
1764
1765 let result = self.execute_with_session(query, &temp_session).await
1766 .map_err(|e| match e {
1767 PgSqliteError::Sqlite(sqlite_err) => sqlite_err,
1768 other => rusqlite::Error::SqliteFailure(
1769 rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_ERROR),
1770 Some(format!("Execution error: {other}"))
1771 )
1772 })?;
1773
1774 self.remove_session_connection(&temp_session);
1775 Ok(result)
1776 } else {
1777 let mut conn = Self::create_initial_connection(&self.db_path, &Config::load())?;
1778
1779 // Register functions on the temporary connection
1780 crate::functions::register_all_functions(&conn)?;
1781
1782 // Handle COMMENT DDL statements
1783 if CommentDdlHandler::is_comment_ddl(query) {
1784 return match CommentDdlHandler::handle_comment_ddl(&mut conn, query) {
1785 Ok(()) => Ok(DbResponse {
1786 columns: vec![],
1787 rows: vec![],
1788 rows_affected: 0,
1789 }),
1790 Err(PgSqliteError::Sqlite(e)) => Err(e),
1791 Err(PgSqliteError::Protocol(msg)) => Err(rusqlite::Error::SqliteFailure(
1792 rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_ERROR),
1793 Some(msg)
1794 )),
1795 Err(_) => Err(rusqlite::Error::SqliteFailure(
1796 rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_ERROR),
1797 Some("Comment operation failed".to_string())
1798 )),
1799 };
1800 }
1801
1802 // Check if this is a CREATE TABLE statement that needs special handling
1803 let (processed_query, type_mappings) =
1804 if query.trim_start().to_uppercase().starts_with("CREATE TABLE") {
1805 eprintln!("🔨 Processing CREATE TABLE statement in query_with_session...");
1806 // Use CREATE TABLE translator with full metadata capture
1807 use crate::translator::CreateTableTranslator;

Callers 15

test_sqlite.pyFile · 0.45
execute_cachedMethod · 0.45
test_lazy_schema_loadingFunction · 0.45
test_preloadingFunction · 0.45
test_schema_loadingFunction · 0.45
test_query_executionFunction · 0.45
execute_with_paramsMethod · 0.45

Calls 9

register_all_functionsFunction · 0.85
process_queryFunction · 0.50
execute_with_sessionMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by 15

test_lazy_schema_loadingFunction · 0.36
test_preloadingFunction · 0.36
test_schema_loadingFunction · 0.36
test_query_executionFunction · 0.36
test_uuid_functionsFunction · 0.36
test_json_agg_functionsFunction · 0.36
test_table_existsFunction · 0.36
test_resolve_column_oidFunction · 0.36
test_get_all_tablesFunction · 0.36