Skip to content
Snippets Groups Projects
Commit fea8787e authored by pdg16's avatar pdg16
Browse files

v1.11.17

parent a208643a
Branches
No related tags found
1 merge request!28Development
...@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file. ...@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## 1..11.16 - 2019-10-30 ## 1.11.17 - 2019-10-08
## Changed
- Fix query\_exec
## 1.11.16 - 2019-10-30
## Changed ## Changed
- University Teacher updated - University Teacher updated
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
"mocha": "^3.5.3", "mocha": "^3.5.3",
"monetdb-pool": "0.0.8", "monetdb-pool": "0.0.8",
"mongoose": "^4.13.17", "mongoose": "^4.13.17",
"natives": "^1.1.6",
"nconf": "^0.8.5", "nconf": "^0.8.5",
"node-uuid": "^1.4.8", "node-uuid": "^1.4.8",
"nodemailer": "^4.6.8", "nodemailer": "^4.6.8",
...@@ -60,6 +61,7 @@ ...@@ -60,6 +61,7 @@
"passport-http-bearer": "^1.0.1", "passport-http-bearer": "^1.0.1",
"passport-oauth2-client-password": "^0.1.2", "passport-oauth2-client-password": "^0.1.2",
"request": "^2.88.0", "request": "^2.88.0",
"sqlstring": "^2.3.1",
"squel": "^5.12.2", "squel": "^5.12.2",
"winston": "^2.4.4" "winston": "^2.4.4"
}, },
......
/*
Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
This file is part of simcaq-node.
simcaq-node is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
simcaq-node is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with simcaq-node. If not, see <https://www.gnu.org/licenses/>.
*/
const libs = `${process.cwd()}/libs`; const libs = `${process.cwd()}/libs`;
...@@ -5,6 +25,8 @@ const log = require(`${libs}/log`)(module); ...@@ -5,6 +25,8 @@ const log = require(`${libs}/log`)(module);
const conn = require(`${libs}/db/monet`); const conn = require(`${libs}/db/monet`);
const SqlString = require('sqlstring');
// Promise that executes an SQL query with optional parameters // Promise that executes an SQL query with optional parameters
// ``` // ```
// Examples: // Examples:
...@@ -17,26 +39,17 @@ const conn = require(`${libs}/db/monet`); ...@@ -17,26 +39,17 @@ const conn = require(`${libs}/db/monet`);
// ``` // ```
function execSqlQuery(sqlQuery, sqlQueryParams = []) { function execSqlQuery(sqlQuery, sqlQueryParams = []) {
log.debug(`Executing SQL query '${sqlQuery}' with params '${sqlQueryParams}'`); log.debug(`Executing SQL query '${sqlQuery}' with params '${sqlQueryParams}'`);
let queryStrWithParams = SqlString.format(sqlQuery, sqlQueryParams);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Prepare statement
conn.prepare(sqlQuery, true).then((dbQuery) => {
// Execute query // Execute query
dbQuery.exec(sqlQueryParams).then((dbResult) => { conn.query(queryStrWithParams, [], true).then((dbResult) => {
// release resources allocated for the prepared statement // release resources allocated for the prepared statement
dbQuery.release();
resolve(dbResult.data); resolve(dbResult.data);
}).catch((queryError) => { },(queryError) => {
log.error(`SQL query execution error: ${queryError.message}`); log.error(`SQL query execution error: ${queryError.message}`);
log.error(`SQL query: ${sqlQuery} with params: ${sqlQueryParams}`); log.error(`SQL query: ${sqlQuery} with params: ${sqlQueryParams}`);
// release resources allocated for the prepared statement
dbQuery.release();
reject(new Error(queryError.message)); reject(new Error(queryError.message));
}); });
}).catch((prepError) => {
log.error(`SQL prepared statement error: ${prepError.message}`);
log.error(`SQL query: ${sqlQuery} with params: ${sqlQueryParams}`);
reject(new Error(prepError.message));
});
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment