@@ -11,6 +11,17 @@ import Table from "../../database/table";
1111import Statement from "../../database/statement" ;
1212import { TableColumn } from "../../types" ;
1313
14+ export type SqlParameter = string | number ;
15+
16+ export interface ScrollerOptions {
17+ basicSelect : string ;
18+ parameters ?: SqlParameter [ ] ;
19+ isCL ?: boolean ;
20+ queryId ?: string ;
21+ withCancel ?: boolean ;
22+ ref ?: ObjectRef ;
23+ }
24+
1425export class ResultSetPanelProvider implements WebviewViewProvider {
1526 _view : WebviewView | WebviewPanel ;
1627 loadingState : boolean ;
@@ -193,17 +204,17 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
193204 }
194205 }
195206
196- async setScrolling ( basicSelect : string , isCL = false , queryId : string = `` , withCancel = false , ref ?: ObjectRef ) {
207+ async setScrolling ( options : ScrollerOptions ) {
197208 this . loadingState = false ;
198209 await this . focus ( ) ;
199210
200211 let updatable : html . UpdatableInfo | undefined ;
201212
202- if ( ref ) {
203- const schema = ref . object . schema || ref . object . system ;
213+ if ( options . ref ) {
214+ const schema = options . ref . object . schema || options . ref . object . system ;
204215 if ( schema ) {
205216 const goodSchema = Statement . delimName ( schema , true ) ;
206- const goodName = Statement . delimName ( ref . object . name , true ) ;
217+ const goodName = Statement . delimName ( options . ref . object . name , true ) ;
207218
208219 try {
209220 const isPartitioned = await Table . isPartitioned ( goodSchema , goodName ) ;
@@ -234,16 +245,16 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
234245 } ) ) ;
235246
236247 if ( ! currentColumns . some ( c => c . useInWhere ) ) {
237- const cName = ref . alias || `t` ;
248+ const cName = options . ref . alias || `t` ;
238249
239250 // Support for using a custom column list
240- const selectClauseStart = basicSelect . toLowerCase ( ) . indexOf ( `select ` ) ;
241- const fromClauseStart = basicSelect . toLowerCase ( ) . indexOf ( `from` ) ;
251+ const selectClauseStart = options . basicSelect . toLowerCase ( ) . indexOf ( `select ` ) ;
252+ const fromClauseStart = options . basicSelect . toLowerCase ( ) . indexOf ( `from` ) ;
242253 let possibleColumnList : string | undefined ;
243254
244255 possibleColumnList = `${ cName } .*` ;
245256 if ( fromClauseStart > 0 ) {
246- possibleColumnList = basicSelect . substring ( 0 , fromClauseStart ) ;
257+ possibleColumnList = options . basicSelect . substring ( 0 , fromClauseStart ) ;
247258 if ( selectClauseStart >= 0 ) {
248259 possibleColumnList = possibleColumnList . substring ( selectClauseStart + 7 ) ;
249260
@@ -254,20 +265,20 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
254265 }
255266
256267 // We need to override the input statement if they want to do updatable
257- const whereClauseStart = basicSelect . toLowerCase ( ) . indexOf ( `where` ) ;
268+ const whereClauseStart = options . basicSelect . toLowerCase ( ) . indexOf ( `where` ) ;
258269 let fromWhereClause : string | undefined ;
259270
260271 if ( whereClauseStart > 0 ) {
261- fromWhereClause = basicSelect . substring ( whereClauseStart ) ;
272+ fromWhereClause = options . basicSelect . substring ( whereClauseStart ) ;
262273 }
263274
264275
265- basicSelect = `select rrn(${ cName } ) as RRN, ${ possibleColumnList } from ${ schema } .${ ref . object . name } as ${ cName } ${ fromWhereClause || `` } ` ;
276+ options . basicSelect = `select rrn(${ cName } ) as RRN, ${ possibleColumnList } from ${ schema } .${ options . ref . object . name } as ${ cName } ${ fromWhereClause || `` } ` ;
266277 currentColumns = [ { name : `RRN` , jsType : `number` , useInWhere : true } , ...currentColumns ] ;
267278 }
268279
269280 updatable = {
270- table : schema + `.` + ref . object . name ,
281+ table : schema + `.` + options . ref . object . name ,
271282 columns : currentColumns
272283 } ;
273284 }
@@ -278,11 +289,11 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
278289 }
279290 }
280291
281- this . _view . webview . html = html . generateScroller ( basicSelect , isCL , withCancel , updatable ) ;
292+ this . _view . webview . html = html . generateScroller ( options . basicSelect , options . parameters , options . isCL , options . withCancel , updatable ) ;
282293
283294 this . _view . webview . postMessage ( {
284295 command : `fetch` ,
285- queryId
296+ queryId : options . queryId
286297 } ) ;
287298 }
288299
0 commit comments