Skip to content

Commit a6d2009

Browse files
mamcxcloutiertyler
authored andcommitted
Fix incomplete transaction bug (#21)
* Fix incomplete transaction bug * Clippy
1 parent c2a5113 commit a6d2009

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

crates/core/src/host/module_host.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl DatabaseUpdate {
3434

3535
pub fn from_writes(stdb: &RelationalDB, writes: &Vec<Write>) -> Self {
3636
let mut map: HashMap<u32, Vec<TableOp>> = HashMap::new();
37+
//TODO: This should be wrapped with .auto_commit
3738
let tx = stdb.begin_tx();
3839
for write in writes {
3940
let op = match write.operation {

crates/core/src/sql/ast.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,17 @@ fn compile_where(table: &From, filter: Option<SqlExpr>) -> Result<Option<Selecti
389389
}
390390

391391
fn find_table(db: &RelationalDB, t: Table) -> Result<TableSchema, PlanError> {
392-
let tx = db.begin_tx();
393-
let table_id = db
394-
.table_id_from_name(&tx, &t.name)?
395-
.ok_or(PlanError::UnknownTable { table: t.name.clone() })?;
396-
if !db.inner.table_id_exists(&tx, &TableId(table_id)) {
397-
return Err(PlanError::UnknownTable { table: t.name });
398-
}
399-
let schema = db
400-
.schema_for_table(&tx, table_id)
401-
.map_err(|e| PlanError::DatabaseInternal(Box::new(e)));
402-
db.rollback_tx(tx);
403-
schema
392+
//TODO: We should thread the `tx` from a upper layer instead...
393+
db.with_auto_commit(|tx| {
394+
let table_id = db
395+
.table_id_from_name(tx, &t.name)?
396+
.ok_or(PlanError::UnknownTable { table: t.name.clone() })?;
397+
if !db.inner.table_id_exists(tx, &TableId(table_id)) {
398+
return Err(PlanError::UnknownTable { table: t.name });
399+
}
400+
db.schema_for_table(tx, table_id)
401+
.map_err(|e| PlanError::DatabaseInternal(Box::new(e)))
402+
})
404403
}
405404

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

0 commit comments

Comments
 (0)