How correctly execute sql statements to Oracle database from Node.JS?
up vote
0
down vote
favorite
I am new in Node.JS ecosystem. Don't throw tomatoes at me please. I need some advice.
I am trying connect Node.JS
project with remote Oracle 12c
database. I use oracledb driver for this task.
From error I understand that problem with Promise
and parameters like start_date
and end_date
from url not inserted in SQL statement which I use in controller. How to fix this problems?
ERROR:
(node:39204) UnhandledPromiseRejectionWarning: Error: ORA-01036: illegal variable name/number
(node:39204) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:39204) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
URL format: GET /period/?start_date=2018-10-01&end_date=2018-10-31
routes/articles.js:
const express = require('express');
const router = express.Router();
const articleControllers = require('../controllers/articles');
router.get('/period', articleControllers.get_period_articles);
module.exports = router;
controllers/articles.js:
const oracleDatabase = require('modules/oracle_database');
async function get_period_articles(req, res, next) {
try {
let start_date = req.query.start_date;
let end_date = req.query.end_date;
const binds = {};
binds.start_date = start_date;
binds.end_date = end_date;
let query = `
SELECT * FROM ArticleTable
WHERE
CREATE_DATE BETWEEN TO_DATE(':start_date', 'YYYY-MM-DD') AND TO_DATE(':end_date', 'YYYY-MM-DD');
`;
const result = oracleDatabase.executeSQLStatement(query, binds);
console.log(result); // <- undefined
} catch (error) {
next(error);
}
}
module.exports.get_period_incidents = get_period_incidents;
modules/oracle_database.js:
const oracledb = require('oracledb');
const oracleDatabaseConfiguration = require('../config/oracle_database');
async function initialization() {
await oracledb.createPool(oracleDatabaseConfiguration);
}
module.exports.initialization = initialization;
function executeSQLStatement(query, binds = , options = {}) {
return new Promise(async (resolve, reject) => {
let connection;
options.outFormat = oracledb.OBJECT;
options.autoCommit = true;
try {
connection = await oracledb.getConnection();
const result = await connection.execute(query, binds, options);
resolve(result);
} catch (error) {
reject(error);
} finally {
if (connection) {
try {
await connection.close();
} catch (error) {
console.log(error);
}
}
}
});
}
module.exports.executeSQLStatement = executeSQLStatement;
javascript node.js
add a comment |
up vote
0
down vote
favorite
I am new in Node.JS ecosystem. Don't throw tomatoes at me please. I need some advice.
I am trying connect Node.JS
project with remote Oracle 12c
database. I use oracledb driver for this task.
From error I understand that problem with Promise
and parameters like start_date
and end_date
from url not inserted in SQL statement which I use in controller. How to fix this problems?
ERROR:
(node:39204) UnhandledPromiseRejectionWarning: Error: ORA-01036: illegal variable name/number
(node:39204) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:39204) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
URL format: GET /period/?start_date=2018-10-01&end_date=2018-10-31
routes/articles.js:
const express = require('express');
const router = express.Router();
const articleControllers = require('../controllers/articles');
router.get('/period', articleControllers.get_period_articles);
module.exports = router;
controllers/articles.js:
const oracleDatabase = require('modules/oracle_database');
async function get_period_articles(req, res, next) {
try {
let start_date = req.query.start_date;
let end_date = req.query.end_date;
const binds = {};
binds.start_date = start_date;
binds.end_date = end_date;
let query = `
SELECT * FROM ArticleTable
WHERE
CREATE_DATE BETWEEN TO_DATE(':start_date', 'YYYY-MM-DD') AND TO_DATE(':end_date', 'YYYY-MM-DD');
`;
const result = oracleDatabase.executeSQLStatement(query, binds);
console.log(result); // <- undefined
} catch (error) {
next(error);
}
}
module.exports.get_period_incidents = get_period_incidents;
modules/oracle_database.js:
const oracledb = require('oracledb');
const oracleDatabaseConfiguration = require('../config/oracle_database');
async function initialization() {
await oracledb.createPool(oracleDatabaseConfiguration);
}
module.exports.initialization = initialization;
function executeSQLStatement(query, binds = , options = {}) {
return new Promise(async (resolve, reject) => {
let connection;
options.outFormat = oracledb.OBJECT;
options.autoCommit = true;
try {
connection = await oracledb.getConnection();
const result = await connection.execute(query, binds, options);
resolve(result);
} catch (error) {
reject(error);
} finally {
if (connection) {
try {
await connection.close();
} catch (error) {
console.log(error);
}
}
}
});
}
module.exports.executeSQLStatement = executeSQLStatement;
javascript node.js
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am new in Node.JS ecosystem. Don't throw tomatoes at me please. I need some advice.
I am trying connect Node.JS
project with remote Oracle 12c
database. I use oracledb driver for this task.
From error I understand that problem with Promise
and parameters like start_date
and end_date
from url not inserted in SQL statement which I use in controller. How to fix this problems?
ERROR:
(node:39204) UnhandledPromiseRejectionWarning: Error: ORA-01036: illegal variable name/number
(node:39204) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:39204) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
URL format: GET /period/?start_date=2018-10-01&end_date=2018-10-31
routes/articles.js:
const express = require('express');
const router = express.Router();
const articleControllers = require('../controllers/articles');
router.get('/period', articleControllers.get_period_articles);
module.exports = router;
controllers/articles.js:
const oracleDatabase = require('modules/oracle_database');
async function get_period_articles(req, res, next) {
try {
let start_date = req.query.start_date;
let end_date = req.query.end_date;
const binds = {};
binds.start_date = start_date;
binds.end_date = end_date;
let query = `
SELECT * FROM ArticleTable
WHERE
CREATE_DATE BETWEEN TO_DATE(':start_date', 'YYYY-MM-DD') AND TO_DATE(':end_date', 'YYYY-MM-DD');
`;
const result = oracleDatabase.executeSQLStatement(query, binds);
console.log(result); // <- undefined
} catch (error) {
next(error);
}
}
module.exports.get_period_incidents = get_period_incidents;
modules/oracle_database.js:
const oracledb = require('oracledb');
const oracleDatabaseConfiguration = require('../config/oracle_database');
async function initialization() {
await oracledb.createPool(oracleDatabaseConfiguration);
}
module.exports.initialization = initialization;
function executeSQLStatement(query, binds = , options = {}) {
return new Promise(async (resolve, reject) => {
let connection;
options.outFormat = oracledb.OBJECT;
options.autoCommit = true;
try {
connection = await oracledb.getConnection();
const result = await connection.execute(query, binds, options);
resolve(result);
} catch (error) {
reject(error);
} finally {
if (connection) {
try {
await connection.close();
} catch (error) {
console.log(error);
}
}
}
});
}
module.exports.executeSQLStatement = executeSQLStatement;
javascript node.js
I am new in Node.JS ecosystem. Don't throw tomatoes at me please. I need some advice.
I am trying connect Node.JS
project with remote Oracle 12c
database. I use oracledb driver for this task.
From error I understand that problem with Promise
and parameters like start_date
and end_date
from url not inserted in SQL statement which I use in controller. How to fix this problems?
ERROR:
(node:39204) UnhandledPromiseRejectionWarning: Error: ORA-01036: illegal variable name/number
(node:39204) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:39204) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
URL format: GET /period/?start_date=2018-10-01&end_date=2018-10-31
routes/articles.js:
const express = require('express');
const router = express.Router();
const articleControllers = require('../controllers/articles');
router.get('/period', articleControllers.get_period_articles);
module.exports = router;
controllers/articles.js:
const oracleDatabase = require('modules/oracle_database');
async function get_period_articles(req, res, next) {
try {
let start_date = req.query.start_date;
let end_date = req.query.end_date;
const binds = {};
binds.start_date = start_date;
binds.end_date = end_date;
let query = `
SELECT * FROM ArticleTable
WHERE
CREATE_DATE BETWEEN TO_DATE(':start_date', 'YYYY-MM-DD') AND TO_DATE(':end_date', 'YYYY-MM-DD');
`;
const result = oracleDatabase.executeSQLStatement(query, binds);
console.log(result); // <- undefined
} catch (error) {
next(error);
}
}
module.exports.get_period_incidents = get_period_incidents;
modules/oracle_database.js:
const oracledb = require('oracledb');
const oracleDatabaseConfiguration = require('../config/oracle_database');
async function initialization() {
await oracledb.createPool(oracleDatabaseConfiguration);
}
module.exports.initialization = initialization;
function executeSQLStatement(query, binds = , options = {}) {
return new Promise(async (resolve, reject) => {
let connection;
options.outFormat = oracledb.OBJECT;
options.autoCommit = true;
try {
connection = await oracledb.getConnection();
const result = await connection.execute(query, binds, options);
resolve(result);
} catch (error) {
reject(error);
} finally {
if (connection) {
try {
await connection.close();
} catch (error) {
console.log(error);
}
}
}
});
}
module.exports.executeSQLStatement = executeSQLStatement;
javascript node.js
javascript node.js
asked Nov 22 at 9:42
Nurzhan Nogerbek
82921941
82921941
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Finally I found the problem.
In controllers/articles.js
file change query to:
let query = `
SELECT * FROM ArticleTable
WHERE CREATE_DATE BETWEEN TO_DATE(:start_date, 'YYYY-MM-DD') AND TO_DATE(:end_date, 'YYYY-MM-DD');
`;
As you can see I just remove apostrophe '
.
Also in the same file I change to:
const result = await oracleDatabase.executeSQLStatement(query, binds);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427949%2fhow-correctly-execute-sql-statements-to-oracle-database-from-node-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Finally I found the problem.
In controllers/articles.js
file change query to:
let query = `
SELECT * FROM ArticleTable
WHERE CREATE_DATE BETWEEN TO_DATE(:start_date, 'YYYY-MM-DD') AND TO_DATE(:end_date, 'YYYY-MM-DD');
`;
As you can see I just remove apostrophe '
.
Also in the same file I change to:
const result = await oracleDatabase.executeSQLStatement(query, binds);
add a comment |
up vote
0
down vote
accepted
Finally I found the problem.
In controllers/articles.js
file change query to:
let query = `
SELECT * FROM ArticleTable
WHERE CREATE_DATE BETWEEN TO_DATE(:start_date, 'YYYY-MM-DD') AND TO_DATE(:end_date, 'YYYY-MM-DD');
`;
As you can see I just remove apostrophe '
.
Also in the same file I change to:
const result = await oracleDatabase.executeSQLStatement(query, binds);
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Finally I found the problem.
In controllers/articles.js
file change query to:
let query = `
SELECT * FROM ArticleTable
WHERE CREATE_DATE BETWEEN TO_DATE(:start_date, 'YYYY-MM-DD') AND TO_DATE(:end_date, 'YYYY-MM-DD');
`;
As you can see I just remove apostrophe '
.
Also in the same file I change to:
const result = await oracleDatabase.executeSQLStatement(query, binds);
Finally I found the problem.
In controllers/articles.js
file change query to:
let query = `
SELECT * FROM ArticleTable
WHERE CREATE_DATE BETWEEN TO_DATE(:start_date, 'YYYY-MM-DD') AND TO_DATE(:end_date, 'YYYY-MM-DD');
`;
As you can see I just remove apostrophe '
.
Also in the same file I change to:
const result = await oracleDatabase.executeSQLStatement(query, binds);
answered Nov 22 at 10:34
Nurzhan Nogerbek
82921941
82921941
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427949%2fhow-correctly-execute-sql-statements-to-oracle-database-from-node-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown