Skip to content

Commit 8422072

Browse files
committed
Remove savepoint IDs entirely
Turns out that Postgres allows nested savepoints with the same name
1 parent 6a69646 commit 8422072

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,12 @@ impl PostgresConnection {
323323
})
324324
}
325325
326+
326327
pub fn in_transaction<T>(&self, blk: &fn(&PostgresTransaction) -> T) -> T {
327328
self.quick_query("BEGIN");
328329
329330
let trans = PostgresTransaction {
330331
conn: self,
331-
savepoint_id: 0,
332332
commit: Cell::new(true)
333333
};
334334
// If this fails, Postgres will rollback when the connection closes
@@ -379,7 +379,6 @@ impl PostgresConnection {
379379
380380
pub struct PostgresTransaction<'self> {
381381
priv conn: &'self PostgresConnection,
382-
priv savepoint_id: uint,
383382
priv commit: Cell<bool>
384383
}
385384
@@ -406,22 +405,19 @@ impl<'self> PostgresTransaction<'self> {
406405
}
407406
408407
pub fn in_transaction<T>(&self, blk: &fn(&PostgresTransaction) -> T) -> T {
409-
let savepoint = fmt!("savepoint_%u", self.savepoint_id);
410-
411-
self.conn.quick_query(fmt!("SAVEPOINT %s", savepoint));
408+
self.conn.quick_query("SAVEPOINT sp");
412409
413410
let nested_trans = PostgresTransaction {
414411
conn: self.conn,
415-
savepoint_id: self.savepoint_id + 1,
416412
commit: Cell::new(true)
417413
};
418414
419415
let ret = blk(&nested_trans);
420416
421417
if nested_trans.commit.take() {
422-
self.conn.quick_query(fmt!("RELEASE %s", savepoint));
418+
self.conn.quick_query("RELEASE sp");
423419
} else {
424-
self.conn.quick_query(fmt!("ROLLBACK TO %s", savepoint));
420+
self.conn.quick_query("ROLLBACK TO sp");
425421
}
426422
427423
ret

0 commit comments

Comments
 (0)