Show tables statement results in Token unknown error

154 Views Asked by At

I am having to integrate with a Firebird 1.5 database. We can't upgrade the DB to a newer version.

I run the below code to attempt to see what the tables are

var Firebird = require('node-firebird');

var options = {};

options.host = '127.0.0.1';
options.port = 3050;
options.database = 'C:\\Database.fdb';
options.user = 'sysdba';
options.password = 'masterkey';
options.lowercase_keys = false; // set to true to lowercase keys
options.role = null;            // default
options.pageSize = 4096;        // default when creating database
options.pageSize = 4096;        // default when creating database
options.retryConnectionInterval = 1000; // reconnect interval in case of connection drop

Firebird.attach(options, function(err, db) {
    console.log("starting");
    if (err) {
        console.log(err)
        throw err;
    }
    
    // db = DATABASE
    db.execute('show tables', function(err, result) {
        // IMPORTANT: close the connection
        console.log(err)
        console.log(result)
        db.detach();
    });

});

The above results in the following error:

Error: Dynamic SQL Error, SQL error code = -104, Token unknown - line 1, column 1, show
    at doCallback (C:\nodetest\node_modules\node-firebird\lib\index.js:1321:21)
    at C:\nodetest\node_modules\node-firebird\lib\index.js:3100:25
    at C:\nodetest\node_modules\node-firebird\lib\messages.js:151:25
    at search (C:\nodetest\node_modules\node-firebird\lib\messages.js:117:13)
    at C:\nodetest\node_modules\node-firebird\lib\messages.js:54:21
    at FSReqCallback.wrapper [as oncomplete] (node:fs:675:5) {
  gdscode: 335544569,
  gdsparams: undefined
}

Changing just the query in the code to a select on a table I know should exist

select first 1 * from tag

Just sits hanging as if the code is stuck trying to read the table.

Is there anything obvious I'm doing wrong? Or is there a different way we should be connecting to this database?

1

There are 1 best solutions below

0
Mark Rotteveel On

Firebird doesn't have a show tables statement. That is a command specific to the Firebird isql query tool. To query for tables, you need to query the metadata tables, e.g.

select RDB$RELATION_NAME from RDB$RELATIONS

(note: this will also includes views, to exclude them add condition where RDB$VIEW_BLR is null)

As an aside, Firebird 1.5 has been end-of-life since October 2009. Several security issues have been solved in newer versions. You should really upgrade to a newer version.