Commit c3df08aa authored by gwenn's avatar gwenn

Add savepoint helper methods.

parent 80bbe1d9
......@@ -443,6 +443,21 @@ func (c *Conn) Rollback() error {
return c.exec("ROLLBACK")
}
// (See http://sqlite.org/lang_savepoint.html)
func (c *Conn) Savepoint(name string) error {
return c.exec(Mprintf("SAVEPOINT %Q", name))
}
// (See http://sqlite.org/lang_savepoint.html)
func (c *Conn) ReleaseSavepoint(name string) error {
return c.exec(Mprintf("RELEASE %Q", name))
}
// (See http://sqlite.org/lang_savepoint.html)
func (c *Conn) RollbackSavepoint(name string) error {
return c.exec(Mprintf("ROLLBACK TO SAVEPOINT %Q", name))
}
func (c *Conn) exec(cmd string) error {
s, err := c.prepare(cmd)
if err != nil {
......
......@@ -76,6 +76,15 @@ func TestTransaction(t *testing.T) {
checkNoError(t, db.Commit(), "Error while commiting transaction: %s")
}
func TestSavepoint(t *testing.T) {
db := open(t)
defer db.Close()
checkNoError(t, db.Savepoint("1"), "Error while creating savepoint: %s")
checkNoError(t, db.Savepoint("2"), "Error while creating savepoint: %s")
checkNoError(t, db.RollbackSavepoint("2"), "Error while creating savepoint: %s")
checkNoError(t, db.ReleaseSavepoint("1"), "Error while creating savepoint: %s")
}
func TestExists(t *testing.T) {
db := open(t)
defer db.Close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment