private createQueryRunner()

in src/models/sqlOutputContentProvider.ts [273:336]


    private createQueryRunner(statusView: any, uri: string, resultsUri: string,
                              selection: ISelectionData, title: string): QueryRunner {
        // Reuse existing query runner if it exists
        let queryRunner: QueryRunner;

        if (this._queryResultsMap.has(resultsUri)) {
            let existingRunner: QueryRunner = this._queryResultsMap.get(resultsUri).queryRunner;

            // If the query is already in progress, don't attempt to send it
            if (existingRunner.isExecutingQuery) {
                this._vscodeWrapper.showInformationMessage(LocalizedConstants.msgRunQueryInProgress);
                return;
            }

            // If the query is not in progress, we can reuse the query runner
            queryRunner = existingRunner;
            queryRunner.resetHasCompleted();

            // update the open pane assuming its open (if its not its a bug covered by the previewhtml command later)
            this.update(vscode.Uri.parse(resultsUri));
        } else {
            // We do not have a query runner for this editor, so create a new one
            // and map it to the results uri
            queryRunner = new QueryRunner(uri, title, statusView);
            queryRunner.eventEmitter.on('resultSet', (resultSet) => {
                this._service.broadcast(resultsUri, 'resultSet', resultSet);
            });
            queryRunner.eventEmitter.on('batchStart', (batch) => {
                // Build a link for the selection and send it in a message
                let encodedUri = encodeURIComponent(resultsUri);
                let link = LocalWebService.getEndpointUri(Interfaces.ContentType.EditorSelection) + `?uri=${encodedUri}`;
                if (batch.selection) {
                    link += `&startLine=${batch.selection.startLine}` +
                            `&startColumn=${batch.selection.startColumn}` +
                            `&endLine=${batch.selection.endLine}` +
                            `&endColumn=${batch.selection.endColumn}`;
                }

                let message = {
                    message: LocalizedConstants.runQueryBatchStartMessage,
                    batchId: undefined,
                    isError: false,
                    time: new Date().toLocaleTimeString(),
                    link: {
                        text: Utils.formatString(LocalizedConstants.runQueryBatchStartLine, batch.selection.startLine + 1),
                        uri: link
                    }
                };
                this._service.broadcast(resultsUri, 'message', message);
            });
            queryRunner.eventEmitter.on('message', (message) => {
                this._service.broadcast(resultsUri, 'message', message);
            });
            queryRunner.eventEmitter.on('complete', (totalMilliseconds) => {
                this._service.broadcast(resultsUri, 'complete', totalMilliseconds);
            });
            queryRunner.eventEmitter.on('start', () => {
                this._service.resetSocket(resultsUri);
            });
            this._queryResultsMap.set(resultsUri, new QueryRunnerState(queryRunner));
        }

        return queryRunner;
    }