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
f7e223db
Commit
f7e223db
authored
Dec 31, 2017
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement RowsNextResultSet
parent
7a9d5708
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
1 deletion
+94
-1
driver.go
driver.go
+31
-1
driver_test.go
driver_test.go
+63
-0
No files found.
driver.go
View file @
f7e223db
...
...
@@ -316,7 +316,37 @@ func (r *rowsImpl) Close() error {
return
r
.
s
.
s
.
Reset
()
}
// TODO HasNextResultSet && Stmt.tail ?
func
(
r
*
rowsImpl
)
HasNextResultSet
()
bool
{
return
len
(
r
.
s
.
s
.
tail
)
>
0
}
func
(
r
*
rowsImpl
)
NextResultSet
()
error
{
currentStmt
:=
r
.
s
.
s
nextQuery
:=
currentStmt
.
tail
var
nextStmt
*
Stmt
var
err
error
for
len
(
nextQuery
)
>
0
{
nextStmt
,
err
=
currentStmt
.
c
.
Prepare
(
nextQuery
)
if
err
!=
nil
{
return
err
}
else
if
nextStmt
.
stmt
==
nil
{
// this happens for a comment or white-space
nextQuery
=
nextStmt
.
tail
continue
}
break
}
if
nextStmt
==
nil
{
return
io
.
EOF
}
// TODO close vs reset ?
err
=
currentStmt
.
Finalize
()
if
err
!=
nil
{
return
err
}
r
.
s
.
s
=
nextStmt
return
nil
}
func
(
r
*
rowsImpl
)
ColumnTypeScanType
(
index
int
)
reflect
.
Type
{
switch
r
.
s
.
s
.
ColumnType
(
index
)
{
...
...
driver_test.go
View file @
f7e223db
...
...
@@ -514,3 +514,66 @@ func TestNilAndEmptyBytes(t *testing.T) {
checkSqlRowsClose
(
rows
,
t
)
}
}
func
TestMultipleResultSets
(
t
*
testing
.
T
)
{
db
:=
sqlOpen
(
t
)
defer
checkSqlDbClose
(
db
,
t
)
rows
,
err
:=
db
.
Query
(
"SELECT 1; SELECT 2; SELECT 3"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
rows
.
Close
()
var
i
int
for
rows
.
Next
()
{
if
err
:=
rows
.
Scan
(
&
i
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
i
!=
1
{
t
.
Fatalf
(
"expected 1, got %d"
,
i
)
}
}
if
!
rows
.
NextResultSet
()
{
t
.
Fatal
(
"expected more result sets"
,
rows
.
Err
())
}
for
rows
.
Next
()
{
if
err
:=
rows
.
Scan
(
&
i
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
i
!=
2
{
t
.
Fatalf
(
"expected 2, got %d"
,
i
)
}
}
// Make sure that if we ignore a result we can still query.
rows
,
err
=
db
.
Query
(
"select 4; select 5"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
rows
.
Close
()
for
rows
.
Next
()
{
if
err
:=
rows
.
Scan
(
&
i
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
i
!=
4
{
t
.
Fatalf
(
"expected 4, got %d"
,
i
)
}
}
if
!
rows
.
NextResultSet
()
{
t
.
Fatal
(
"expected more result sets"
,
rows
.
Err
())
}
for
rows
.
Next
()
{
if
err
:=
rows
.
Scan
(
&
i
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
i
!=
5
{
t
.
Fatalf
(
"expected 5, got %d"
,
i
)
}
}
if
rows
.
NextResultSet
()
{
t
.
Fatal
(
"unexpected result set"
)
}
}
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