Skip to content

Commit

Permalink
Updated dataFormatVersion option to dataFormatSupport (#253)
Browse files Browse the repository at this point in the history
- Changed the name of the client config option dataFormatVersion to dataFormatSupport to match hana-client driver
- Restricted dataFormatSupport versions to only those supported by the driver (1 - 4 for now). If versions that are not supported are entered in the config, an error will be sent.
- Added unit tests to test the dataFormatSupport restrictions
  • Loading branch information
he-is-harry authored Jan 21, 2025
1 parent 71a7bfd commit 3ff9c3e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
26 changes: 19 additions & 7 deletions lib/protocol/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var reply = require('./reply');
var createExecuteTask = require('./ExecuteTask').create;
var ReplySegment = reply.Segment;
var part = require('./part');
const DataFormatVersion = require('./common/DataFormatVersion');
var MessageType = common.MessageType;
var MessageTypeName = common.MessageTypeName;
var SegmentKind = common.SegmentKind;
Expand Down Expand Up @@ -457,13 +458,24 @@ Connection.prototype.connect = function connect(options, cb) {
}
delete options[key];
}
if(key.toUpperCase() === "DATAFORMATVERSION") {
this.connectOptions.setOptions([
{name : common.ConnectOption.DATA_FORMAT_VERSION,
value : options[key]},
{name : common.ConnectOption.DATA_FORMAT_VERSION2,
value : options[key]}
]);
if(key.toUpperCase() === "DATAFORMATSUPPORT") {
if (options[key] && options[key] >= 1 && options[key] <= DataFormatVersion.MAX_VERSION) {
this.connectOptions.setOptions([
{name : common.ConnectOption.DATA_FORMAT_VERSION,
value : options[key]},
{name : common.ConnectOption.DATA_FORMAT_VERSION2,
value : options[key]}
]);
} else {
// Raise an error for the invalid data format version
if (options[key] > DataFormatVersion.MAX_VERSION) {
return cb(new Error(util.format("Maximum driver supported data format %d is less than client requested %d",
DataFormatVersion.MAX_VERSION, options[key])));
} else {
return cb(new Error(util.format("Data format %s is invalid. Supported values are 1 to %d",
options[key], DataFormatVersion.MAX_VERSION)));
}
}
}
}
this.connectOptions.setOptions([
Expand Down
4 changes: 3 additions & 1 deletion lib/protocol/common/DataFormatVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ module.exports = {
COMPLETE_DATATYPE_SUPPORT: 1,
// deprecated
EXTENDED_DATE_TIME_SUPPORT: 3,
LEVEL4: 4
LEVEL4: 4,
// Maximum data format version supported by this driver
MAX_VERSION: 4,
};
2 changes: 1 addition & 1 deletion test/acceptance/db.DataType.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

var async = require('async');
// Set the data format version necessary for the data types
var db = require('../db')({dataFormatVersion: 4});
var db = require('../db')({dataFormatSupport: 4});
var RemoteDB = require('../db/RemoteDB');
var lorem = require('../fixtures/lorem');

Expand Down
44 changes: 44 additions & 0 deletions test/lib.Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var FunctionCode = lib.common.FunctionCode;
var SegmentKind = lib.common.SegmentKind;
var ErrorLevel = lib.common.ErrorLevel;
var PartKind = lib.common.PartKind;
const DataFormatVersion = lib.common.DataFormatVersion;

function connect(options, connectListener) {
var socket = mock.createSocket(options);
Expand Down Expand Up @@ -659,5 +660,48 @@ describe('Lib', function () {

});

context('data format support', function() {
function dataFormatTestConnection(options, cb) {
var connection = createConnection();

// Add authentication method so that the mock connection will go through
connection._createAuthenticationManager = function createManager(options) {
var manager = mock.createManager(options);
manager.sessionCookie = 'cookie';
return manager;
};
connection.send = sendAuthenticationRequest;
connection.connect(options, function (err) {
cb(err, connection);
});
}

it('should set valid data format support version', function (done) {
dataFormatTestConnection({ dataFormatSupport: 4 }, function (err, connection) {
if (err) { throw err; }
connection.connectOptions.should.have.property('dataFormatVersion', 4);
connection.connectOptions.should.have.property('dataFormatVersion2', 4);
done();
});
});

it('should not overwrite with invalid data format version', function (done) {
dataFormatTestConnection({ dataFormatSupport: -2 }, function (err, connection) {
err.should.be.an.instanceOf(Error);
err.message.should.equal(util.format("Data format -2 is invalid. Supported values are 1 to %d", DataFormatVersion.MAX_VERSION));
done();
});
});

it('should not overwrite with data format version past max support', function (done) {
dataFormatTestConnection({ dataFormatSupport: 99 }, function (err, connection) {
err.should.be.an.instanceOf(Error);
err.message.should.equal(util.format("Maximum driver supported data format %d is less than client requested 99",
DataFormatVersion.MAX_VERSION));
done();
});
});
});

});
});

0 comments on commit 3ff9c3e

Please sign in to comment.