fix(connect): support informix-sqli JDBC URL parsing
This commit is contained in:
parent
6152b01ea8
commit
c13efc65f8
|
|
@ -45,6 +45,7 @@ const SCHEME_PROFILES: Record<string, ConnectionProfile> = {
|
|||
kwdb: { type: "kwdb", profile: "kwdb", label: "KWDB", defaultPort: 26257 },
|
||||
gbase: { type: "gbase", profile: "gbase", label: "GBase", defaultPort: 5258 },
|
||||
"gbasedbt-sqli": { type: "gbase", profile: "gbase8s", label: "GBase 8s", defaultPort: 9088 },
|
||||
"informix-sqli": { type: "informix", profile: "informix", label: "Informix", defaultPort: 9088 },
|
||||
yashandb: { type: "yashandb", profile: "yashandb", label: "YashanDB", defaultPort: 1688 },
|
||||
opengauss: { type: "gaussdb", profile: "opengauss", label: "openGauss", defaultPort: 5432 },
|
||||
tdengine: { type: "tdengine", profile: "tdengine", label: "TDengine", defaultPort: 6041 },
|
||||
|
|
@ -362,6 +363,28 @@ function parseJdbcGbase8sUrl(source: string): ParsedConnectionUrl | null {
|
|||
};
|
||||
}
|
||||
|
||||
function parseJdbcInformixUrl(source: string): ParsedConnectionUrl | null {
|
||||
const match = /^jdbc:informix-sqli:\/\/(?:(?<userinfo>[^@/?#]*)@)?(?<host>\[[^\]]+\]|[^:/?#]+)(?::(?<port>\d+))?\/(?<database>[^:?#]*)(?::(?<params>[^?#]*))?/i.exec(source);
|
||||
if (!match?.groups) return null;
|
||||
|
||||
const rawUserInfo = match.groups.userinfo || "";
|
||||
const [rawUser = "", ...passwordParts] = rawUserInfo.split(":");
|
||||
const host = match.groups.host.replace(/^\[/, "").replace(/\]$/, "");
|
||||
|
||||
return {
|
||||
dbType: "informix",
|
||||
driverProfile: "informix",
|
||||
driverLabel: "Informix",
|
||||
host,
|
||||
port: match.groups.port ? Number(match.groups.port) : 9088,
|
||||
username: decodeUrlPart(rawUser),
|
||||
password: decodeUrlPart(passwordParts.join(":")),
|
||||
database: decodeUrlPart(match.groups.database || ""),
|
||||
urlParams: match.groups.params || "",
|
||||
ssl: false,
|
||||
};
|
||||
}
|
||||
|
||||
export function parseConnectionUrl(value: string, preferredProfile?: string): ParsedConnectionUrl {
|
||||
const input = value.trim();
|
||||
if (!input) {
|
||||
|
|
@ -371,6 +394,8 @@ export function parseConnectionUrl(value: string, preferredProfile?: string): Pa
|
|||
if (jdbcUCanAccess) return jdbcUCanAccess;
|
||||
const jdbcGbase8s = parseJdbcGbase8sUrl(input);
|
||||
if (jdbcGbase8s) return jdbcGbase8s;
|
||||
const jdbcInformix = parseJdbcInformixUrl(input);
|
||||
if (jdbcInformix) return jdbcInformix;
|
||||
const jdbcOracle = parseJdbcOracleUrl(input);
|
||||
if (jdbcOracle) return jdbcOracle;
|
||||
const jdbcSqlServer = parseJdbcSqlServerUrl(input);
|
||||
|
|
|
|||
|
|
@ -168,6 +168,50 @@ test("parses GBase 8s JDBC URLs", () => {
|
|||
assert.equal(parsed.urlParams, "GBASEDBTSERVER=gbase01;CLIENT_LOCALE=zh_cn.utf8");
|
||||
});
|
||||
|
||||
test("parses Informix JDBC URLs with INFORMIXSERVER", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:informix-sqli://192.168.1.1:9088/mydb:INFORMIXSERVER=ol_informix");
|
||||
|
||||
assert.equal(parsed.dbType, "informix");
|
||||
assert.equal(parsed.driverProfile, "informix");
|
||||
assert.equal(parsed.driverLabel, "Informix");
|
||||
assert.equal(parsed.host, "192.168.1.1");
|
||||
assert.equal(parsed.port, 9088);
|
||||
assert.equal(parsed.database, "mydb");
|
||||
assert.equal(parsed.urlParams, "INFORMIXSERVER=ol_informix");
|
||||
});
|
||||
|
||||
test("parses Informix JDBC URLs with multiple parameters", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:informix-sqli://192.168.1.1:9088/mydb:INFORMIXSERVER=ol_informix;DB_LOCALE=en_US.UTF8");
|
||||
|
||||
assert.equal(parsed.dbType, "informix");
|
||||
assert.equal(parsed.host, "192.168.1.1");
|
||||
assert.equal(parsed.port, 9088);
|
||||
assert.equal(parsed.database, "mydb");
|
||||
assert.equal(parsed.urlParams, "INFORMIXSERVER=ol_informix;DB_LOCALE=en_US.UTF8");
|
||||
});
|
||||
|
||||
test("parses Informix JDBC URLs with credentials", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:informix-sqli://user:p%40ss@db.example.com:1533/testdb:INFORMIXSERVER=myserver");
|
||||
|
||||
assert.equal(parsed.dbType, "informix");
|
||||
assert.equal(parsed.host, "db.example.com");
|
||||
assert.equal(parsed.port, 1533);
|
||||
assert.equal(parsed.username, "user");
|
||||
assert.equal(parsed.password, "p@ss");
|
||||
assert.equal(parsed.database, "testdb");
|
||||
assert.equal(parsed.urlParams, "INFORMIXSERVER=myserver");
|
||||
});
|
||||
|
||||
test("parses Informix JDBC URLs without extra parameters", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:informix-sqli://192.168.1.1:9088/mydb");
|
||||
|
||||
assert.equal(parsed.dbType, "informix");
|
||||
assert.equal(parsed.host, "192.168.1.1");
|
||||
assert.equal(parsed.port, 9088);
|
||||
assert.equal(parsed.database, "mydb");
|
||||
assert.equal(parsed.urlParams, "");
|
||||
});
|
||||
|
||||
test("parses UCanAccess JDBC URLs as Access database files", () => {
|
||||
const parsed = parseConnectionUrl("jdbc:ucanaccess:///Users/me/data/Northwind.accdb;memory=false");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue