Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
57cd7e0d
Commit
57cd7e0d
authored
Jun 10, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attempt to fix Transaction.
parent
1febd6dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
18 deletions
+22
-18
sqlite.go
sqlite.go
+18
-12
sqlite_test.go
sqlite_test.go
+4
-6
No files found.
sqlite.go
View file @
57cd7e0d
...
...
@@ -446,36 +446,42 @@ func (c *Conn) Rollback() error {
// If the transaction occurs within another transaction (only one that is started using this method) a Savepoint is created.
// Two errors may be returned: the first is the one returned by the f function,
// the second is the one returned by begin/commit/rollback.
func
(
c
*
Conn
)
Transaction
(
t
TransactionType
,
f
func
(
c
*
Conn
)
error
)
(
gerr
error
,
serr
error
)
{
// (See http://sqlite.org/tclsqlite.html#transaction)
func
(
c
*
Conn
)
Transaction
(
t
TransactionType
,
f
func
(
c
*
Conn
)
error
)
(
err
error
)
{
if
c
.
nTransaction
==
0
{
s
err
=
c
.
BeginTransaction
(
t
)
err
=
c
.
BeginTransaction
(
t
)
}
else
{
s
err
=
c
.
Savepoint
(
strconv
.
Itoa
(
int
(
c
.
nTransaction
)))
err
=
c
.
Savepoint
(
strconv
.
Itoa
(
int
(
c
.
nTransaction
)))
}
if
s
err
!=
nil
{
if
err
!=
nil
{
return
}
c
.
nTransaction
++
defer
func
()
{
c
.
nTransaction
--
if
gerr
!=
nil
{
if
c
.
nTransaction
==
0
{
serr
=
c
.
Rollback
()
if
err
!=
nil
{
_
,
ko
:=
err
.
(
*
ConnError
)
if
c
.
nTransaction
==
0
||
ko
{
c
.
Rollback
()
}
else
{
serr
=
c
.
RollbackSavepoint
(
strconv
.
Itoa
(
int
(
c
.
nTransaction
)))
if
rerr
:=
c
.
RollbackSavepoint
(
strconv
.
Itoa
(
int
(
c
.
nTransaction
)));
rerr
!=
nil
{
Log
(
-
1
,
rerr
.
Error
())
}
else
if
rerr
:=
c
.
ReleaseSavepoint
(
strconv
.
Itoa
(
int
(
c
.
nTransaction
)));
rerr
!=
nil
{
Log
(
-
1
,
rerr
.
Error
())
}
}
}
else
{
if
c
.
nTransaction
==
0
{
s
err
=
c
.
Commit
()
err
=
c
.
Commit
()
}
else
{
s
err
=
c
.
ReleaseSavepoint
(
strconv
.
Itoa
(
int
(
c
.
nTransaction
)))
err
=
c
.
ReleaseSavepoint
(
strconv
.
Itoa
(
int
(
c
.
nTransaction
)))
}
if
s
err
!=
nil
{
if
err
!=
nil
{
c
.
Rollback
()
}
}
}()
g
err
=
f
(
c
)
err
=
f
(
c
)
return
}
...
...
sqlite_test.go
View file @
57cd7e0d
...
...
@@ -249,16 +249,14 @@ func TestTransaction(t *testing.T) {
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
createTable
(
db
,
t
)
gerr
,
s
err
:=
db
.
Transaction
(
Immediate
,
func
(
_
*
Conn
)
error
{
err
,
nerr
:=
db
.
Transaction
(
Immediate
,
func
(
__
*
Conn
)
error
{
err
:=
db
.
Transaction
(
Immediate
,
func
(
_
*
Conn
)
error
{
err
:=
db
.
Transaction
(
Immediate
,
func
(
__
*
Conn
)
error
{
return
db
.
Exec
(
"INSERT INTO test VALUES (?, ?, ?, ?)"
,
0
,
273.1
,
1
,
"test"
)
})
checkNoError
(
t
,
err
,
"Applicative error: %s"
)
checkNoError
(
t
,
nerr
,
"SQLite error: %s"
)
checkNoError
(
t
,
err
,
"error: %s"
)
return
err
})
checkNoError
(
t
,
gerr
,
"Applicative error: %s"
)
checkNoError
(
t
,
serr
,
"SQLite error: %s"
)
checkNoError
(
t
,
err
,
"error: %s"
)
}
func
assertEquals
(
t
*
testing
.
T
,
format
string
,
expected
,
actual
interface
{})
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment