From d794b300d846d624285ed5596ea92c32ad288700 Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Wed, 16 Aug 2023 09:37:33 +0700 Subject: [PATCH] Fixing issue with azuresql DSNs --- dburl.go | 4 ---- dburl_test.go | 8 ++++---- scheme.go | 52 --------------------------------------------------- 3 files changed, 4 insertions(+), 60 deletions(-) diff --git a/dburl.go b/dburl.go index 75cc708..69962b2 100644 --- a/dburl.go +++ b/dburl.go @@ -131,10 +131,6 @@ func Parse(urlstr string) (*URL, error) { if u.DSN, err = scheme.Generator(u); err != nil { return nil, err } - // fix actual driver - if scheme.Actual != nil { - u.Driver = scheme.Actual(u) - } return u, nil } diff --git a/dburl_test.go b/dburl_test.go index 7b121c2..71bc249 100644 --- a/dburl_test.go +++ b/dburl_test.go @@ -124,10 +124,10 @@ func TestParse(t *testing.T) { {`mssql://user:pass@localhost/dbname`, `sqlserver`, `sqlserver://user:pass@localhost/?database=dbname`, ``}, {`mssql://user@localhost/service/dbname`, `sqlserver`, `sqlserver://user@localhost/service?database=dbname`, ``}, {`mssql://user:!234%23$@localhost:1580/dbname`, `sqlserver`, `sqlserver://user:%21234%23$@localhost:1580/?database=dbname`, ``}, - {`mssql://user:!234%23$@localhost:1580/service/dbname?fedauth=true`, `azuresql`, `azuresql://user:%21234%23$@localhost:1580/service?database=dbname&fedauth=true`, ``}, - {`azuresql://user:pass@localhost:100/dbname`, `azuresql`, `azuresql://user:pass@localhost:100/?database=dbname`, ``}, - {`sqlserver://xxx.database.windows.net?database=xxx&fedauth=ActiveDirectoryMSI`, `azuresql`, `azuresql://xxx.database.windows.net?database=xxx&fedauth=ActiveDirectoryMSI`, ``}, - {`azuresql://xxx.database.windows.net/dbname?fedauth=ActiveDirectoryMSI`, `azuresql`, `azuresql://xxx.database.windows.net/?database=dbname&fedauth=ActiveDirectoryMSI`, ``}, + {`mssql://user:!234%23$@localhost:1580/service/dbname?fedauth=true`, `sqlserver`, `azuresql://user:%21234%23$@localhost:1580/service?database=dbname&fedauth=true`, ``}, + {`azuresql://user:pass@localhost:100/dbname`, `sqlserver`, `azuresql://user:pass@localhost:100/?database=dbname`, ``}, + {`sqlserver://xxx.database.windows.net?database=xxx&fedauth=ActiveDirectoryMSI`, `sqlserver`, `azuresql://xxx.database.windows.net?database=xxx&fedauth=ActiveDirectoryMSI`, ``}, + {`azuresql://xxx.database.windows.net/dbname?fedauth=ActiveDirectoryMSI`, `sqlserver`, `azuresql://xxx.database.windows.net/?database=dbname&fedauth=ActiveDirectoryMSI`, ``}, { `adodb://Microsoft.ACE.OLEDB.12.0?Extended+Properties=%22Text%3BHDR%3DNO%3BFMT%3DDelimited%22`, `adodb`, // 30 `Data Source=.;Extended Properties="Text;HDR=NO;FMT=Delimited";Provider=Microsoft.ACE.OLEDB.12.0`, ``, diff --git a/scheme.go b/scheme.go index 8cd8df9..a1d0b7c 100644 --- a/scheme.go +++ b/scheme.go @@ -43,11 +43,6 @@ type Scheme struct { // // Used for "wire compatible" driver schemes. Override string - // Actual is a func that can be used to inspect the URL that changes the - // actual Driver name returned. Used for drivers that have registered - // multiple driver names using a single package import (ie, Microsoft's SQL - // Server driver). - Actual func(*URL) string } // BaseSchemes returns the supported base schemes. @@ -60,35 +55,30 @@ func BaseSchemes() []Scheme { false, []string{"mariadb", "maria", "percona", "aurora"}, "", - nil, }, { "oracle", GenFromURL("oracle://localhost:1521"), 0, false, []string{"ora", "oci", "oci8", "odpi", "odpi-c"}, "", - nil, }, { "postgres", GenPostgres, TransportUnix, false, []string{"pg", "postgresql", "pgsql"}, "", - nil, }, { "sqlite3", GenOpaque, 0, true, []string{"sqlite", "file"}, "", - nil, }, { "sqlserver", GenSqlserver, 0, false, []string{"ms", "mssql", "azuresql"}, "", - sqlserverDriver, }, // wire compatibles { @@ -96,31 +86,26 @@ func BaseSchemes() []Scheme { GenFromURL("postgres://localhost:26257/?sslmode=disable"), 0, false, []string{"cr", "cockroach", "crdb", "cdb"}, "postgres", - nil, }, { "memsql", GenMysql, 0, false, nil, "mysql", - nil, }, { "redshift", GenFromURL("postgres://localhost:5439/"), 0, false, []string{"rs"}, "postgres", - nil, }, { "tidb", GenMysql, 0, false, nil, "mysql", - nil, }, { "vitess", GenMysql, 0, false, []string{"vt"}, "mysql", - nil, }, // alternate implementations { @@ -128,28 +113,24 @@ func BaseSchemes() []Scheme { GenGodror, 0, false, []string{"gr"}, "", - nil, }, { "moderncsqlite", GenOpaque, 0, true, []string{"mq", "modernsqlite"}, "", - nil, }, { "mymysql", GenMymysql, TransportTCP | TransportUDP | TransportUnix, false, []string{"zm", "mymy"}, "", - nil, }, { "pgx", GenFromURL("postgres://localhost:5432/"), TransportUnix, false, []string{"px"}, "", - nil, }, // other databases { @@ -157,214 +138,182 @@ func BaseSchemes() []Scheme { GenAdodb, 0, false, []string{"ado"}, "", - nil, }, { "awsathena", GenScheme("s3"), 0, false, []string{"s3", "aws", "athena"}, "", - nil, }, { "avatica", GenFromURL("http://localhost:8765/"), 0, false, []string{"phoenix"}, "", - nil, }, { "bigquery", GenScheme("bigquery"), 0, false, []string{"bq"}, "", - nil, }, { "clickhouse", GenFromURL("clickhouse://localhost:9000/"), 0, false, []string{"ch"}, "", - nil, }, { "cosmos", GenCosmos, 0, false, []string{"cm"}, "", - nil, }, { "cql", GenCassandra, 0, false, []string{"ca", "cassandra", "datastax", "scy", "scylla"}, "", - nil, }, { "csvq", GenOpaque, 0, true, []string{"csv", "tsv", "json"}, "", - nil, }, { "databend", GenDatabend, 0, false, []string{"dd", "bend"}, "", - nil, }, { "exasol", GenExasol, 0, false, []string{"ex", "exa"}, "", - nil, }, { "firebirdsql", GenFirebird, 0, false, []string{"fb", "firebird"}, "", - nil, }, { "flightsql", GenScheme("flightsql"), 0, false, []string{"fl", "flight"}, "", - nil, }, { "genji", GenOpaque, 0, true, []string{"gj"}, "", - nil, }, { "h2", GenFromURL("h2://localhost:9092/"), 0, false, nil, "", - nil, }, { "hdb", GenScheme("hdb"), 0, false, []string{"sa", "saphana", "sap", "hana"}, "", - nil, }, { "hive", GenSchemeTruncate, 0, false, nil, "", - nil, }, { "ignite", GenIgnite, 0, false, []string{"ig", "gridgain"}, "", - nil, }, { "impala", GenScheme("impala"), 0, false, nil, "", - nil, }, { "maxcompute", GenSchemeTruncate, 0, false, []string{"mc"}, "", - nil, }, { "n1ql", GenFromURL("http://localhost:9000/"), 0, false, []string{"couchbase"}, "", - nil, }, { "nzgo", GenPostgres, TransportUnix, false, []string{"nz", "netezza"}, "", - nil, }, { "odbc", GenOdbc, TransportAny, false, nil, "", - nil, }, { "oleodbc", GenOleodbc, TransportAny, false, []string{"oo", "ole"}, "adodb", - nil, }, { "ots", GenTableStore, TransportAny, false, []string{"tablestore"}, "", - nil, }, { "presto", GenPresto, 0, false, []string{"prestodb", "prestos", "prs", "prestodbs"}, "", - nil, }, { "ql", GenOpaque, 0, true, []string{"ql", "cznic", "cznicql"}, "", - nil, }, { "snowflake", GenSnowflake, 0, false, []string{"sf"}, "", - nil, }, { "spanner", GenSpanner, 0, false, []string{"sp"}, "", - nil, }, { "tds", GenFromURL("http://localhost:5000/"), 0, false, []string{"ax", "ase", "sapase"}, "", - nil, }, { "trino", GenPresto, 0, false, []string{"trino", "trinos", "trs"}, "", - nil, }, { "vertica", GenFromURL("vertica://localhost:5433/"), 0, false, nil, "", - nil, }, { "voltdb", GenVoltdb, 0, false, []string{"volt", "vdb"}, "", - nil, }, } } @@ -426,7 +375,6 @@ func Register(scheme Scheme) { Transport: scheme.Transport, Opaque: scheme.Opaque, Override: scheme.Override, - Actual: scheme.Actual, } schemeMap[scheme.Driver] = sz // add aliases