"s1" is too common.
Also omit ``savepoint`` in sql statements: it is a noise word
# inner transaction: it always has a name
self._outer_transaction = False
self._savepoint_name = (
- savepoint_name or f"s{len(self._conn._savepoints) + 1}"
+ savepoint_name or f"_pg3_{len(self._conn._savepoints) + 1}"
)
@property
commands = []
if self._savepoint_name and not self._outer_transaction:
commands.append(
- sql.SQL("release savepoint {}")
+ sql.SQL("release {}")
.format(sql.Identifier(self._savepoint_name))
.as_string(self._conn)
)
commands = []
if self._savepoint_name and not self._outer_transaction:
commands.append(
- sql.SQL("rollback to savepoint {n}; release savepoint {n}")
+ sql.SQL("rollback to {n}; release {n}")
.format(n=sql.Identifier(self._savepoint_name))
.as_string(self._conn)
)
conn.cursor().execute("select 1")
assert commands.popall() == ["begin"]
with conn.transaction() as tx:
- assert commands.popall() == ['savepoint "s1"']
- assert tx.savepoint_name == "s1"
- assert commands.popall() == ['release savepoint "s1"']
+ assert commands.popall() == ['savepoint "_pg3_1"']
+ assert tx.savepoint_name == "_pg3_1"
+ assert commands.popall() == ['release "_pg3_1"']
conn.rollback()
assert commands.popall() == ["rollback"]
with conn.transaction(savepoint_name="bar") as tx:
assert commands.popall() == ['savepoint "bar"']
assert tx.savepoint_name == "bar"
- assert commands.popall() == ['release savepoint "bar"']
+ assert commands.popall() == ['release "bar"']
assert commands.popall() == ["commit"]
# Case 3 (with savepoint name auto-generated)
with conn.transaction():
assert commands.popall() == ["begin"]
with conn.transaction() as tx:
- assert commands.popall() == ['savepoint "s2"']
- assert tx.savepoint_name == "s2"
- assert commands.popall() == ['release savepoint "s2"']
+ assert commands.popall() == ['savepoint "_pg3_2"']
+ assert tx.savepoint_name == "_pg3_2"
+ assert commands.popall() == ['release "_pg3_2"']
assert commands.popall() == ["commit"]
assert commands.popall() == ['savepoint "bar"']
assert tx.savepoint_name == "bar"
raise ExpectedException
- assert commands.popall() == [
- 'rollback to savepoint "bar"; release savepoint "bar"'
- ]
+ assert commands.popall() == ['rollback to "bar"; release "bar"']
assert commands.popall() == ["commit"]
# Case 3 (with savepoint name auto-generated)
assert commands.popall() == ["begin"]
with pytest.raises(ExpectedException):
with conn.transaction() as tx:
- assert commands.popall() == ['savepoint "s2"']
- assert tx.savepoint_name == "s2"
+ assert commands.popall() == ['savepoint "_pg3_2"']
+ assert tx.savepoint_name == "_pg3_2"
raise ExpectedException
- assert commands.popall() == [
- 'rollback to savepoint "s2"; release savepoint "s2"'
- ]
+ assert commands.popall() == ['rollback to "_pg3_2"; release "_pg3_2"']
assert commands.popall() == ["commit"]
await (await aconn.cursor()).execute("select 1")
assert commands.popall() == ["begin"]
async with aconn.transaction() as tx:
- assert commands.popall() == ['savepoint "s1"']
- assert tx.savepoint_name == "s1"
+ assert commands.popall() == ['savepoint "_pg3_1"']
+ assert tx.savepoint_name == "_pg3_1"
- assert commands.popall() == ['release savepoint "s1"']
+ assert commands.popall() == ['release "_pg3_1"']
await aconn.rollback()
assert commands.popall() == ["rollback"]
async with aconn.transaction(savepoint_name="bar") as tx:
assert commands.popall() == ['savepoint "bar"']
assert tx.savepoint_name == "bar"
- assert commands.popall() == ['release savepoint "bar"']
+ assert commands.popall() == ['release "bar"']
assert commands.popall() == ["commit"]
# Case 3 (with savepoint name auto-generated)
async with aconn.transaction():
assert commands.popall() == ["begin"]
async with aconn.transaction() as tx:
- assert commands.popall() == ['savepoint "s2"']
- assert tx.savepoint_name == "s2"
- assert commands.popall() == ['release savepoint "s2"']
+ assert commands.popall() == ['savepoint "_pg3_2"']
+ assert tx.savepoint_name == "_pg3_2"
+ assert commands.popall() == ['release "_pg3_2"']
assert commands.popall() == ["commit"]
assert commands.popall() == ['savepoint "bar"']
assert tx.savepoint_name == "bar"
raise ExpectedException
- assert commands.popall() == [
- 'rollback to savepoint "bar"; release savepoint "bar"'
- ]
+ assert commands.popall() == ['rollback to "bar"; release "bar"']
assert commands.popall() == ["commit"]
# Case 3 (with savepoint name auto-generated)
assert commands.popall() == ["begin"]
with pytest.raises(ExpectedException):
async with aconn.transaction() as tx:
- assert commands.popall() == ['savepoint "s2"']
- assert tx.savepoint_name == "s2"
+ assert commands.popall() == ['savepoint "_pg3_2"']
+ assert tx.savepoint_name == "_pg3_2"
raise ExpectedException
- assert commands.popall() == [
- 'rollback to savepoint "s2"; release savepoint "s2"'
- ]
+ assert commands.popall() == ['rollback to "_pg3_2"; release "_pg3_2"']
assert commands.popall() == ["commit"]