Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 41296a0

Browse files
committed
Added some items suggested by Arne and an issue commenter
1 parent 0e9ffec commit 41296a0

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

Diff for: surprises.md

+40
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,44 @@ example, comparing MySQL, PostgreSQL, and Oracle:
7171
WHERE col = ? WHERE col = $1 WHERE col = :col
7272
VALUES(?, ?, ?) VALUES($1, $2, $3) VALUES(:val1, :val2, :val3)
7373

74+
Multiple Result Sets
75+
====================
76+
77+
The Go driver doesn't support multiple result sets from a single query in any
78+
way, and there doesn't seem to be any plan to do that, although there is [a
79+
feature request](https://code.google.com/p/go/issues/detail?id=5171) for
80+
supporting bulk operations such as bulk copy.
81+
82+
This means, among other things, that a stored procedure that returns multiple
83+
result sets will not work correctly.
84+
85+
Invoking Stored Procedures
86+
==========================
87+
88+
Invoking stored procedures is driver-specific, but in the MySQL driver it can't
89+
be done at present. It might seem that you'd be able to call a simple
90+
procedure that returns a single result set, by executing something like this:
91+
92+
err := db.QueryRow("CALL mydb.myprocedure").Scan(&result)
93+
94+
In fact, this won't work. You'll get the following error: _Error
95+
1312: PROCEDURE mydb.myprocedure can't return a result set in the given
96+
context_. This is because MySQL expects the connection to be set into
97+
multi-statement mode, even for a single result, and the driver doesn't currently
98+
do that.
99+
100+
Multiple Statement Support
101+
==========================
102+
103+
The `database/sql` doesn't offer multiple-statement support. That means you
104+
can't do something like the following:
105+
106+
_, err := db.Exec("DELETE FROM tbl1; DELETE FROM tbl2")
107+
108+
Similarly, there is no way to batch statements in a transaction. Each statement
109+
in a transaction must be executed serially, and the resources that it holds
110+
(such as a Result or Rows) must be closed so the underlying connection is free
111+
for another statement to use. This means that each statement in a transaction
112+
results in a separate set of network round-trips to the database.
113+
74114
{% include toc.md %}

Diff for: test.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"database/sql"
6+
"log"
7+
_ "github.com/VividCortex/mysql"
8+
)
9+
10+
func main() {
11+
db, _ := sql.Open("mysql", "root@tcp(127.0.0.1:12830)/customers?charset=utf8")
12+
var res string
13+
err := db.QueryRow("call template.foo").Scan(&res)
14+
if err != nil {
15+
log.Fatal(err)
16+
}
17+
fmt.Println(res)
18+
}

0 commit comments

Comments
 (0)