Skip to content

Commit efe6c68

Browse files
committed
INFILE: add examples to the doc
1 parent 216b5a2 commit efe6c68

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ For this feature you need direct access to the package. Therefore you must chang
149149
import "github.com/go-sql-driver/mysql"
150150
```
151151

152-
Files must be whitelisted by registering them with `mysql.RegisterLocalFile(filepath)` (recommended) or the Whitelist check must be deactivated by using the DSN parameter `allowAllFiles=true` (might be insecure).
152+
Files must be whitelisted by registering them with `mysql.RegisterLocalFile(filepath)` (recommended) or the Whitelist check must be deactivated by using the DSN parameter `allowAllFiles=true` ([*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)).
153153

154154
To use a `io.Reader` a handler function must be registered with `mysql.RegisterReaderHandler(name, handler)` which returns a `io.Reader` or `io.ReadCloser`. The Reader is available with the filepath `Reader::<name>` then.
155155

156-
See also the [godoc of Go-MySQL-Driver](http://godoc.org/github.com/go-sql-driver/mysql "golang mysql driver documentation")
156+
See the [godoc of Go-MySQL-Driver](http://godoc.org/github.com/go-sql-driver/mysql "golang mysql driver documentation") for details.
157157

158158

159159
### `time.Time` support

infile.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,37 @@ func init() {
3131
// so that it can be used by "LOAD DATA LOCAL INFILE <filepath>".
3232
// Alternatively you can allow the use of all local files with
3333
// the DSN parameter 'allowAllFiles=true'
34-
func RegisterLocalFile(filepath string) {
35-
fileRegister[strings.Trim(filepath, `"`)] = true
34+
//
35+
// filePath := "/home/gopher/data.csv"
36+
// mysql.RegisterLocalFile(filePath)
37+
// err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo")
38+
// if err != nil {
39+
// ...
40+
//
41+
func RegisterLocalFile(filePath string) {
42+
fileRegister[strings.Trim(filePath, `"`)] = true
3643
}
3744

3845
// DeregisterLocalFile removes the given filepath from the whitelist.
39-
func DeregisterLocalFile(filepath string) {
40-
delete(fileRegister, strings.Trim(filepath, `"`))
46+
func DeregisterLocalFile(filePath string) {
47+
delete(fileRegister, strings.Trim(filePath, `"`))
4148
}
4249

4350
// RegisterReaderHandler registers a handler function which is used
4451
// to receive a io.Reader.
4552
// The Reader can be used by "LOAD DATA LOCAL INFILE Reader::<name>".
4653
// If the handler returns a io.ReadCloser Close() is called when the
4754
// request is finished.
55+
//
56+
// mysql.RegisterReaderHandler("data", func() io.Reader {
57+
// var csvReader io.Reader // Some Reader that returns CSV data
58+
// ... // Open Reader here
59+
// return csvReader
60+
// })
61+
// err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo")
62+
// if err != nil {
63+
// ...
64+
//
4865
func RegisterReaderHandler(name string, handler func() io.Reader) {
4966
readerRegister[name] = handler
5067
}

0 commit comments

Comments
 (0)