Skip to content

Commit

Permalink
Fix incomplete transaction bug (#21)
Browse files Browse the repository at this point in the history
* Fix incomplete transaction bug

* Clippy
  • Loading branch information
mamcx authored and cloutiertyler committed Aug 1, 2023
1 parent c2a5113 commit a6d2009
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions crates/core/src/host/module_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl DatabaseUpdate {

pub fn from_writes(stdb: &RelationalDB, writes: &Vec<Write>) -> Self {
let mut map: HashMap<u32, Vec<TableOp>> = HashMap::new();
//TODO: This should be wrapped with .auto_commit
let tx = stdb.begin_tx();
for write in writes {
let op = match write.operation {
Expand Down
23 changes: 11 additions & 12 deletions crates/core/src/sql/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,17 @@ fn compile_where(table: &From, filter: Option<SqlExpr>) -> Result<Option<Selecti
}

fn find_table(db: &RelationalDB, t: Table) -> Result<TableSchema, PlanError> {
let tx = db.begin_tx();
let table_id = db
.table_id_from_name(&tx, &t.name)?
.ok_or(PlanError::UnknownTable { table: t.name.clone() })?;
if !db.inner.table_id_exists(&tx, &TableId(table_id)) {
return Err(PlanError::UnknownTable { table: t.name });
}
let schema = db
.schema_for_table(&tx, table_id)
.map_err(|e| PlanError::DatabaseInternal(Box::new(e)));
db.rollback_tx(tx);
schema
//TODO: We should thread the `tx` from a upper layer instead...
db.with_auto_commit(|tx| {
let table_id = db
.table_id_from_name(tx, &t.name)?
.ok_or(PlanError::UnknownTable { table: t.name.clone() })?;
if !db.inner.table_id_exists(tx, &TableId(table_id)) {
return Err(PlanError::UnknownTable { table: t.name });
}
db.schema_for_table(tx, table_id)
.map_err(|e| PlanError::DatabaseInternal(Box::new(e)))
})
}

fn compile_from(db: &RelationalDB, from: &[TableWithJoins]) -> Result<From, PlanError> {
Expand Down

0 comments on commit a6d2009

Please sign in to comment.