ML - Verifying ODBC Driver (#11587)

* Verifying ODBC is installed before opening package manager dialog
This commit is contained in:
Leila Lali
2020-08-13 08:52:10 -07:00
committed by GitHub
parent 053a2c7446
commit cc8989c2a5
6 changed files with 154 additions and 15 deletions

View File

@@ -120,6 +120,8 @@ export class PackageManager {
await utils.executeTasks(this._apiWrapper, constants.installPackageMngDependenciesMsgTaskName, [
this.installRequiredPythonPackages(this._config.requiredSqlPythonPackages),
this.installRequiredRPackages()], true);
await this.verifyOdbcInstalled();
}
private async installRequiredRPackages(): Promise<void> {
@@ -186,6 +188,45 @@ export class PackageManager {
}
}
private async verifyOdbcInstalled(): Promise<void> {
let connection = await this.getCurrentConnection();
if (connection) {
let credentials = await this._apiWrapper.getCredentials(connection.connectionId);
const separator = '=';
let connectionParts: string[] = [];
if (connection) {
connectionParts.push(utils.getKeyValueString('DRIVER', `{${constants.supportedODBCDriver}}`, separator));
if (connection.userName) {
connectionParts.push(utils.getKeyValueString('UID', connection.userName, separator));
connectionParts.push(utils.getKeyValueString('PWD', credentials[azdata.ConnectionOptionSpecialType.password], separator));
} else {
connectionParts.push(utils.getKeyValueString('Trusted_Connection', 'yes', separator));
}
connectionParts.push(utils.getKeyValueString('SERVER', connection.serverName, separator));
}
let scripts: string[] = [
'import pyodbc',
`connection = pyodbc.connect('${connectionParts.join(';')}')`,
'cursor = connection.cursor()',
'cursor.execute("SELECT @@version;")'
];
let pythonExecutable = await this._config.getPythonExecutable(true);
try {
await this._processService.execScripts(pythonExecutable, scripts, [], this._outputChannel);
} catch (err) {
const result = await this._apiWrapper.showErrorMessage(constants.verifyOdbcDriverError, constants.learnMoreTitle);
if (result === constants.learnMoreTitle) {
await this._apiWrapper.openExternal(vscode.Uri.parse(constants.odbcDriverDocuments));
}
throw err;
}
}
}
private async getInstalledPipPackages(): Promise<nbExtensionApis.IPackageDetails[]> {
try {
let pythonExecutable = await this.getPythonExecutable();