Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
bcb976c5
Commit
bcb976c5
authored
Jan 26, 2012
by
Blake Mizerany
Committed by
Brad Fitzpatrick
Jan 26, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
database/sql: fix Tx.Query
Fixes #2784 R=golang-dev, bradfitz CC=golang-dev
https://golang.org/cl/5574073
parent
5c04272f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
sql.go
src/pkg/database/sql/sql.go
+5
-2
sql_test.go
src/pkg/database/sql/sql_test.go
+34
-0
No files found.
src/pkg/database/sql/sql.go
View file @
bcb976c5
...
...
@@ -556,8 +556,11 @@ func (tx *Tx) Query(query string, args ...interface{}) (*Rows, error) {
if
err
!=
nil
{
return
nil
,
err
}
defer
stmt
.
Close
()
return
stmt
.
Query
(
args
...
)
rows
,
err
:=
stmt
.
Query
(
args
...
)
if
err
==
nil
{
rows
.
closeStmt
=
stmt
}
return
rows
,
err
}
// QueryRow executes a query that is expected to return at most one row.
...
...
src/pkg/database/sql/sql_test.go
View file @
bcb976c5
...
...
@@ -311,6 +311,40 @@ func TestTxStmt(t *testing.T) {
}
}
// Issue: http://golang.org/issue/2784
// This test didn't fail before because we got luckly with the fakedb driver.
// It was failing, and now not, in github.com/bradfitz/go-sql-test
func
TestTxQuery
(
t
*
testing
.
T
)
{
db
:=
newTestDB
(
t
,
""
)
defer
closeDB
(
t
,
db
)
exec
(
t
,
db
,
"CREATE|t1|name=string,age=int32,dead=bool"
)
exec
(
t
,
db
,
"INSERT|t1|name=Alice"
)
tx
,
err
:=
db
.
Begin
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
tx
.
Rollback
()
r
,
err
:=
tx
.
Query
(
"SELECT|t1|name|"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
r
.
Next
()
{
if
r
.
Err
()
!=
nil
{
t
.
Fatal
(
r
.
Err
())
}
t
.
Fatal
(
"expected one row"
)
}
var
x
string
err
=
r
.
Scan
(
&
x
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
// Tests fix for issue 2542, that we release a lock when querying on
// a closed connection.
func
TestIssue2542Deadlock
(
t
*
testing
.
T
)
{
...
...
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