pub struct TransactionManager { /* private fields */ }Expand description
Manages the state of database transactions in a thread-safe manner.
This struct wraps the TransactionState in an Arc<Mutex<>> to allow it to be
shared across different parts of the application, such as between the REPL and
other command handlers, while preventing race conditions.
Implementations§
Source§impl TransactionManager
impl TransactionManager
Sourcepub fn begin_transaction(&self, conn: &Connection) -> Result<()>
pub fn begin_transaction(&self, conn: &Connection) -> Result<()>
Begins a new database transaction.
If a transaction is already active, it prints a warning and does nothing.
Otherwise, it executes a BEGIN statement and sets the state to Active.
§Arguments
conn- A reference to therusqlite::Connection.
Sourcepub fn commit_transaction(&self, conn: &Connection) -> Result<()>
pub fn commit_transaction(&self, conn: &Connection) -> Result<()>
Commits the active database transaction.
If no transaction is active, it prints a message and does nothing.
Otherwise, it executes a COMMIT statement and resets the state to None.
§Arguments
conn- A reference to therusqlite::Connection.
Sourcepub fn rollback_transaction(&self, conn: &Connection) -> Result<()>
pub fn rollback_transaction(&self, conn: &Connection) -> Result<()>
Rolls back the active database transaction.
If no transaction is active, it prints a message and does nothing.
Otherwise, it executes a ROLLBACK statement and resets the state to None.
§Arguments
conn- A reference to therusqlite::Connection.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Checks if a transaction is currently active.
§Returns
true if the transaction state is Active, false otherwise.
Sourcepub fn show_status(&self)
pub fn show_status(&self)
Prints the current transaction status to the console.
Sourcepub fn handle_sql_command(&self, conn: &Connection, sql: &str) -> Result<bool>
pub fn handle_sql_command(&self, conn: &Connection, sql: &str) -> Result<bool>
Intercepts and handles transaction-related SQL commands.
This method checks if the input SQL string matches known transaction control
statements (BEGIN, COMMIT, ROLLBACK) or a DROP command. If a match is found,
it calls the appropriate TransactionManager method and returns Ok(true).
For DROP, it adds extra validation.
If the command is not a recognized transaction command, it returns Ok(false),
indicating that the command should be executed as a standard SQL query.
§Arguments
conn- A reference to therusqlite::Connection.sql- The SQL command string to be processed.
§Returns
A Result<bool> which is Ok(true) if the command was handled, or Ok(false) if not.