Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/eclipse/paho.mqtt.golang v1.5.1
github.com/fatih/color v1.15.0
github.com/foxcpp/go-mockdns v0.0.0-20201212160233-ede2f9158d15
github.com/go-sql-driver/mysql v1.5.0
github.com/go-sql-driver/mysql v1.9.3
github.com/gofrs/uuid v3.3.0+incompatible
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec
github.com/google/flatbuffers v25.9.23+incompatible
Expand Down Expand Up @@ -62,6 +62,7 @@ require (
cloud.google.com/go/iam v1.2.2 // indirect
cloud.google.com/go/longrunning v0.6.2 // indirect
cloud.google.com/go/monitoring v1.21.2 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
cloud.google.com/go/storage v1.43.0 h1:CcxnSohZwizt4LCzQHWvBf1/kvtHUn7gk9QERXPyXFs=
cloud.google.com/go/storage v1.43.0/go.mod h1:ajvxEa7WmZS1PxvKRq4bq0tFT3vMd502JwstCcYv0Q0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/99designs/keyring v1.2.2 h1:pZd3neh/EmUzWONb35LxQfvuY7kiSXAq3HQd97+XBn0=
Expand Down Expand Up @@ -197,8 +199,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo=
github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
Expand Down
24 changes: 24 additions & 0 deletions stdlib/sql/from_private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,30 @@ func TestMssqlOpenFunctionDialer(t *testing.T) {
}
}

func TestMysqlOpenFunctionDialer(t *testing.T) {
expectErr := errors.New("test dial error")
deps := mockDeps{
Deps: flux.NewDefaultDependencies(),
dialer: &mockDialer{err: expectErr},
}

openFn := mysqlOpenFunction("username:password@tcp(localhost:3306)/dbname")
db, err := openFn(deps)
if err != nil {
t.Fatalf("unexpected error from open function: %v", err)
}
defer db.Close()

// Ping triggers a real connection attempt, which will use our mock dialer.
err = db.Ping()
if err == nil {
t.Fatal("expected error from Ping, got nil")
}
if !errors.Is(err, expectErr) {
t.Fatalf("expected error %q, got: %v", expectErr, err)
}
}

func TestFromSqliteUrlValidation(t *testing.T) {
testCases := executetest.SourceUrlValidationTestCases{
{
Expand Down
20 changes: 20 additions & 0 deletions stdlib/sql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/go-sql-driver/mysql"
"github.com/influxdata/flux"
"github.com/influxdata/flux/codes"
"github.com/influxdata/flux/execute"
Expand Down Expand Up @@ -197,3 +198,22 @@ func MysqlColumnTranslateFunc() translationFunc {
func mysqlQuoteIdent(name string) string {
return fmt.Sprintf("`%s`", strings.ReplaceAll(name, "`", "``"))
}

func mysqlOpenFunction(dataSourceName string) openFunc {
return func(deps flux.Dependencies) (*sql.DB, error) {
cfg, err := mysql.ParseDSN(dataSourceName)
if err != nil {
return nil, err
}
dialer, err := deps.Dialer()
if err != nil {
return nil, err
}
cfg.DialFunc = dialer.DialContext
connector, err := mysql.NewConnector(cfg)
if err != nil {
return nil, err
}
return sql.OpenDB(connector), nil
}
}
2 changes: 2 additions & 0 deletions stdlib/sql/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func getOpenFunc(driverName, dataSourceName string) openFunc {
switch driverName {
case "mssql", "sqlserver":
return mssqlOpenFunction(dataSourceName)
case "mysql":
return mysqlOpenFunction(dataSourceName)
case "postgres":
return postgresOpenFunction(dataSourceName)
default:
Expand Down
Loading