ing-bank/vscode-psl

Dynamic IBS server from environments.json

joelgomes85 opened this issue · 11 comments

Allow dynamic configuration of servers so it can be possible add a connection with other IBS server types and other connection properties like we have in eclipse (example: SCA$IBS/fileEncoding=UTF8)

Can this be solved by interfacing with the Profile JDBC driver?

Sorry, I do not know the best way to do this. Also in Squirrel we need to put in the connection string the correct server and encoding: protocol=jdbc:xxxxxl/database=xxxxxxxxx.xxxx.xx.xxx.net:12345:SCA$WRK/timeout=45/transType=MTM/rowPrefetch=30/signOnType=1/fileEncoding=UTF8

This is the only limitation that I have at this moment.
You can reproduce this by sending to profile special characters, example:
sent to host:

write "sábado"

refresh from host:

write "sábado"

Now imagine this in DAT files.

Also if I need to use another server type like SCA$WRK I can't because this is hard coded.

The server type is normally in the message. I played around with the Python implementation a long time ago, and I remember that when constructing the message to the MTM's , you need to specify a server type. I aslo notices that here, which is actually hardcoded to SCA$IBS:

	private servertype: string = 'SCA$IBS';

This is in the MtmConnection class, and should then probably be configurable.

As for the UTF-8 issue, I assume this really depends on the encoding that you use in vscode and in GT.M. It should not depend on the transport, because the transport is afaik just sending bytes :-)

SquirrelSQL, Eclipse,... all use FIS JDBC driver and options you are mentioning are the connection properties used by JDBC driver. This VSCode plugin is not using (any more) JDBC driver and connection are implemented in TypeScript and there is no use of this options.

Make sure your database charset is matching your file encoding on your development environment.
For plugin developers - just make sure that you take character set into account when you encode text to bytes (numbers with |).

should then probably be configurable

...

depends on the encoding

@mreitsmaing Configuring the server type is easy. The encoding should also be doable, but looks less straightforward. Thoughts on exactly how?


This VSCode plugin is not using (any more) JDBC driver and connection are implemented in TypeScript

@kdrozd True, but it can be re-implemented. Still keep the TypeScript implementation by default, but additionally allow the developer to use their own JDBC driver and specify the connection string. This would solve the issue and also make the extension a bit more "future-proof".

@mreitsmaing Check out this function in utils.ts that is used to read the response from the MTM

export function parseResponse(serviceClass: number, outputData: Buffer): string {
	// unpacking multiple times to get the token, remove the endiness by extracting from position 2
	let returnString: string = ''
	let returnArray: Buffer[];
	returnArray = lv2vFormat(outputData);
	returnArray = lv2vFormat(returnArray[1]);
	returnArray = lv2vFormat(returnArray[1]);
	returnString = returnArray[0].toString()
	if (returnString === 'ER') {
		throw returnArray.map(x => x.toString()).join('')
	}
	if (serviceClass === 5) {
		returnString = returnArray[2].toString() + String.fromCharCode(0) + returnArray[3].toString()
	}
	return returnString;
}

The toString() method accepts an encoding paramter:
https://nodejs.org/docs/latest-v6.x/api/buffer.html#buffer_buf_tostring_encoding_start_end

More about encoding Buffers:
https://nodejs.org/docs/latest-v6.x/api/buffer.html#buffer_buffers_and_character_encodings

@atiplea I took a look at the SCJDBC driver code and it uses the encoding, of the fileEncoding parameter mentioned in one of the comments above, to convert the message into that particular encoding and then send it to Profile.
What I'm basically saying is, with that piece of code you are in the right track to solve the issue without even using the JDBC driver again.

This is the only limitation that I have at this moment.
You can reproduce this by sending to profile special characters, example:
sent to host:

write "sábado"

refresh from host:

write "sábado"

@joelgomes85 We have noticed this problem ourselves, but think it might be a limitation within Profile. Do you encounter the same issue when using Eclipse? By default vscode is using utf8 encoding.

yes, @atiplea. I'm currently working in a project were if I don't use the fileEncoding option in Eclipse, the encoding is bad. Even if the file and the project in Eclipse are all with the UTF-8 encoding.
Also if I use the fileEncoding option in Eclipse to send to Host and then I refresh from host with vscode the encoding is bad. I think it's needed to encode both the message to the server and the response from the server.

I opened a pull request with the solution. The user specified serverType and encoding will now be used.

There was a mistake on our side where we were sending to Profile one byte at a time (thanks @kdrozd). This is why á (a 2 byte char in utf8) became á. That should also be fixed now. Can someone review?

Finally released! Thanks for being patient and opening the issue @joelgomes85