Skip to content

fix: resolve parser cache collision with dual typeCast connections #3644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/parsers/parser_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function keyFromFields(type, fields, options, config) {
Boolean(options.rowsAsArray),
Boolean(options.supportBigNumbers || config.supportBigNumbers),
Boolean(options.bigNumberStrings || config.bigNumberStrings),
typeof options.typeCast,
typeof options.typeCast === 'function' ? 'function' : options.typeCast,
options.timezone || config.timezone,
Boolean(options.decimalNumbers),
options.dateStrings,
Expand Down
12 changes: 6 additions & 6 deletions test/esm/unit/parsers/cache-key-serialization.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -383,25 +383,25 @@ const result9 = _keyFromFields(

assert.deepStrictEqual(
result1,
'[null,"undefined",null,false,false,false,"undefined",null,false,null,[null,null,null,null,null,null,null]]'
'[null,"undefined",null,false,false,false,null,null,false,null,[null,null,null,null,null,null,null]]'
);
assert(JSON.parse(result1));

assert.deepStrictEqual(
result2,
'[null,"undefined",null,false,false,false,"undefined","local",false,null,[null,null,null,null,null,null,null]]'
'[null,"undefined",null,false,false,false,null,"local",false,null,[null,null,null,null,null,null,null]]'
);
assert(JSON.parse(result2));

assert.deepStrictEqual(
result3,
'[null,"string","",false,false,false,"boolean","local",false,false,[null,null,null,null,null,null,null]]'
'[null,"string","",false,false,false,true,"local",false,false,[null,null,null,null,null,null,null]]'
);
assert(JSON.parse(result3));

assert.deepStrictEqual(
result4,
'["binary","boolean",false,false,false,false,"boolean","local",false,"DATETIME",["id","3",null,"test","test","16899","63"],["value","246",null,"test","test","0","63"]]'
'["binary","boolean",false,false,false,false,true,"local",false,"DATETIME",["id","3",null,"test","test","16899","63"],["value","246",null,"test","test","0","63"]]'
);
assert(JSON.parse(result4));

Expand All @@ -410,14 +410,14 @@ assert(JSON.parse(result5));

assert.deepStrictEqual(
result6,
'["binary","boolean",false,true,true,true,"boolean","\\"\\"`\'",true,"#",[":","©",null,"/",",","_","❌"]]'
'["binary","boolean",false,true,true,true,true,"\\"\\"`\'",true,"#",[":","©",null,"/",",","_","❌"]]'
);
// Ensuring that JSON is valid with invalid delimiters
assert(JSON.parse(result6));

assert.deepStrictEqual(
result7,
'["binary","boolean",true,true,true,true,"boolean","local",true,"DATETIME",["id","3",null,"test","test","16899","63"],["value","246",null,"test","test","0","63"]]'
'["binary","boolean",true,true,true,true,true,"local",true,"DATETIME",["id","3",null,"test","test","16899","63"],["value","246",null,"test","test","0","63"]]'
);
assert(JSON.parse(result7));

Expand Down
69 changes: 69 additions & 0 deletions test/integration/config/test-typecast-dual-connections.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';

const common = require('../../common.test.cjs');
const { assert } = require('poku');

// Create two connections with different typecast configurations
const connectionTypeCastTrue = common.createConnection({
typeCast: true,
});

const connectionTypeCastFalse = common.createConnection({
typeCast: false,
});

function cleanupConnections() {
try {
connectionTypeCastTrue.end();
} catch (err) {
// Connection might already be closed
}
try {
connectionTypeCastFalse.end();
} catch (err) {
// Connection might already be closed
}
}

process.on('exit', cleanupConnections);
process.on('SIGINT', () => {
cleanupConnections();
process.exit(0);
});
process.on('SIGTERM', () => {
cleanupConnections();
process.exit(0);
});

// Test connection with typeCast: true
connectionTypeCastTrue.query('SELECT 1', (err, results) => {
assert.ifError(err);
assert.equal(typeof results[0]['1'], 'number');
assert.equal(results[0]['1'], 1);
console.log(
'typeCast: true - Result type:',
typeof results[0]['1'],
'Value:',
results[0]['1']
);
connectionTypeCastTrue.end();
});

// Test connection with typeCast: false
connectionTypeCastFalse.query('SELECT 1', (err, results) => {
assert.ifError(err);
assert(
Buffer.isBuffer(results[0]['1']),
'Result should be a Buffer when typeCast is false'
);
assert.equal(results[0]['1'].toString(), '1');
console.log(
'typeCast: false - Result type:',
typeof results[0]['1'],
'Is Buffer:',
Buffer.isBuffer(results[0]['1']),
'Value:',
results[0]['1'].toString()
);
connectionTypeCastFalse.end();
});
Loading