@@ -12,13 +12,15 @@ import { ExplainTree } from "./explain/nodes";
1212import { DoveResultsView , ExplainTreeItem } from "./explain/doveResultsView" ;
1313import { DoveNodeView , PropertyNode } from "./explain/doveNodeView" ;
1414import { DoveTreeDecorationProvider } from "./explain/doveTreeDecorationProvider" ;
15- import { ResultSetPanelProvider } from "./resultSetPanelProvider" ;
15+ import { ResultSetPanelProvider , SqlParameter } from "./resultSetPanelProvider" ;
1616import { generateSqlForAdvisedIndexes } from "./explain/advice" ;
1717import { updateStatusBar } from "../jobManager/statusBar" ;
1818import { DbCache } from "../../language/providers/logic/cache" ;
1919import { ExplainType } from "../../connection/types" ;
2020import { queryResultToRpgDs } from "./codegen" ;
2121import Configuration from "../../configuration" ;
22+ import { getSqlDocument } from "../../language/providers/logic/parse" ;
23+ import { getLiteralsFromStatement , getPriorBindableStatement } from "./binding" ;
2224
2325export type StatementQualifier = "statement" | "bind" | "update" | "explain" | "onlyexplain" | "json" | "csv" | "cl" | "sql" | "rpg" ;
2426
@@ -317,7 +319,6 @@ async function runHandler(options?: StatementInfo) {
317319 const inWindow = Boolean ( options && options . viewColumn ) ;
318320
319321 if ( statementDetail . qualifier === `cl` ) {
320- // TODO: handle noUi
321322 if ( statementDetail . noUi ) {
322323 setCancelButtonVisibility ( true ) ;
323324 const command = statementDetail . content . split ( ` ` ) [ 0 ] . toUpperCase ( ) ;
@@ -338,13 +339,24 @@ async function runHandler(options?: StatementInfo) {
338339 isCL : true ,
339340 } ) ; // Never errors
340341 }
341-
342- } else if ( [ `statement` , `update` , `cl` ] . includes ( statementDetail . qualifier ) ) {
342+
343+ } else if ( [ `statement` , `update` , `bind` ] . includes ( statementDetail . qualifier ) ) {
344+ let parameters : SqlParameter [ ] = [ ] ;
345+ if ( editor && statementDetail . qualifier === `bind` ) {
346+ const position = editor . selection . active ;
347+ const runStatement = getPriorBindableStatement ( editor , editor . document . offsetAt ( position ) ) ;
348+
349+ if ( runStatement ) {
350+ parameters = getLiteralsFromStatement ( statementDetail . group ) ;
351+ statementDetail . content = runStatement ;
352+ }
353+ }
354+
343355 // If it's a basic statement, we can let it scroll!
344356 if ( statementDetail . noUi ) {
345357 setCancelButtonVisibility ( true ) ;
346358 chosenView . setLoadingText ( `Running SQL statement... (${ possibleTitle } )` , false ) ;
347- await JobManager . runSQL ( statementDetail . content , undefined , 1 ) ;
359+ await JobManager . runSQL ( statementDetail . content , { parameters } , 1 ) ;
348360
349361 } else {
350362 if ( inWindow ) {
@@ -360,6 +372,7 @@ async function runHandler(options?: StatementInfo) {
360372 basicSelect : statementDetail . content ,
361373 withCancel : inWindow ,
362374 ref : updatableTable ,
375+ parameters,
363376 } )
364377 }
365378
@@ -551,7 +564,7 @@ export function parseStatement(editor?: vscode.TextEditor, existingInfo?: Statem
551564 const document = editor . document ;
552565 const cursor = editor . document . offsetAt ( editor . selection . active ) ;
553566
554- sqlDocument = new Document ( document . getText ( ) ) ;
567+ sqlDocument = getSqlDocument ( document ) ;
555568 statementInfo . group = sqlDocument . getGroupByOffset ( cursor ) ;
556569 }
557570
0 commit comments