Commit 041796b7 authored by gwenn's avatar gwenn

Use sqlite3_exec for transaction commands.

parent f687a5d8
...@@ -293,7 +293,7 @@ func (c *Conn) GetAutocommit() bool { ...@@ -293,7 +293,7 @@ func (c *Conn) GetAutocommit() bool {
type TransactionType int type TransactionType int
const ( const (
DEFERRED TransactionType = 0 DEFERRED TransactionType = 0
IMMEDIATE TransactionType = 1 IMMEDIATE TransactionType = 1
EXCLUSIVE TransactionType = 2 EXCLUSIVE TransactionType = 2
) )
...@@ -304,11 +304,11 @@ func (c *Conn) Begin() os.Error { ...@@ -304,11 +304,11 @@ func (c *Conn) Begin() os.Error {
func (c *Conn) BeginTransaction(t TransactionType) os.Error { func (c *Conn) BeginTransaction(t TransactionType) os.Error {
if t == DEFERRED { if t == DEFERRED {
return c.Exec("BEGIN") return c.exec("BEGIN")
} else if t == IMMEDIATE { } else if t == IMMEDIATE {
return c.Exec("BEGIN IMMEDIATE") return c.exec("BEGIN IMMEDIATE")
} else if t == EXCLUSIVE { } else if t == EXCLUSIVE {
return c.Exec("BEGIN EXCLUSIVE") return c.exec("BEGIN EXCLUSIVE")
} }
panic(fmt.Sprintf("Unsupported transaction type: '%#v'", t)) panic(fmt.Sprintf("Unsupported transaction type: '%#v'", t))
return nil return nil
...@@ -316,11 +316,21 @@ func (c *Conn) BeginTransaction(t TransactionType) os.Error { ...@@ -316,11 +316,21 @@ func (c *Conn) BeginTransaction(t TransactionType) os.Error {
func (c *Conn) Commit() os.Error { func (c *Conn) Commit() os.Error {
// TODO Check autocommit? // TODO Check autocommit?
return c.Exec("COMMIT") return c.exec("COMMIT")
} }
func (c *Conn) Rollback() os.Error { func (c *Conn) Rollback() os.Error {
// TODO Check autocommit? // TODO Check autocommit?
return c.Exec("ROLLBACK") return c.exec("ROLLBACK")
}
func (c *Conn) exec(cmd string) os.Error {
cmdstr := C.CString(cmd)
defer C.free(unsafe.Pointer(cmdstr))
rv := C.sqlite3_exec(c.db, cmdstr, nil, nil, nil)
if rv != C.SQLITE_OK {
return c.error(rv)
}
return nil
} }
// Prepared Statement (sqlite3_stmt) // Prepared Statement (sqlite3_stmt)
......
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