in src/SqlUtils.ts [107:156]
public static buildSqlCmdCallWithConnectionInfo(connectionConfig: SqlConnectionConfig, database?: string): string {
// sqlcmd should be added to PATH already, we just need to see if need to add ".exe" for Windows
let sqlCmdPath: string;
switch (process.platform) {
case "win32":
sqlCmdPath = "sqlcmd.exe";
break;
case "linux":
case "darwin":
sqlCmdPath = "sqlcmd";
break;
default:
throw new Error(`Platform ${process.platform} is not supported.`);
}
if (!database) {
database = connectionConfig.Database;
}
let sqlcmdCall = `"${sqlCmdPath}" -S ${connectionConfig.Server},${connectionConfig.Port ?? 1433} -d ${database}`;
// Determine the correct sqlcmd arguments based on the auth type
switch (connectionConfig.FormattedAuthentication) {
case undefined:
case 'sqlpassword':
// No authentication type defaults SQL login
sqlcmdCall += ` -U "${connectionConfig.UserId}"`;
core.exportVariable(Constants.sqlcmdPasswordEnvVarName, connectionConfig.Password);
break;
case 'activedirectorydefault':
sqlcmdCall += ` --authentication-method=ActiveDirectoryDefault`;
break;
case 'activedirectorypassword':
sqlcmdCall += ` --authentication-method=ActiveDirectoryPassword -U "${connectionConfig.UserId}"`;
core.exportVariable(Constants.sqlcmdPasswordEnvVarName, connectionConfig.Password);
break;
case 'activedirectoryserviceprincipal':
sqlcmdCall += ` --authentication-method=ActiveDirectoryServicePrincipal -U "${connectionConfig.UserId}"`;
core.exportVariable(Constants.sqlcmdPasswordEnvVarName, connectionConfig.Password);
break;
default:
throw new Error(`Authentication type ${connectionConfig.FormattedAuthentication} is not supported.`);
}
return sqlcmdCall;
}