From c8e46f774e6ec9c4cfe2550852b874dc8c5568c6 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Tue, 19 Oct 2021 18:58:52 +0200 Subject: [PATCH 1/9] msnodesqlv8 upgrade --- app/package.json | 2 +- packages/api/package.json | 2 +- yarn.lock | 58 +++++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/app/package.json b/app/package.json index 5f9b6acc..cf3829d7 100644 --- a/app/package.json +++ b/app/package.json @@ -107,6 +107,6 @@ "electron-builder": "22.10.5" }, "optionalDependencies": { - "msnodesqlv8": "^2.0.10" + "msnodesqlv8": "^2.4.0" } } diff --git a/packages/api/package.json b/packages/api/package.json index 39a9896b..cb2adc89 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -70,6 +70,6 @@ "webpack-cli": "^3.3.11" }, "optionalDependencies": { - "msnodesqlv8": "^2.0.10" + "msnodesqlv8": "^2.4.0" } } diff --git a/yarn.lock b/yarn.lock index 5cd15192..fa4b1db9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7344,13 +7344,14 @@ ms@^2.0.0: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -msnodesqlv8@^2.0.10: - version "2.0.10" - resolved "https://registry.yarnpkg.com/msnodesqlv8/-/msnodesqlv8-2.0.10.tgz#47d05157c2d30e5f48fa0aa550a0353ab56a027c" - integrity sha512-oA46Y8ZQxYEW9M8U+Wg4bI5g8nI2pueIkyameEpxanHqr9d5w4a0Pgk2WvugHiY1UYmN1bPziUdqBgwkBSGrnA== +msnodesqlv8@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/msnodesqlv8/-/msnodesqlv8-2.4.0.tgz#7815b965655a5ccb0635f2f48476b5d6d49e3343" + integrity sha512-CYecwSZS86jE1Nr7sO/cWWfmeg5F+hhFbs8gABGqOsiLWWoylFrOiPfcV3Z4jgDcVWIV6pF2eiBCE/b8KriypA== dependencies: nan "^2.14.2" - prebuild-install "^6.0.0" + node-abi "^2.30.0" + prebuild-install "^6.1.2" mute-stream@0.0.8: version "0.0.8" @@ -7465,6 +7466,13 @@ node-abi@^2.21.0: dependencies: semver "^5.4.1" +node-abi@^2.30.0: + version "2.30.1" + resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.30.1.tgz#c437d4b1fe0e285aaf290d45b45d4d7afedac4cf" + integrity sha512-/2D0wOQPgaUWzVSVgRMx+trKJRC2UG4SUc4oCJoXx9Uxjtp0Vy3/kt7zcbxHF8+Z/pK3UloLWzBISg72brfy1w== + dependencies: + semver "^5.4.1" + node-abi@^2.7.0: version "2.19.3" resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.19.3.tgz#252f5dcab12dad1b5503b2d27eddd4733930282d" @@ -8366,27 +8374,6 @@ prebuild-install@6.0.1: tunnel-agent "^0.6.0" which-pm-runs "^1.0.0" -prebuild-install@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-6.0.0.tgz#669022bcde57c710a869e39c5ca6bf9cd207f316" - integrity sha512-h2ZJ1PXHKWZpp1caLw0oX9sagVpL2YTk+ZwInQbQ3QqNd4J03O6MpFNmMTJlkfgPENWqe5kP0WjQLqz5OjLfsw== - dependencies: - detect-libc "^1.0.3" - expand-template "^2.0.3" - github-from-package "0.0.0" - minimist "^1.2.3" - mkdirp-classic "^0.5.3" - napi-build-utils "^1.0.1" - node-abi "^2.7.0" - noop-logger "^0.1.1" - npmlog "^4.0.1" - pump "^3.0.0" - rc "^1.2.7" - simple-get "^3.0.3" - tar-fs "^2.0.0" - tunnel-agent "^0.6.0" - which-pm-runs "^1.0.0" - prebuild-install@^6.0.1: version "6.1.2" resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-6.1.2.tgz#6ce5fc5978feba5d3cbffedca0682b136a0b5bff" @@ -8407,6 +8394,25 @@ prebuild-install@^6.0.1: tar-fs "^2.0.0" tunnel-agent "^0.6.0" +prebuild-install@^6.1.2: + version "6.1.4" + resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-6.1.4.tgz#ae3c0142ad611d58570b89af4986088a4937e00f" + integrity sha512-Z4vpywnK1lBg+zdPCVCsKq0xO66eEV9rWo2zrROGGiRS4JtueBOdlB1FnY8lcy7JsUud/Q3ijUxyWN26Ika0vQ== + dependencies: + detect-libc "^1.0.3" + expand-template "^2.0.3" + github-from-package "0.0.0" + minimist "^1.2.3" + mkdirp-classic "^0.5.3" + napi-build-utils "^1.0.1" + node-abi "^2.21.0" + npmlog "^4.0.1" + pump "^3.0.0" + rc "^1.2.7" + simple-get "^3.0.3" + tar-fs "^2.0.0" + tunnel-agent "^0.6.0" + prelude-ls@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" From a25af4714e6b2e44de6367188740938e74e1e3cd Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Tue, 19 Oct 2021 19:10:27 +0200 Subject: [PATCH 2/9] #183 fix msnodesql driver problem --- .../src/backend/nativeDriver.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js b/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js index 914c0ccb..f4edd419 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js +++ b/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js @@ -43,22 +43,38 @@ function extractNativeColumns(meta) { return res; } -async function nativeConnect({ server, port, user, password, database, authType }) { +async function connectWithDriver({ server, port, user, password, database, authType }, driver) { let connectionString = `server=${server}`; if (port && !server.includes('\\')) connectionString += `,${port}`; - connectionString += ';Driver={SQL Server Native Client 11.0}'; + connectionString += `;Driver={${driver}}`; if (authType == 'sspi') connectionString += ';Trusted_Connection=Yes'; else connectionString += `;UID=${user};PWD=${password}`; if (database) connectionString += `;Database=${database}`; return new Promise((resolve, reject) => { msnodesqlv8.open(connectionString, (err, conn) => { - if (err) reject(err); - conn._connectionType = 'msnodesqlv8'; - resolve(conn); + if (err) { + reject(err); + } else { + conn._connectionType = 'msnodesqlv8'; + resolve(conn); + } }); }); } +async function nativeConnect(connection) { + const drivers = ['ODBC Driver 17 for SQL Server', 'SQL Server Native Client 11.0']; + for (let i = 0; i < drivers.length; i += 1) { + try { + const res = await connectWithDriver(connection, drivers[i]); + return res; + } catch (err) { + if (err.message.includes('[ODBC Driver Manager]') && i < drivers.length - 1) continue; + throw err; + } + } +} + async function nativeQueryCore(pool, sql, options) { if (sql == null) { return Promise.resolve({ From 04902c2d9fa2fb02e122ba31ea266f6730939aad Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Tue, 19 Oct 2021 19:11:01 +0200 Subject: [PATCH 3/9] v4.3.4-beta.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 351ba260..6fe88617 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "4.3.3", + "version": "4.3.4-beta.1", "name": "dbgate-all", "workspaces": [ "packages/*", From 50a22b63d066ae8dde2c1cdbd94407c435ffc45e Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Tue, 19 Oct 2021 21:16:25 +0200 Subject: [PATCH 4/9] v4.3.4-beta.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6fe88617..0fd14dd9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "4.3.4-beta.1", + "version": "4.3.4-beta.2", "name": "dbgate-all", "workspaces": [ "packages/*", From c571582ed86011750f847e66ae2bfac92d00d791 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 21 Oct 2021 07:25:34 +0200 Subject: [PATCH 5/9] native ms sql connect fix + logs --- plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js b/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js index f4edd419..c0b71d23 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js +++ b/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js @@ -67,9 +67,13 @@ async function nativeConnect(connection) { for (let i = 0; i < drivers.length; i += 1) { try { const res = await connectWithDriver(connection, drivers[i]); + console.error(`Connected SQL Server with ${drivers[i]} driver`); return res; } catch (err) { - if (err.message.includes('[ODBC Driver Manager]') && i < drivers.length - 1) continue; + if (err.message && err.message.includes('[ODBC Driver Manager]') && i < drivers.length - 1) { + console.error(`Failed connecting with ${drivers[i]} driver, trying next`, err); + continue; + } throw err; } } From 96afe1b0d67537db4a536b2ca31677beef4cb9d5 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 21 Oct 2021 07:25:50 +0200 Subject: [PATCH 6/9] v4.3.4-beta.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0fd14dd9..31b5c2f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "4.3.4-beta.2", + "version": "4.3.4-beta.3", "name": "dbgate-all", "workspaces": [ "packages/*", From bf315c53ac45ccc3be5e80130227d25a2a73775b Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 24 Oct 2021 07:53:02 +0200 Subject: [PATCH 7/9] report error from mssql native connect --- plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js b/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js index c0b71d23..0546799d 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js +++ b/plugins/dbgate-plugin-mssql/src/backend/nativeDriver.js @@ -64,6 +64,7 @@ async function connectWithDriver({ server, port, user, password, database, authT async function nativeConnect(connection) { const drivers = ['ODBC Driver 17 for SQL Server', 'SQL Server Native Client 11.0']; + for (let i = 0; i < drivers.length; i += 1) { try { const res = await connectWithDriver(connection, drivers[i]); @@ -74,7 +75,7 @@ async function nativeConnect(connection) { console.error(`Failed connecting with ${drivers[i]} driver, trying next`, err); continue; } - throw err; + throw new Error(`${err}`); } } } From 902267f5eb1d0ed81d94fa2bd78cb02bbc05689f Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 24 Oct 2021 08:03:03 +0200 Subject: [PATCH 8/9] Improved ms sql windows connect UX --- packages/types/engines.d.ts | 1 + packages/web/src/modals/ConnectionModalDriverFields.svelte | 2 ++ plugins/dbgate-plugin-mssql/src/backend/driver.js | 2 +- plugins/dbgate-plugin-mssql/src/frontend/driver.js | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/types/engines.d.ts b/packages/types/engines.d.ts index 0a728b0a..910bfe3b 100644 --- a/packages/types/engines.d.ts +++ b/packages/types/engines.d.ts @@ -47,6 +47,7 @@ export interface EngineDriver { showConnectionTab?: (tab: 'ssl' | 'sshTunnel', values: any) => boolean; beforeConnectionSave?: (values: any) => any; databaseUrlPlaceholder?: string; + defaultAuthTypeName?: string; connect({ server, port, user, password, database }): Promise; close(pool): Promise; query(pool: any, sql: string, options?: QueryOptions): Promise; diff --git a/packages/web/src/modals/ConnectionModalDriverFields.svelte b/packages/web/src/modals/ConnectionModalDriverFields.svelte index eb53ca27..b2b05373 100644 --- a/packages/web/src/modals/ConnectionModalDriverFields.svelte +++ b/packages/web/src/modals/ConnectionModalDriverFields.svelte @@ -65,6 +65,8 @@ ({ value: auth.name, label: auth.title, diff --git a/plugins/dbgate-plugin-mssql/src/backend/driver.js b/plugins/dbgate-plugin-mssql/src/backend/driver.js index af87acaf..2c2caae1 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/driver.js +++ b/plugins/dbgate-plugin-mssql/src/backend/driver.js @@ -41,7 +41,7 @@ const windowsAuthTypes = [ disabledFields: ['port'], }, { - title: 'Tedious driver', + title: 'NodeJs portable driver (tedious)', name: 'tedious', }, ]; diff --git a/plugins/dbgate-plugin-mssql/src/frontend/driver.js b/plugins/dbgate-plugin-mssql/src/frontend/driver.js index 17a2f61e..bfbdf9a2 100644 --- a/plugins/dbgate-plugin-mssql/src/frontend/driver.js +++ b/plugins/dbgate-plugin-mssql/src/frontend/driver.js @@ -59,6 +59,7 @@ const driver = { engine: 'mssql@dbgate-plugin-mssql', title: 'Microsoft SQL Server', defaultPort: 1433, + defaultAuthTypeName: 'tedious', }; module.exports = driver; From 2015b330be31710aa85d68a68ffe6d18bce1ca68 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 24 Oct 2021 10:18:57 +0200 Subject: [PATCH 9/9] v4.3.4-beta.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 31b5c2f2..a735b3d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "4.3.4-beta.3", + "version": "4.3.4-beta.4", "name": "dbgate-all", "workspaces": [ "packages/*",