Skip to content

Commit 03f3101

Browse files
author
Kenneth Shaw
committed
Adding oracle test and making adodb provider URLs a bit friendlier
1 parent 38dcf1f commit 03f3101

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

dburl_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,20 @@ func TestParse(t *testing.T) {
7878
{`mssql://user@localhost/service/dbname`, `mssql`, `Database=dbname;Server=localhost\service;User ID=user`},
7979
{`mssql://user:!234%23$@localhost:1580/dbname`, `mssql`, `Database=dbname;Password=!234#$;Port=1580;Server=localhost;User ID=user`},
8080

81-
{`adodb://Microsoft.ACE.OLEDB.12.0?Extended+Properties=%22Text%3BHDR%3DNO%3BFMT%3DDelimited%22`, `adodb`,
82-
`Data Source=.;Extended Properties="Text;HDR=NO;FMT=Delimited";Provider=Microsoft.ACE.OLEDB.12.0`}, // 30
83-
{`adodb://user:[email protected]:1542/dbname`, `adodb`, `Database=dbname;Password=pass;Port=1542;Provider=Provider.Name;User ID=user`},
84-
81+
{`adodb://Microsoft.ACE.OLEDB.12.0?Extended+Properties=%22Text%3BHDR%3DNO%3BFMT%3DDelimited%22`, `adodb`, // 30
82+
`Data Source=.;Extended Properties="Text;HDR=NO;FMT=Delimited";Provider=Microsoft.ACE.OLEDB.12.0`},
83+
{`adodb://user:[email protected]:1542/Oracle8i/dbname`, `adodb`,
84+
`Data Source=Oracle8i;Database=dbname;Password=pass;Port=1542;Provider=Provider.Name;User ID=user`},
8585
{`oo+Postgres+Unicode://user:pass@host:5432/dbname`, `adodb`,
86-
`Provider=MSDASQL.1;Extended Properties="Database=dbname;Driver={Postgres Unicode};PWD=pass;Port=5432;Server=host;UID=user"`}, // 31
86+
`Provider=MSDASQL.1;Extended Properties="Database=dbname;Driver={Postgres Unicode};PWD=pass;Port=5432;Server=host;UID=user"`},
8787

8888
{`file:/path/to/file.sqlite3`, `sqlite3`, `/path/to/file.sqlite3`}, // 33
8989
{`sqlite:///path/to/file.sqlite3`, `sqlite3`, `/path/to/file.sqlite3`},
9090
{`sq://path/to/file.sqlite3`, `sqlite3`, `path/to/file.sqlite3`},
9191
{`sq:path/to/file.sqlite3`, `sqlite3`, `path/to/file.sqlite3`},
9292
{`sq:./path/to/file.sqlite3`, `sqlite3`, `./path/to/file.sqlite3`},
93+
94+
{`oracle://user:pass@localhost/xe.oracle.docker`, `ora`, `user/pass@localhost/xe.oracle.docker`}, // 38
9395
}
9496

9597
for i, test := range tests {

dsn.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,22 @@ func GenADODB(u *URL) (string, error) {
335335
q.Set("Port", u.Port())
336336

337337
// grab dbname
338-
dbname := strings.TrimPrefix(u.Path, "/")
339-
if dbname == "" {
340-
dbname = "."
338+
dsname, dbname := strings.TrimPrefix(u.Path, "/"), ""
339+
if dsname == "" {
340+
dsname = "."
341341
}
342342

343-
if dbname == "." {
344-
q.Set("Data Source", dbname)
345-
} else {
346-
q.Set("Database", dbname)
343+
// check if data source is not a path on disk
344+
if mode(dsname) == 0 {
345+
if i := strings.IndexAny(dsname, `\/`); i != -1 {
346+
dbname = dsname[i+1:]
347+
dsname = dsname[:i]
348+
}
347349
}
348350

351+
q.Set("Data Source", dsname)
352+
q.Set("Database", dbname)
353+
349354
// add user/pass
350355
if u.User != nil {
351356
q.Set("User ID", u.User.Username())

0 commit comments

Comments
 (0)