(cell: vscode.NotebookCell)
| 40 | } |
| 41 | |
| 42 | private async doExecution(cell: vscode.NotebookCell): Promise<void> { |
| 43 | const execution = this._controller.createNotebookCellExecution(cell); |
| 44 | execution.executionOrder = ++this._executionOrder; |
| 45 | execution.start(Date.now()); |
| 46 | |
| 47 | // this is a sql block |
| 48 | const rawQuery = cell.document.getText(); |
| 49 | if (!globalConnPool.pool) { |
| 50 | writeErr( |
| 51 | execution, |
| 52 | 'No active connection found. Configure database connections in the SQL Notebook sidepanel.' |
| 53 | ); |
| 54 | return; |
| 55 | } |
| 56 | const conn = await globalConnPool.pool.getConnection(); |
| 57 | execution.token.onCancellationRequested(() => { |
| 58 | console.debug('got cancellation request'); |
| 59 | (async () => { |
| 60 | conn.release(); |
| 61 | conn.destroy(); |
| 62 | writeErr(execution, 'Query cancelled'); |
| 63 | })(); |
| 64 | }); |
| 65 | |
| 66 | console.debug('executing query', { query: rawQuery }); |
| 67 | let result: ExecutionResult; |
| 68 | try { |
| 69 | result = await conn.query(rawQuery); |
| 70 | console.debug('sql query completed', result); |
| 71 | conn.release(); |
| 72 | } catch (err) { |
| 73 | console.debug('sql query failed', err); |
| 74 | // @ts-ignore |
| 75 | writeErr(execution, err.message); |
| 76 | conn.release(); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if (typeof result === 'string') { |
| 81 | writeSuccess(execution, [[text(result)]]); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | if ( |
| 86 | result.length === 0 || |
| 87 | (result.length === 1 && result[0].length === 0) |
| 88 | ) { |
| 89 | writeSuccess(execution, [[text('Successfully executed query')]]); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | writeSuccess( |
| 94 | execution, |
| 95 | result.map((item) => { |
| 96 | const outputs = [text(resultToMarkdownTable(item), 'text/markdown')]; |
| 97 | if (outputJsonMimeType()) { |
| 98 | outputs.push(json(item)); |
| 99 | } |
no test coverage detected