mirror of
				https://github.com/Fabio286/antares.git
				synced 2025-06-05 21:59:22 +02:00 
			
		
		
		
	fix: error when launching queries without a result from query tabs
This commit is contained in:
		@@ -285,15 +285,20 @@ export class AntaresConnector {
 | 
			
		||||
      switch (this._client) { // TODO: uniform fields with every client type, needed table name and fields array
 | 
			
		||||
         case 'maria':
 | 
			
		||||
         case 'mysql': {
 | 
			
		||||
            const { rows, fields } = await new Promise((resolve, reject) => {
 | 
			
		||||
               this._connection.query(sql, (err, rows, fields) => {
 | 
			
		||||
            const { rows, report, fields } = await new Promise((resolve, reject) => {
 | 
			
		||||
               this._connection.query(sql, (err, response, fields) => {
 | 
			
		||||
                  if (err)
 | 
			
		||||
                     reject(err);
 | 
			
		||||
                  else
 | 
			
		||||
                     resolve({ rows, fields });
 | 
			
		||||
                  else {
 | 
			
		||||
                     resolve({
 | 
			
		||||
                        rows: Array.isArray(response) ? response : false,
 | 
			
		||||
                        report: !Array.isArray(response) ? response : false,
 | 
			
		||||
                        fields
 | 
			
		||||
                     });
 | 
			
		||||
                  }
 | 
			
		||||
               });
 | 
			
		||||
            });
 | 
			
		||||
            return { rows, fields };
 | 
			
		||||
            return { rows, report, fields };
 | 
			
		||||
         }
 | 
			
		||||
         case 'mssql': {
 | 
			
		||||
            const results = await this._connection.request().query(sql);
 | 
			
		||||
 
 | 
			
		||||
@@ -201,6 +201,7 @@ export default {
 | 
			
		||||
      max-width: 320px;
 | 
			
		||||
      pointer-events: none;
 | 
			
		||||
      text-overflow: ellipsis;
 | 
			
		||||
      overflow: hidden;
 | 
			
		||||
      transition: opacity 0.2s;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,9 @@
 | 
			
		||||
               <div v-if="results.rows">
 | 
			
		||||
                  {{ $t('word.results') }}: <b>{{ results.rows.length }}</b>
 | 
			
		||||
               </div>
 | 
			
		||||
               <div v-if="results.report">
 | 
			
		||||
                  {{ $t('message.affectedRows') }}: <b>{{ results.report.affectedRows }}</b>
 | 
			
		||||
               </div>
 | 
			
		||||
               <div v-if="workspace.breadcrumbs.schema">
 | 
			
		||||
                  {{ $t('word.schema') }}: <b>{{ workspace.breadcrumbs.schema }}</b>
 | 
			
		||||
               </div>
 | 
			
		||||
@@ -94,8 +97,7 @@ export default {
 | 
			
		||||
      async runQuery (query) {
 | 
			
		||||
         if (!query) return;
 | 
			
		||||
         this.isQuering = true;
 | 
			
		||||
         this.results = {};
 | 
			
		||||
         this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [] });
 | 
			
		||||
         this.clearTabData();
 | 
			
		||||
 | 
			
		||||
         try { // Query Data
 | 
			
		||||
            const params = {
 | 
			
		||||
@@ -107,33 +109,54 @@ export default {
 | 
			
		||||
            const { status, response } = await Connection.rawQuery(params);
 | 
			
		||||
            if (status === 'success') {
 | 
			
		||||
               this.results = response;
 | 
			
		||||
               this.selectedFields = response.fields.map(field => field.orgName);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
               this.addNotification({ status: 'error', message: response });
 | 
			
		||||
         }
 | 
			
		||||
         catch (err) {
 | 
			
		||||
            this.addNotification({ status: 'error', message: err.stack });
 | 
			
		||||
         }
 | 
			
		||||
               if (response.rows) { // if is a select
 | 
			
		||||
                  this.selectedFields = response.fields.map(field => field.orgName);
 | 
			
		||||
 | 
			
		||||
         try { // Table data
 | 
			
		||||
            const params = {
 | 
			
		||||
               uid: this.connection.uid,
 | 
			
		||||
               schema: this.schema,
 | 
			
		||||
               table: this.table
 | 
			
		||||
            };
 | 
			
		||||
                  try { // Table data
 | 
			
		||||
                     const params = {
 | 
			
		||||
                        uid: this.connection.uid,
 | 
			
		||||
                        schema: this.schema,
 | 
			
		||||
                        table: this.table
 | 
			
		||||
                     };
 | 
			
		||||
 | 
			
		||||
            const { status, response } = await Tables.getTableColumns(params);
 | 
			
		||||
                     const { status, response } = await Tables.getTableColumns(params);
 | 
			
		||||
 | 
			
		||||
            if (status === 'success') {
 | 
			
		||||
               let fields = response.filter(field => this.selectedFields.includes(field.name));
 | 
			
		||||
               if (this.selectedFields.length) {
 | 
			
		||||
                  fields = fields.map((field, index) => {
 | 
			
		||||
                     return { ...field, alias: this.results.fields[index].name };
 | 
			
		||||
                  });
 | 
			
		||||
                     if (status === 'success') {
 | 
			
		||||
                        let fields = response.filter(field => this.selectedFields.includes(field.name));
 | 
			
		||||
                        if (this.selectedFields.length) {
 | 
			
		||||
                           fields = fields.map((field, index) => {
 | 
			
		||||
                              return { ...field, alias: this.results.fields[index].name };
 | 
			
		||||
                           });
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields });
 | 
			
		||||
                     }
 | 
			
		||||
                     else
 | 
			
		||||
                        this.addNotification({ status: 'error', message: response });
 | 
			
		||||
                  }
 | 
			
		||||
                  catch (err) {
 | 
			
		||||
                     this.addNotification({ status: 'error', message: err.stack });
 | 
			
		||||
                  }
 | 
			
		||||
 | 
			
		||||
                  try { // Key usage (foreign keys)
 | 
			
		||||
                     const params = {
 | 
			
		||||
                        uid: this.connection.uid,
 | 
			
		||||
                        schema: this.schema,
 | 
			
		||||
                        table: this.table
 | 
			
		||||
                     };
 | 
			
		||||
 | 
			
		||||
                     const { status, response } = await Tables.getKeyUsage(params);
 | 
			
		||||
                     if (status === 'success')
 | 
			
		||||
                        this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: response });
 | 
			
		||||
                     else
 | 
			
		||||
                        this.addNotification({ status: 'error', message: response });
 | 
			
		||||
                  }
 | 
			
		||||
                  catch (err) {
 | 
			
		||||
                     this.addNotification({ status: 'error', message: err.stack });
 | 
			
		||||
                  }
 | 
			
		||||
               }
 | 
			
		||||
               else { // if is a query without results
 | 
			
		||||
               }
 | 
			
		||||
 | 
			
		||||
               this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields });
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
               this.addNotification({ status: 'error', message: response });
 | 
			
		||||
@@ -142,28 +165,15 @@ export default {
 | 
			
		||||
            this.addNotification({ status: 'error', message: err.stack });
 | 
			
		||||
         }
 | 
			
		||||
 | 
			
		||||
         try { // Key usage (foreign keys)
 | 
			
		||||
            const params = {
 | 
			
		||||
               uid: this.connection.uid,
 | 
			
		||||
               schema: this.schema,
 | 
			
		||||
               table: this.table
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            const { status, response } = await Tables.getKeyUsage(params);
 | 
			
		||||
            if (status === 'success')
 | 
			
		||||
               this.setTabKeyUsage({ cUid: this.connection.uid, tUid: this.tabUid, keyUsage: response });
 | 
			
		||||
            else
 | 
			
		||||
               this.addNotification({ status: 'error', message: response });
 | 
			
		||||
         }
 | 
			
		||||
         catch (err) {
 | 
			
		||||
            this.addNotification({ status: 'error', message: err.stack });
 | 
			
		||||
         }
 | 
			
		||||
 | 
			
		||||
         this.isQuering = false;
 | 
			
		||||
         this.lastQuery = query;
 | 
			
		||||
      },
 | 
			
		||||
      reloadTable () {
 | 
			
		||||
         this.runQuery(this.lastQuery);
 | 
			
		||||
      },
 | 
			
		||||
      clearTabData () {
 | 
			
		||||
         this.results = {};
 | 
			
		||||
         this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields: [] });
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -69,7 +69,8 @@ module.exports = {
 | 
			
		||||
      uploadFile: 'Upload file',
 | 
			
		||||
      addNewRow: 'Add new row',
 | 
			
		||||
      numberOfInserts: 'Number of inserts',
 | 
			
		||||
      openNewTab: 'Open a new tab'
 | 
			
		||||
      openNewTab: 'Open a new tab',
 | 
			
		||||
      affectedRows: 'Affected rows'
 | 
			
		||||
   },
 | 
			
		||||
   // Date and Time
 | 
			
		||||
   short: {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user