Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
go
Commits
4435c8bf
Commit
4435c8bf
authored
Jan 10, 2012
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/sql: close Rows on EOF
Fixes #2624 R=rsc CC=golang-dev
https://golang.org/cl/5530068
parent
25cf9bde
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
11 deletions
+31
-11
src/pkg/exp/sql/fakedb_test.go
src/pkg/exp/sql/fakedb_test.go
+17
-8
src/pkg/exp/sql/sql.go
src/pkg/exp/sql/sql.go
+5
-2
src/pkg/exp/sql/sql_test.go
src/pkg/exp/sql/sql_test.go
+9
-1
No files found.
src/pkg/exp/sql/fakedb_test.go
View file @
4435c8bf
...
...
@@ -110,25 +110,34 @@ func init() {
// Supports dsn forms:
// <dbname>
// <dbname>;
wipe
// <dbname>;
<opts> (no currently supported options)
func
(
d
*
fakeDriver
)
Open
(
dsn
string
)
(
driver
.
Conn
,
error
)
{
d
.
mu
.
Lock
()
defer
d
.
mu
.
Unlock
()
d
.
openCount
++
if
d
.
dbs
==
nil
{
d
.
dbs
=
make
(
map
[
string
]
*
fakeDB
)
}
parts
:=
strings
.
Split
(
dsn
,
";"
)
if
len
(
parts
)
<
1
{
return
nil
,
errors
.
New
(
"fakedb: no database name"
)
}
name
:=
parts
[
0
]
db
:=
d
.
getDB
(
name
)
d
.
mu
.
Lock
()
d
.
openCount
++
d
.
mu
.
Unlock
()
return
&
fakeConn
{
db
:
db
},
nil
}
func
(
d
*
fakeDriver
)
getDB
(
name
string
)
*
fakeDB
{
d
.
mu
.
Lock
()
defer
d
.
mu
.
Unlock
()
if
d
.
dbs
==
nil
{
d
.
dbs
=
make
(
map
[
string
]
*
fakeDB
)
}
db
,
ok
:=
d
.
dbs
[
name
]
if
!
ok
{
db
=
&
fakeDB
{
name
:
name
}
d
.
dbs
[
name
]
=
db
}
return
&
fakeConn
{
db
:
db
},
nil
return
db
}
func
(
db
*
fakeDB
)
wipe
()
{
...
...
src/pkg/exp/sql/sql.go
View file @
4435c8bf
...
...
@@ -549,8 +549,8 @@ func (s *Stmt) Exec(args ...interface{}) (Result, error) {
// statement, a function to call to release the connection, and a
// statement bound to that connection.
func
(
s
*
Stmt
)
connStmt
()
(
ci
driver
.
Conn
,
releaseConn
func
(),
si
driver
.
Stmt
,
err
error
)
{
if
s
.
stickyE
rr
!=
nil
{
return
nil
,
nil
,
nil
,
s
.
stickyErr
if
err
=
s
.
stickyErr
;
e
rr
!=
nil
{
return
}
s
.
mu
.
Lock
()
if
s
.
closed
{
...
...
@@ -726,6 +726,9 @@ func (rs *Rows) Next() bool {
rs
.
lastcols
=
make
([]
interface
{},
len
(
rs
.
rowsi
.
Columns
()))
}
rs
.
lasterr
=
rs
.
rowsi
.
Next
(
rs
.
lastcols
)
if
rs
.
lasterr
==
io
.
EOF
{
rs
.
Close
()
}
return
rs
.
lasterr
==
nil
}
...
...
src/pkg/exp/sql/sql_test.go
View file @
4435c8bf
...
...
@@ -10,8 +10,10 @@ import (
"testing"
)
const
fakeDBName
=
"foo"
func
newTestDB
(
t
*
testing
.
T
,
name
string
)
*
DB
{
db
,
err
:=
Open
(
"test"
,
"foo"
)
db
,
err
:=
Open
(
"test"
,
fakeDBName
)
if
err
!=
nil
{
t
.
Fatalf
(
"Open: %v"
,
err
)
}
...
...
@@ -73,6 +75,12 @@ func TestQuery(t *testing.T) {
if
!
reflect
.
DeepEqual
(
got
,
want
)
{
t
.
Logf
(
" got: %#v
\n
want: %#v"
,
got
,
want
)
}
// And verify that the final rows.Next() call, which hit EOF,
// also closed the rows connection.
if
n
:=
len
(
db
.
freeConn
);
n
!=
1
{
t
.
Errorf
(
"free conns after query hitting EOF = %d; want 1"
,
n
)
}
}
func
TestRowsColumns
(
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