Skip to content

Commit d5a8a1f

Browse files
committed
cater for sqlserver and oracle being defined in connection string (both will be ODBC driver)
1 parent 1dd5624 commit d5a8a1f

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ DDBC
33

44
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/buggins/ddbc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
55

6-
![CI](https://github.com/buggins/ddbc/workflows/CI/badge.svg)
6+
[![CI](https://github.com/buggins/ddbc/workflows/CI/badge.svg)](https://github.com/buggins/ddbc/actions?query=workflow%3ACI)
77

88
[![Build Status](https://travis-ci.org/buggins/ddbc.svg?branch=master)](https://travis-ci.org/buggins/ddbc)
99

@@ -148,9 +148,23 @@ ddbc:postgresql://127.0.0.1:5432
148148
### Microsoft SQL Server (via ODBC)
149149

150150
```
151+
ddbc:sqlserver://localhost,1433?user=sa,password=bbk4k77JKH88g54,driver=FreeTDS
152+
153+
or
154+
151155
ddbc:odbc://localhost,1433?user=sa,password=bbk4k77JKH88g54,driver=FreeTDS
152156
```
153157

158+
### Oracle (via ODBC) **experimental**
159+
160+
```
161+
ddbc:oracle://localhost:1521?user=sa,password=bbk4k77JKH88g54,driver=FreeTDS
162+
163+
or
164+
165+
ddbc:odbc://localhost:1521?user=sa,password=bbk4k77JKH88g54,driver=FreeTDS
166+
```
167+
154168
### DSN connections for Microsoft SQL Server
155169
The correct format to use for a dsn connection string is `odbc://?dsn=<DSN name>`.
156170
Note that the server portion before the `?` is empty, so the default server for

source/ddbc/common.d

+3-3
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,9 @@ string extractDriverNameFromURL(string url) {
552552
url = stripDdbcPrefix(url);
553553
import std.string;
554554
int colonPos = cast(int)url.indexOf(":");
555-
if (colonPos < 0)
556-
return url;
557-
return url[0 .. colonPos];
555+
556+
string dbName = colonPos < 0 ? url : url[0 .. colonPos];
557+
return dbName == "sqlserver" || dbName == "oracle" ? "odbc" : dbName;
558558
}
559559

560560
/// extract parameters from URL string to string[string] map, update url to strip params

source/ddbc/core.d

+16-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ string makeDDBCUrl(string driverName, string[string] params) {
411411
string makeDDBCUrl(string driverName, string host = null, int port = 0,
412412
string dbName = null, string[string] params = null) {
413413
import std.algorithm.searching : canFind;
414-
enforce(canFind(["sqlite", "postgresql", "mysql", "odbc"], driverName), "driver must be one of sqlite|postgresql|mysql|odbc");
414+
enforce(canFind(["sqlite", "postgresql", "mysql", "sqlserver", "oracle", "odbc"], driverName), "driver must be one of sqlite|postgresql|mysql|sqlserver|oracle|odbc");
415415
import std.conv : to;
416416
char[] res;
417417
res.assumeSafeAppend;
@@ -462,6 +462,21 @@ private unittest {
462462
assert(url == "ddbc:mysql://127.0.0.1:3306/mydb", "MySQL URL is not correct: "~url);
463463
}
464464

465+
private unittest {
466+
string url = makeDDBCUrl("sqlserver", "127.0.0.1", 1433, "mydb");
467+
assert(url == "ddbc:sqlserver://127.0.0.1:1433/mydb", "SQL Server URL is not correct: "~url);
468+
}
469+
470+
private unittest {
471+
string url = makeDDBCUrl("oracle", "127.0.0.1", 1521, "mydb");
472+
assert(url == "ddbc:oracle://127.0.0.1:1521/mydb", "Oracle URL is not correct: "~url);
473+
}
474+
475+
private unittest {
476+
string url = makeDDBCUrl("odbc", "127.0.0.1", 3306, "mydb");
477+
assert(url == "ddbc:odbc://127.0.0.1:3306/mydb", "ODBC URL is not correct: "~url);
478+
}
479+
465480
private unittest {
466481
string[string] params;
467482
params["user"] = "sa";

0 commit comments

Comments
 (0)