diff --git a/InfoLogger/lib/services/QueryService.js b/InfoLogger/lib/services/QueryService.js index 4d31d336e..2182bc124 100644 --- a/InfoLogger/lib/services/QueryService.js +++ b/InfoLogger/lib/services/QueryService.js @@ -102,9 +102,10 @@ class QueryService { const criteriaString = this._getCriteriaAsString(criteria); const requestRows = `SELECT * FROM \`messages\` ${criteriaString} ORDER BY \`TIMESTAMP\` LIMIT ?;`; const queryValues = [...values, limit]; + const queryAsString = processPreparedSQLStatement(requestRows, values, limit); const startTime = Date.now(); // ms - this._logger.debugMessage(`SQL to execute: ${processPreparedSQLStatement(requestRows, values, limit)}`); + this._logger.debugMessage(`SQL to execute: ${queryAsString}`); let rows = []; let connection = null; @@ -144,7 +145,7 @@ class QueryService { count: rows.length, limit: limit, time: totalTime, // ms - queryAsString: this._getSQLQueryAsString(criteriaString, limit), + queryAsString, }; } @@ -186,16 +187,6 @@ class QueryService { return criteria && criteria.length ? `WHERE ${criteria.join(' AND ')}` : ''; } - /** - * Get the SQL Query used as a string - * @param {string} criteriaVerbose - criteria as string in SQL format - * @param {number} limit - limit of number of messages - * @returns {string} - SQL Query as string - */ - _getSQLQueryAsString(criteriaVerbose, limit) { - return `SELECT * FROM \`messages\` ${criteriaVerbose} ORDER BY \`TIMESTAMP\` LIMIT ${limit}`; - } - /** * Translates `filters` from client side to SQL condition to put on WHERE clause * diff --git a/InfoLogger/test/lib/services/mocha-query-service.test.js b/InfoLogger/test/lib/services/mocha-query-service.test.js index b5a017b01..1be3a2f85 100644 --- a/InfoLogger/test/lib/services/mocha-query-service.test.js +++ b/InfoLogger/test/lib/services/mocha-query-service.test.js @@ -329,8 +329,9 @@ describe('\'QueryService\' test suite', () => { }); it('should successfully return result when filters are provided for querying', async () => { - const query = 'SELECT * FROM `messages` WHERE `timestamp`>=? AND `timestamp`<=? AND `hostname` = ? ' - + 'AND NOT(`hostname` = ? AND `hostname` IS NOT NULL) AND `severity` IN (?) ORDER BY `TIMESTAMP` LIMIT 10'; + const query = 'SELECT * FROM `messages` WHERE `timestamp`>=\'1563794601.351\' AND `timestamp`<=\'1563794661.354\' ' + + 'AND `hostname` = \'test\' AND NOT(`hostname` = \'testEx\' AND `hostname` IS NOT NULL) ' + + 'AND `severity` IN (\'D\',\'W\') ORDER BY `TIMESTAMP` LIMIT 10;'; const sqlDataSource = new QueryService(); const connection = {