1fb726d48Sopenharmony_ci/*
2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb726d48Sopenharmony_ci * You may obtain a copy of the License at
6fb726d48Sopenharmony_ci *
7fb726d48Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb726d48Sopenharmony_ci *
9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and
13fb726d48Sopenharmony_ci * limitations under the License.
14fb726d48Sopenharmony_ci */
15fb726d48Sopenharmony_ci
16fb726d48Sopenharmony_ciimport { BaseElement, element } from '../../base-ui/BaseElement';
17fb726d48Sopenharmony_ciimport { LitTable } from '../../base-ui/table/lit-table';
18fb726d48Sopenharmony_ciimport '../../base-ui/table/lit-table';
19fb726d48Sopenharmony_ciimport { LitTableColumn } from '../../base-ui/table/lit-table-column';
20fb726d48Sopenharmony_ciimport { info } from '../../log/Log';
21fb726d48Sopenharmony_ciimport { LitProgressBar } from '../../base-ui/progress-bar/LitProgressBar';
22fb726d48Sopenharmony_ciimport { PageNation } from '../../base-ui/chart/pagenation/PageNation';
23fb726d48Sopenharmony_ciimport { PaginationBox } from '../../base-ui/chart/pagenation/PaginationBox';
24fb726d48Sopenharmony_ciimport { SpStatisticsHttpUtil } from '../../statistics/util/SpStatisticsHttpUtil';
25fb726d48Sopenharmony_ciimport { getAllSql } from './trace/base/CommonSql';
26fb726d48Sopenharmony_ciimport { LitIcon } from '../../base-ui/icon/LitIcon';
27fb726d48Sopenharmony_ciimport { queryCustomizeSelect } from '../database/sql/SqlLite.sql';
28fb726d48Sopenharmony_ciimport { SpQuerySQLHtml } from './SpQuerySQL.html';
29fb726d48Sopenharmony_ci
30fb726d48Sopenharmony_ci@element('sp-query-sql')
31fb726d48Sopenharmony_ciexport class SpQuerySQL extends BaseElement {
32fb726d48Sopenharmony_ci  private queryTableEl: LitTable | undefined;
33fb726d48Sopenharmony_ci  private notSupportList: Array<string> | undefined = [];
34fb726d48Sopenharmony_ci  private querySize: HTMLElement | undefined;
35fb726d48Sopenharmony_ci  private keyList: Array<string> | undefined;
36fb726d48Sopenharmony_ci  private selector: HTMLTextAreaElement | undefined;
37fb726d48Sopenharmony_ci  private isSupportSql: boolean = true;
38fb726d48Sopenharmony_ci  private response: HTMLDivElement | undefined;
39fb726d48Sopenharmony_ci  private statDataArray: unknown[] = [];
40fb726d48Sopenharmony_ci  private sliceData: unknown[] = [];
41fb726d48Sopenharmony_ci  private querySqlErrorText: string = '';
42fb726d48Sopenharmony_ci  private progressLoad: LitProgressBar | undefined;
43fb726d48Sopenharmony_ci  private pagination: PaginationBox | undefined;
44fb726d48Sopenharmony_ci  private sqlListDiv: HTMLDivElement | undefined;
45fb726d48Sopenharmony_ci
46fb726d48Sopenharmony_ci  initElements(): void {
47fb726d48Sopenharmony_ci    this.progressLoad = this.shadowRoot?.querySelector('.load-query-sql') as LitProgressBar;
48fb726d48Sopenharmony_ci    this.selector = this.shadowRoot?.querySelector('.sql-select') as HTMLTextAreaElement;
49fb726d48Sopenharmony_ci    this.queryTableEl = this.shadowRoot?.querySelector('lit-table') as LitTable;
50fb726d48Sopenharmony_ci    this.queryTableEl.setAttribute('data-query-scene', '');
51fb726d48Sopenharmony_ci    this.querySize = this.shadowRoot?.querySelector('.query_size') as HTMLElement;
52fb726d48Sopenharmony_ci    this.response = this.shadowRoot?.querySelector('#dataResult') as HTMLDivElement;
53fb726d48Sopenharmony_ci    this.pagination = this.shadowRoot?.querySelector('.pagination-box') as PaginationBox;
54fb726d48Sopenharmony_ci    this.notSupportList?.push('insert', 'delete', 'update', 'drop', 'alter', 'truncate', 'create');
55fb726d48Sopenharmony_ci    this.sqlListDiv = this.shadowRoot?.querySelector('#sqlList') as HTMLDivElement;
56fb726d48Sopenharmony_ci    let htmlDivElement = this.queryTableEl.shadowRoot?.querySelector('.table') as HTMLDivElement;
57fb726d48Sopenharmony_ci    htmlDivElement.style.overflowX = 'scroll';
58fb726d48Sopenharmony_ci    window.addEventListener('resize', () => {
59fb726d48Sopenharmony_ci      this.freshTableHeadResizeStyle();
60fb726d48Sopenharmony_ci    });
61fb726d48Sopenharmony_ci    let copyButtonEl = this.shadowRoot?.querySelector('#copy-button') as HTMLButtonElement;
62fb726d48Sopenharmony_ci    copyButtonEl.addEventListener('click', () => {
63fb726d48Sopenharmony_ci      this.copyTableData();
64fb726d48Sopenharmony_ci    });
65fb726d48Sopenharmony_ci    let closeButtonEl = this.shadowRoot?.querySelector('#close-button') as HTMLButtonElement;
66fb726d48Sopenharmony_ci    closeButtonEl.addEventListener('click', () => {
67fb726d48Sopenharmony_ci      this.pagination!.style.display = 'none';
68fb726d48Sopenharmony_ci      this.querySize!.textContent = 'Query result - 0 counts.';
69fb726d48Sopenharmony_ci      this.queryTableEl!.dataSource = [];
70fb726d48Sopenharmony_ci      this.response!.innerHTML = '';
71fb726d48Sopenharmony_ci    });
72fb726d48Sopenharmony_ci    this.initCommonList();
73fb726d48Sopenharmony_ci  }
74fb726d48Sopenharmony_ci
75fb726d48Sopenharmony_ci  private initCommonList(): void {
76fb726d48Sopenharmony_ci    let commonSqlList = getAllSql();
77fb726d48Sopenharmony_ci    if (commonSqlList.length > 0) {
78fb726d48Sopenharmony_ci      for (let i = 0; i < commonSqlList.length; i++) {
79fb726d48Sopenharmony_ci        let commonSqlDiv = document.createElement('div');
80fb726d48Sopenharmony_ci        commonSqlDiv.className = 'sql-item';
81fb726d48Sopenharmony_ci        let sql = document.createElement('div');
82fb726d48Sopenharmony_ci        sql.className = 'sql';
83fb726d48Sopenharmony_ci        sql.textContent = commonSqlList[i].sql;
84fb726d48Sopenharmony_ci        let runButton = document.createElement('lit-icon');
85fb726d48Sopenharmony_ci        runButton.className = 'runButton';
86fb726d48Sopenharmony_ci        runButton.title = commonSqlList[i].title;
87fb726d48Sopenharmony_ci        runButton.setAttribute('size', '20');
88fb726d48Sopenharmony_ci        runButton.setAttribute('name', 'run-sql');
89fb726d48Sopenharmony_ci        commonSqlDiv.appendChild(sql);
90fb726d48Sopenharmony_ci        commonSqlDiv.appendChild(runButton);
91fb726d48Sopenharmony_ci        this.sqlListDiv?.append(commonSqlDiv);
92fb726d48Sopenharmony_ci      }
93fb726d48Sopenharmony_ci    }
94fb726d48Sopenharmony_ci  }
95fb726d48Sopenharmony_ci
96fb726d48Sopenharmony_ci  private freshTableHeadResizeStyle(): void {
97fb726d48Sopenharmony_ci    let th = this.queryTableEl!.shadowRoot?.querySelector<HTMLDivElement>('.th');
98fb726d48Sopenharmony_ci    if (th) {
99fb726d48Sopenharmony_ci      let td = th.querySelectorAll<HTMLDivElement>('.td');
100fb726d48Sopenharmony_ci      let firstChild = this.queryTableEl!.shadowRoot?.querySelector<HTMLDivElement>('.body')!.firstElementChild;
101fb726d48Sopenharmony_ci      if (firstChild) {
102fb726d48Sopenharmony_ci        let bodyList = firstChild.querySelectorAll<HTMLDivElement>('.td');
103fb726d48Sopenharmony_ci        for (let index = 0; index < bodyList.length; index++) {
104fb726d48Sopenharmony_ci          td[index].style.width = `${bodyList[index].offsetWidth}px`;
105fb726d48Sopenharmony_ci          td[index].style.overflow = 'hidden';
106fb726d48Sopenharmony_ci        }
107fb726d48Sopenharmony_ci      }
108fb726d48Sopenharmony_ci    }
109fb726d48Sopenharmony_ci    let tableHeadStyle: HTMLDivElement | undefined | null = this.queryTableEl?.shadowRoot?.querySelector(
110fb726d48Sopenharmony_ci      'div.th'
111fb726d48Sopenharmony_ci    ) as HTMLDivElement;
112fb726d48Sopenharmony_ci    if (tableHeadStyle && tableHeadStyle.hasChildNodes()) {
113fb726d48Sopenharmony_ci      for (let index = 0; index < tableHeadStyle.children.length; index++) {
114fb726d48Sopenharmony_ci        // @ts-ignore
115fb726d48Sopenharmony_ci        tableHeadStyle.children[index].style.gridArea = null;
116fb726d48Sopenharmony_ci      }
117fb726d48Sopenharmony_ci    }
118fb726d48Sopenharmony_ci    this.queryTableEl!.style.height = '100%';
119fb726d48Sopenharmony_ci  }
120fb726d48Sopenharmony_ci
121fb726d48Sopenharmony_ci  private async copyTableData(): Promise<void> {
122fb726d48Sopenharmony_ci    let copyResult = '';
123fb726d48Sopenharmony_ci    for (let keyListKey of this.keyList!) {
124fb726d48Sopenharmony_ci      copyResult += `${keyListKey}\t`;
125fb726d48Sopenharmony_ci    }
126fb726d48Sopenharmony_ci    copyResult += '\n';
127fb726d48Sopenharmony_ci    let copyData: unknown[];
128fb726d48Sopenharmony_ci    if (this.statDataArray.length > maxPageSize) {
129fb726d48Sopenharmony_ci      copyData = this.sliceData;
130fb726d48Sopenharmony_ci    } else {
131fb726d48Sopenharmony_ci      copyData = this.statDataArray;
132fb726d48Sopenharmony_ci    }
133fb726d48Sopenharmony_ci    for (const value of copyData) {
134fb726d48Sopenharmony_ci      this.keyList?.forEach((key) => {
135fb726d48Sopenharmony_ci        // @ts-ignore
136fb726d48Sopenharmony_ci        copyResult += `${value[key]}\t`;
137fb726d48Sopenharmony_ci      });
138fb726d48Sopenharmony_ci      copyResult += '\n';
139fb726d48Sopenharmony_ci    }
140fb726d48Sopenharmony_ci    await navigator.clipboard.writeText(copyResult);
141fb726d48Sopenharmony_ci  }
142fb726d48Sopenharmony_ci
143fb726d48Sopenharmony_ci  selectEventListener = (event: KeyboardEvent): void => {
144fb726d48Sopenharmony_ci    let enterKey = 13;
145fb726d48Sopenharmony_ci    if (event.ctrlKey && event.keyCode === enterKey) {
146fb726d48Sopenharmony_ci      SpStatisticsHttpUtil.addOrdinaryVisitAction({
147fb726d48Sopenharmony_ci        event: 'query',
148fb726d48Sopenharmony_ci        action: 'query',
149fb726d48Sopenharmony_ci      });
150fb726d48Sopenharmony_ci      this.statDataArray = [];
151fb726d48Sopenharmony_ci      this.keyList = [];
152fb726d48Sopenharmony_ci      this.response!.innerHTML = '';
153fb726d48Sopenharmony_ci      this.queryTableEl!.innerHTML = '';
154fb726d48Sopenharmony_ci      this.pagination!.style.display = 'none';
155fb726d48Sopenharmony_ci      if (this.isSupportSql) {
156fb726d48Sopenharmony_ci        this.executeSql(this.selector!.value);
157fb726d48Sopenharmony_ci      } else {
158fb726d48Sopenharmony_ci        this.querySize!.textContent = this.querySqlErrorText;
159fb726d48Sopenharmony_ci        this.queryTableEl!.dataSource = [];
160fb726d48Sopenharmony_ci        this.response!.innerHTML = '';
161fb726d48Sopenharmony_ci        return;
162fb726d48Sopenharmony_ci      }
163fb726d48Sopenharmony_ci    }
164fb726d48Sopenharmony_ci  };
165fb726d48Sopenharmony_ci
166fb726d48Sopenharmony_ci  private executeSql(sql: string): void {
167fb726d48Sopenharmony_ci    this.progressLoad!.loading = true;
168fb726d48Sopenharmony_ci    if (this.querySize) {
169fb726d48Sopenharmony_ci      this.querySize!.title = `${sql}`;
170fb726d48Sopenharmony_ci    }
171fb726d48Sopenharmony_ci    queryCustomizeSelect(sql).then((resultList): void => {
172fb726d48Sopenharmony_ci      if (resultList && resultList.length > 0) {
173fb726d48Sopenharmony_ci        this.statDataArray = resultList;
174fb726d48Sopenharmony_ci        //@ts-ignore
175fb726d48Sopenharmony_ci        this.keyList = Object.keys(resultList[0]);
176fb726d48Sopenharmony_ci        this.querySize!.textContent = `Query result - ${this.statDataArray.length} counts.` + `(${sql})`;
177fb726d48Sopenharmony_ci        this.initDataElement();
178fb726d48Sopenharmony_ci        this.response!.appendChild(this.queryTableEl!);
179fb726d48Sopenharmony_ci        this.setPageNationTableEl();
180fb726d48Sopenharmony_ci        setTimeout(() => {
181fb726d48Sopenharmony_ci          if (this.parentElement?.clientHeight !== 0) {
182fb726d48Sopenharmony_ci            this.queryTableEl!.style.height = '100%';
183fb726d48Sopenharmony_ci            this.queryTableEl!.reMeauseHeight();
184fb726d48Sopenharmony_ci          }
185fb726d48Sopenharmony_ci        }, 300);
186fb726d48Sopenharmony_ci      } else {
187fb726d48Sopenharmony_ci        this.querySize!.textContent = `Query result - ${this.statDataArray.length} counts.` + `(${sql})`;
188fb726d48Sopenharmony_ci        this.progressLoad!.loading = false;
189fb726d48Sopenharmony_ci      }
190fb726d48Sopenharmony_ci    });
191fb726d48Sopenharmony_ci  }
192fb726d48Sopenharmony_ci
193fb726d48Sopenharmony_ci  private setPageNationTableEl(): void {
194fb726d48Sopenharmony_ci    let timeOutTs: number = 200;
195fb726d48Sopenharmony_ci    let indexNumber = 1;
196fb726d48Sopenharmony_ci    setTimeout(() => {
197fb726d48Sopenharmony_ci      let total = this.statDataArray.length;
198fb726d48Sopenharmony_ci      if (total > maxPageSize) {
199fb726d48Sopenharmony_ci        this.pagination!.style.display = 'block';
200fb726d48Sopenharmony_ci        this.pagination!.style.opacity = '1';
201fb726d48Sopenharmony_ci        const option = {
202fb726d48Sopenharmony_ci          current: 1,
203fb726d48Sopenharmony_ci          total: total,
204fb726d48Sopenharmony_ci          pageSize: pageSize,
205fb726d48Sopenharmony_ci          change: (num: number): void => {
206fb726d48Sopenharmony_ci            this.sliceData = this.statDataArray!.slice((num - indexNumber) * pageSize, num * pageSize);
207fb726d48Sopenharmony_ci            this.queryTableEl!.recycleDataSource = this.sliceData;
208fb726d48Sopenharmony_ci          },
209fb726d48Sopenharmony_ci        };
210fb726d48Sopenharmony_ci        new PageNation(this.pagination, option);
211fb726d48Sopenharmony_ci      } else {
212fb726d48Sopenharmony_ci        this.pagination!.style.opacity = '0';
213fb726d48Sopenharmony_ci        this.queryTableEl!.recycleDataSource = this.statDataArray;
214fb726d48Sopenharmony_ci      }
215fb726d48Sopenharmony_ci      this.freshTableHeadResizeStyle();
216fb726d48Sopenharmony_ci      this.progressLoad!.loading = false;
217fb726d48Sopenharmony_ci    }, timeOutTs);
218fb726d48Sopenharmony_ci  }
219fb726d48Sopenharmony_ci
220fb726d48Sopenharmony_ci  reset(): void {
221fb726d48Sopenharmony_ci    this.pagination!.style.opacity = '0';
222fb726d48Sopenharmony_ci    this.response!.innerHTML = '';
223fb726d48Sopenharmony_ci    this.keyList = [];
224fb726d48Sopenharmony_ci    this.statDataArray = [];
225fb726d48Sopenharmony_ci    this.selector!.value = '';
226fb726d48Sopenharmony_ci    this.querySize!.textContent = 'Please enter a query.';
227fb726d48Sopenharmony_ci    this.resizeSqlHeight().then();
228fb726d48Sopenharmony_ci  }
229fb726d48Sopenharmony_ci
230fb726d48Sopenharmony_ci  private checkSafetySelectSql(): boolean {
231fb726d48Sopenharmony_ci    if (this.selector?.value.trim() === '') {
232fb726d48Sopenharmony_ci      this.querySqlErrorText = 'Please enter a query.';
233fb726d48Sopenharmony_ci      this.querySize!.textContent = this.querySqlErrorText;
234fb726d48Sopenharmony_ci      return false;
235fb726d48Sopenharmony_ci    } else {
236fb726d48Sopenharmony_ci      let queryNormalLength = 15;
237fb726d48Sopenharmony_ci      if (
238fb726d48Sopenharmony_ci        this.selector!.value.length < queryNormalLength ||
239fb726d48Sopenharmony_ci        !this.selector?.value.toLowerCase().trim().startsWith('select')
240fb726d48Sopenharmony_ci      ) {
241fb726d48Sopenharmony_ci        this.querySqlErrorText = `Query result - (Error):  
242fb726d48Sopenharmony_ci        ${this.selector!.value}.`;
243fb726d48Sopenharmony_ci        return false;
244fb726d48Sopenharmony_ci      }
245fb726d48Sopenharmony_ci      if (this.notSupportList && this.notSupportList.length > 0) {
246fb726d48Sopenharmony_ci        for (let index = 0; index < this.notSupportList.length; index++) {
247fb726d48Sopenharmony_ci          let regexStr = new RegExp(this.notSupportList[index], 'i');
248fb726d48Sopenharmony_ci          if (regexStr.test(this.selector!.value)) {
249fb726d48Sopenharmony_ci            this.querySqlErrorText = `Query result - (Error):  
250fb726d48Sopenharmony_ci            ${this.selector!.value}.`;
251fb726d48Sopenharmony_ci            return false;
252fb726d48Sopenharmony_ci          }
253fb726d48Sopenharmony_ci        }
254fb726d48Sopenharmony_ci      }
255fb726d48Sopenharmony_ci    }
256fb726d48Sopenharmony_ci    return true;
257fb726d48Sopenharmony_ci  }
258fb726d48Sopenharmony_ci
259fb726d48Sopenharmony_ci  private initDataElement(): void {
260fb726d48Sopenharmony_ci    if (this.keyList) {
261fb726d48Sopenharmony_ci      info('Metric query Table Colum size is: ', this.keyList.length);
262fb726d48Sopenharmony_ci      this.keyList.forEach((item) => {
263fb726d48Sopenharmony_ci        let htmlElement = document.createElement('lit-table-column') as LitTableColumn;
264fb726d48Sopenharmony_ci        htmlElement.setAttribute('title', item);
265fb726d48Sopenharmony_ci        htmlElement.setAttribute('data-index', item);
266fb726d48Sopenharmony_ci        htmlElement.setAttribute('key', item);
267fb726d48Sopenharmony_ci        htmlElement.setAttribute('align', 'flex-start');
268fb726d48Sopenharmony_ci        htmlElement.setAttribute('height', '32px');
269fb726d48Sopenharmony_ci        this.queryTableEl!.appendChild(htmlElement);
270fb726d48Sopenharmony_ci      });
271fb726d48Sopenharmony_ci    }
272fb726d48Sopenharmony_ci  }
273fb726d48Sopenharmony_ci
274fb726d48Sopenharmony_ci  connectedCallback(): void {
275fb726d48Sopenharmony_ci    // Listen to the sql execution of the query
276fb726d48Sopenharmony_ci    this.addEventListener('keydown', this.selectEventListener);
277fb726d48Sopenharmony_ci    this.selector!.addEventListener('input', this.inputSqlListener);
278fb726d48Sopenharmony_ci    this.selector!.addEventListener('change', this.inputSqlListener);
279fb726d48Sopenharmony_ci    this.selector!.addEventListener('keydown', this.deleteSqlListener);
280fb726d48Sopenharmony_ci    this.shadowRoot
281fb726d48Sopenharmony_ci      ?.querySelectorAll<LitIcon>('.runButton')
282fb726d48Sopenharmony_ci      .forEach((it) => it.addEventListener('click', this.runSqlListener));
283fb726d48Sopenharmony_ci  }
284fb726d48Sopenharmony_ci
285fb726d48Sopenharmony_ci  runSqlListener = (e: Event): void => {
286fb726d48Sopenharmony_ci    this.scrollTo(0, 0);
287fb726d48Sopenharmony_ci    this.statDataArray = [];
288fb726d48Sopenharmony_ci    this.keyList = [];
289fb726d48Sopenharmony_ci    this.response!.innerHTML = '';
290fb726d48Sopenharmony_ci    this.queryTableEl!.innerHTML = '';
291fb726d48Sopenharmony_ci    this.pagination!.style.display = 'none';
292fb726d48Sopenharmony_ci    let previousSibling = (e.target as HTMLDivElement).previousElementSibling;
293fb726d48Sopenharmony_ci    if (previousSibling && previousSibling instanceof HTMLDivElement) {
294fb726d48Sopenharmony_ci      const content = previousSibling.textContent;
295fb726d48Sopenharmony_ci      this.executeSql(content!);
296fb726d48Sopenharmony_ci    }
297fb726d48Sopenharmony_ci  };
298fb726d48Sopenharmony_ci
299fb726d48Sopenharmony_ci  private deleteSqlListener = (event: KeyboardEvent): void => {
300fb726d48Sopenharmony_ci    if (event.key === 'Backspace') {
301fb726d48Sopenharmony_ci      this.resizeSqlHeight().then();
302fb726d48Sopenharmony_ci      this.isSupportSql = this.checkSafetySelectSql();
303fb726d48Sopenharmony_ci    }
304fb726d48Sopenharmony_ci  };
305fb726d48Sopenharmony_ci
306fb726d48Sopenharmony_ci  private async resizeSqlHeight(): Promise<void> {
307fb726d48Sopenharmony_ci    let minRowNumber = 10;
308fb726d48Sopenharmony_ci    let indexNumber = 1;
309fb726d48Sopenharmony_ci    let multipleNumber = 1.2;
310fb726d48Sopenharmony_ci    let paddingNumber = 2;
311fb726d48Sopenharmony_ci    let valueLength = this.selector?.value.split('\n').length;
312fb726d48Sopenharmony_ci    let rowNumber = Number(valueLength) - indexNumber;
313fb726d48Sopenharmony_ci    let selectHeight = '3.2em';
314fb726d48Sopenharmony_ci    if (rowNumber > 0) {
315fb726d48Sopenharmony_ci      if (rowNumber <= minRowNumber) {
316fb726d48Sopenharmony_ci        let allLength = multipleNumber * rowNumber + paddingNumber;
317fb726d48Sopenharmony_ci        selectHeight = `${allLength}em`;
318fb726d48Sopenharmony_ci      } else {
319fb726d48Sopenharmony_ci        selectHeight = '14em';
320fb726d48Sopenharmony_ci      }
321fb726d48Sopenharmony_ci    }
322fb726d48Sopenharmony_ci    // @ts-ignore
323fb726d48Sopenharmony_ci    this.selector?.style.height = selectHeight;
324fb726d48Sopenharmony_ci  }
325fb726d48Sopenharmony_ci
326fb726d48Sopenharmony_ci  private inputSqlListener = async (): Promise<void> => {
327fb726d48Sopenharmony_ci    this.resizeSqlHeight().then();
328fb726d48Sopenharmony_ci    this.isSupportSql = this.checkSafetySelectSql();
329fb726d48Sopenharmony_ci  };
330fb726d48Sopenharmony_ci
331fb726d48Sopenharmony_ci  disconnectedCallback(): void {
332fb726d48Sopenharmony_ci    this.removeEventListener('keydown', this.selectEventListener);
333fb726d48Sopenharmony_ci    this.selector!.removeEventListener('input', this.inputSqlListener);
334fb726d48Sopenharmony_ci    this.selector!.removeEventListener('change', this.inputSqlListener);
335fb726d48Sopenharmony_ci    this.selector!.removeEventListener('keydown', this.deleteSqlListener);
336fb726d48Sopenharmony_ci  }
337fb726d48Sopenharmony_ci
338fb726d48Sopenharmony_ci  attributeChangedCallback(name: string, oldValue: string, newValue: string): void {
339fb726d48Sopenharmony_ci    let queryDataSty: HTMLDivElement | undefined | null = this.queryTableEl?.shadowRoot?.querySelector(
340fb726d48Sopenharmony_ci      'div.tbody'
341fb726d48Sopenharmony_ci    ) as HTMLDivElement;
342fb726d48Sopenharmony_ci    if (queryDataSty && queryDataSty.hasChildNodes()) {
343fb726d48Sopenharmony_ci      for (let index = 0; index < queryDataSty.children.length; index++) {
344fb726d48Sopenharmony_ci        // @ts-ignore
345fb726d48Sopenharmony_ci        queryDataSty.children[index].style.backgroundColor = 'var(--dark-background5,#F6F6F6)';
346fb726d48Sopenharmony_ci      }
347fb726d48Sopenharmony_ci    }
348fb726d48Sopenharmony_ci  }
349fb726d48Sopenharmony_ci
350fb726d48Sopenharmony_ci  initHtml(): string {
351fb726d48Sopenharmony_ci    return SpQuerySQLHtml;
352fb726d48Sopenharmony_ci  }
353fb726d48Sopenharmony_ci}
354fb726d48Sopenharmony_ci
355fb726d48Sopenharmony_ciconst pageSize: number = 200000;
356fb726d48Sopenharmony_ciconst maxPageSize: number = 500000;
357