Coder Social home page Coder Social logo

Comments (4)

asfernandes avatar asfernandes commented on June 18, 2024

Please paste the simplest possible code that makes the error.

from node-firebird-drivers.

VldMrgnn avatar VldMrgnn commented on June 18, 2024

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!!!

from node-firebird-drivers.

asfernandes avatar asfernandes commented on June 18, 2024

The builtin tests uses a Date object. What's the error using Date?

from node-firebird-drivers.

VldMrgnn avatar VldMrgnn commented on June 18, 2024

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
}

from node-firebird-drivers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.