xdenser / node-firebird-libfbclient

Firebird SQL binding
MIT License
82 stars 34 forks source link

using Interbase 6 #122

Closed sqllyw closed 3 years ago

sqllyw commented 3 years ago

Hi, I can use the Firebird 1.5 to view contents in a IB6 database, but with following code, I got an error:

Error: While connecting - bad parameters on attach or create database CHARACTER SET UTF8 is not defined

var fb  = require("firebird");
sys = require("sys"); 
var con = fb.createConnection();
con.connectSync('10.114.173.154://opt/interbase/examples/employee.gdb','sysdba','masterkey','');

var res = con.querySync("select * from country;");

var rows = res.fetchSync("all",true);
console.log(sys.inspect(rows));

is there a way that I can connect to a IB6 db? need is simple, just a read only 'select * from ...' thanks

xdenser commented 3 years ago

Try to use options on createConnection(options) https://github.com/xdenser/node-firebird-libfbclient/blob/master/README.md#reference

sqllyw commented 3 years ago

tried with following code, still have the error, am I missing something?

var fb = require("firebird");
sys = require("sys");
let con = fb.createConnection({ lc_type: 'WIN1252', lc_decode: (data) => iconv.decode(data, 'windows-1252') });

con.connectSync('10.114.173.154://opt/interbase/examples/employee.gdb', 'sysdba', 'masterkey', '');

var res = con.querySync("select * from country;");

var rows = res.fetchSync("all", true);
console.log(sys.inspect(rows));
sqllyw commented 3 years ago

following code works:

var con = fb.createConnection();
con.connectSync('10.114.173.154://opt/interbase/examples/employee.gdb','sysdba','masterkey','');

if I update the fb-bindings-connection.h :

 char *lc_type = const_cast<char *>("UNICODE_FSS");

is this safe ?

xdenser commented 3 years ago

option name is 'lc_ctype'.

sqllyw commented 3 years ago

thanks, updated the code, but still has the same error:

var fb = require("firebird");
sys = require("sys");
let con = fb.createConnection({ lc_ctype: 'WIN1252', lc_decode: (data) => iconv.decode(data, 'windows-1252') });

con.connectSync('10.114.173.154://opt/interbase/examples/employee.gdb', 'sysdba', 'masterkey', '');

var res = con.querySync("select * from country;");

var rows = res.fetchSync("all", true);
console.log(sys.inspect(rows));
xdenser commented 3 years ago

Sorry, checked code again it is 'lc_type'. I wonder why ? in FB/IB API it is 'lc_ctype'. Probably it was someone's PR which I did not check properly. We have no test for this feature. But the code looks ok. Yes you may use C++ patch as workaround. Why do you set "UNICODE_FSS" in C++ and "WIN1252" in JS?

sqllyw commented 3 years ago

Try to use options on createConnection(options) https://github.com/xdenser/node-firebird-libfbclient/blob/master/README.md#reference

I look at firebird.js and found this line:

exports.createConnection = function () {
  var c = new Connection();
  return c;
};

it is not expecting an options object?

xdenser commented 3 years ago

Aha this was not released yet. Last release is 28 Oct 2019, And the PR merged later. Ok I'll make new release.

sqllyw commented 3 years ago

Sorry, checked code again it is 'lc_type'. I wonder why ? in FB/IB API it is 'lc_ctype'. Probably it was someone's PR which I did not check properly. We have no test for this feature. But the code looks ok. Yes you may use C++ patch as workaround. Why do you set "UNICODE_FSS" in C++ and "WIN1252" in JS?

I never know there is an options object, so patched C++ first, which UNICODE_FSS is the one closed to UTF8.

sqllyw commented 3 years ago

Aha this was not released yet. Last release is 28 Oct 2019, And the PR merged later. Ok I'll make new release.

that will be nice, thanks.

sqllyw commented 3 years ago

Aha this was not released yet. Last release is 28 Oct 2019, And the PR merged later. Ok I'll make new release.

Just tried the new release (0.1.5), it works as expected, this really helps to access legacy databases without doing a database migration (ib to fb), Thanks!!!

Following is the final code accessing an Interbase 6 gdb:

var fb = require("firebird");
sys = require("sys");
let con = fb.createConnection({ lc_ctype: 'WIN1252',  lc_ctype_decode:  (data) => data.toString()});

con.connectSync('10.114.173.154://opt/interbase/examples/employee.gdb', 'sysdba', 'masterkey', '');

var res = con.querySync("select * from country;");

var rows = res.fetchSync("all", true);
console.log(sys.inspect(rows));