Closed VldMrgnn closed 3 years ago
Please paste the simplest possible code that makes the error.
Hello, I made an example like follows:
CREATE TABLE TESTDATE (
ID SMALLINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL,
SOME_DATE DATE);
CREATE OR ALTER PROCEDURE TESTDATE1(
XSOMEDATE DATE)
RETURNS(
ID SMALLINT
)
AS
BEGIN
INSERT INTO TESTDATE(SOME_DATE)
VALUES (:XSOMEDATE) RETURNING ID
INTO :ID;
SUSPEND;
END
The procedure in nodejs:
const createNativeClient = require('node-firebird-driver-native').createNativeClient;
const getDefaultLibraryFilename = require('node-firebird-driver-native').getDefaultLibraryFilename;
const config = require(__configDir).configGol
async function testQuery(query, params =[]) {
const dbase = 'ASD' //path to config..
const client = createNativeClient(getDefaultLibraryFilename())
const theDb = config(dbase).database
const theUser = config(dbase).user
const thePass = config(dbase).password
const attachment = await client.connect(theDb, {
password: thePass,
username: theUser
}).catch((e) => console.log(e))
if (!_.size(attachment)) {
console.log('DATABASE CONNECTION ', `${chalk.keyword('yellow')(`${dbase}`)}: ${chalk.bgRed(' FAILED 1110')}`);
return []
}
const transaction = await attachment.startTransaction();
try{
const resultSet = await attachment.executeQuery(transaction, query, params)
const rows = await resultSet.fetchAsObject()
await resultSet.close();
await transaction.commit();
await client.dispose();
return rows;
} catch (err){
await transaction.rollback();
await client.dispose();
return Object.assign({}, {ERROR:err, dbase: dbase, query: query, params: params, FLAG: 1043});
}
}
Then if I run this :
setTimeout( async() => {
let row = await testQuery(`SELECT ID FROM TESTDATE1(?);`, ['1/1/1989'])
console.log('row', row)
}, 1000);
I get error:
row {
ERROR: TypeError: date.getFullYear is not a function
at Object.<anonymous> (/var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:289:86)
at Generator.next (<anonymous>)
at /var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:8:71
at new WrappedPromise (/var/lib/sws/engine/svsync/node_modules/async-listener/es6-wrapped-promise.js:13:18)
at __awaiter (/var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:4:12)
at mappers.<computed> (/var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:241:66)
at /var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:338:58
at Array.map (<anonymous>)
at Object.<anonymous> (/var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:338:35)
at Generator.next (<anonymous>),
dbase: 'ASD',
query: 'SELECT ID FROM TESTDATE1(?);',
params: [ '1/1/1989' ],
FLAG: 1043
}
But if I run like this:
setTimeout( async() => {
let row = await testQuery(`SELECT ID FROM TESTDATE1('1/1/1989');`, [])
console.log('row', row)
}, 1000);
There is no error and returns correctly
row [ { ID: 15 } ]
Thank you!!!
The builtin tests uses a Date
object. What's the error using Date
?
I find out now that this works correctly here!
await testQuery(`SELECT ID FROM TESTDATE1(?);`, [new Date('1/1/1989')])
In the real situation the params are comming long way, so the situation is more like:
await testQuery(`SELECT ID FROM TESTDATE1(?);`, [JSON.parse(JSON.stringify(new Date('1/1/1989')))])
which errors:
row {
ERROR: TypeError: date.getFullYear is not a function
at Object.<anonymous> (/var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:289:86)
at Generator.next (<anonymous>)
at /var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:8:71
at new WrappedPromise (/var/lib/sws/engine/svsync/node_modules/async-listener/es6-wrapped-promise.js:13:18)
at __awaiter (/var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:4:12)
at mappers.<computed> (/var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:241:66)
at /var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:338:58
at Array.map (<anonymous>)
at Object.<anonymous> (/var/lib/sws/engine/svsync/node_modules/node-firebird-driver/dist/lib/impl/fb-util.js:338:35)
at Generator.next (<anonymous>),
dbase: 'ASD',
query: 'SELECT ID FROM TESTDATE1(?);',
params: [ '1988-12-31T22:00:00.000Z' ],
FLAG: 1043
}
Hello and thanks for the great library and tests (which I could learn from ). I am using node-firebird-driver with Firebird 3.0 running on Linux. I cannot go through this when I pass a date ( or timestamp) variable to an insert procedure:
I tryed in various formats to overcome the issue. ( tried '1/1/1989', new Date('1/1/1989') and so on )
For now I have to pass the date as string and then cast it as date. For timestamp I will use uinxtime to pass it like integer.
Please advise. Thank you