You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docker-entrypoint-initdb.d of mysql docker already supports delimiter, but go-sql-driver still does not support this syntax, resulting in failure to create sql functions,If delimiter is not supported, how can I create a sql function correctly
For the test of go-sql-driver, please see the following code
package main
import (
"database/sql""fmt"
_ "github.com/go-sql-driver/mysql"
)
funcmain() {
db, err:=sql.Open("mysql", "root:1234@tcp(127.0.0.1:3309)/fruit?charset=utf8&parseTime=True&loc=UTC")
iferr!=nil {
panic(err)
}
sql:=`CREATE FUNCTION hello1 (s CHAR(20))RETURNS CHAR(50) DETERMINISTICRETURN CONCAT('Hello1, ',s,'!');`rows, err:=db.Exec(sql)
iferr!=nil {
panic(err)
}
fmt.Println("hello1 success", rows) //successsql=`DROP FUNCTION IF EXISTS hello2;DELIMITER $$CREATE FUNCTION hello2(labelIds varchar(500)) RETURNS varchar(1000)BEGIN RETURN CONCAT('Hello, ',s,'!');END $$DELIMITER ;`rows, err=db.Exec(sql)
iferr!=nil { //failureerr=fmt.Errorf("hello2 failure,%v", err)
panic(err)
}
fmt.Println(rows)
}
Error log
PS D:\source\gopath\src\test-sql-driver-function> go run .
hello1 success {0xc0000aa100 0xc00001e240}
panic: hello2 failure,Error 1064: You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$CREATE FUNCTION hello2(labelIds varchar(500))RETURNS varchar(1000' at line 3
goroutine 1 [running]:
main.main()
D:/source/gopath/src/test-sql-driver-function/main.go:40 +0x2d1
exit status 2
Issue description
docker-entrypoint-initdb.d of
mysql docker
already supportsdelimiter
, butgo-sql-driver
still does not support this syntax, resulting in failure to create sql functions,If delimiter is not supported, how can I create a sql function correctlyExample code
About docker-entrypoint-initdb.d test, please click the link to view
https://github.com/relax-space/test-sql-driver-function.git
For the test of go-sql-driver, please see the following code
Error log
Configuration
Driver version (or git SHA): 14bb9c0 (HEAD -> master) Add go.mod (#1003)
Go version: go version go1.13.8 windows/amd64
Server version: MySQL 5.7.22
Server OS: Windows 10
The text was updated successfully, but these errors were encountered: