Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Transaction::transaction is not implemented correctlu #371

@rustonaut

Description

@rustonaut

Ironically this function has a bug:

pub fn transaction<'a>(&'a self) -> Result<Transaction<'a>> {
self.savepoint("sp")
}

Basically it should not reuse the savepoint name sp.

If you do something like:

BEGIN;
INSERT INTO t VALUES (1);
SAVEPOINT sp;
INSERT INTO t VALUES (2);
SAVEPOINT sp;
INSERT INTO t VALUES (3);
ROLLBACK TO sp;
ROLLBACK TO sp;
COMMIT;

then the table will contain 1 and 2!

And while you probably won't run into this in most code,
it can happen much easier if you have code generic over
GenericConnection which uses a transaction.

Possible fixes:

  1. always generate a name including the
    current depth (format!("sp{}", self.depth))
  2. only generate a name if the depth > 1
    (assuming that it starts with 0 on first trans without savepoint, 1 on second etc.)

When we are at it we might want to change savepoint
to accept <S: Into<String>> instead of &str.

I will see if I can make a pull request, but I won't
have time for it before the weekend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions