Skip to content
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

Supports of BOOLEAN type, bug fix, and intellisense experience improvement. #235

Merged
merged 3 commits into from
Oct 20, 2020

Conversation

pomgui
Copy link
Contributor

@pomgui pomgui commented Oct 20, 2020

This PR contains:

  • Support for BOOLEAN type in escape functions.
  • Fix a potential bug
  • GDSCode refactoring to improve intellisense experience.

Details

BOOLEAN type

In Firebird3 a true BOOLEAN type has been added, however the escape functions of this driver didn't support it, causing an error GDSCode.CONVERT_ERROR with a message like conversion error from string "1".

Reproduzing the error

Given a table in a Firebird 3 database:

CREATE TABLE test01(b BOOLEAN);

Execute the code:

FB.attach(options, (err, db) => {
    if (err) return closeDB(db, null, err);
    // Get a new transaction
    db.transaction((err, transaction) => {
        if (err) return closeDB(db, transaction, err);
        // insert a record
        transaction.query(`INSERT INTO test01 VALUES ( ${db.escape(true)} )`, [], 
          (err, _) => closeDB(db, transaction, err)
        );
    });
});
/** Helper function */
function closeDB(db, transac, error) {
    if (error) console.error(error.message, 'GDSCode: ', error.gdscode);
    if (transac) {
        if (!error) {
            console.log('commit()');
            return transac.commit(err => closeDB(db, null, err));
        } else {
            console.log('rollback()');
            return transac.rollback(err => closeDB(db, null, err));
        }
    }
    if (db) {
        console.log('detach()');
        db.detach(err => console.error(err));
    }
}

Output:

conversion error from string "1" GDSCode:  335544334
rollback()
detach()

Fix Potential bug

In messages.js, the getClass function was returning a wrong value, because it was right-shifting 30 bits instead of 28.

Consider the following expressions:

CLASS_MASK == 0xF0000000; 
getCode(0x456789234) == 0x1 // it should return 0x5:
(0x456789234 & CLASS_MASK) == 0x050000000
(0x050000000 >> 28) == 0x5
(0x050000000 >> 30) == 0x1

Despite this function is not being used by the driver itself, it is exported, therefore it should return the correct value.

Intellisense experience

The GDSCode has been refactored changing the line comments (// xpto) with documentation comments (/** xpto */). This allows intellisense capable software (like vscode) show this comments to developer.
Also, the definition file now contains the whole list of codes, in order that typescript users has the intellisense benefit as well, and as now it's an enum, the developer can see the list of codes (normally with a Ctrl+space).

@mariuz mariuz merged commit 879a287 into hgourvest:master Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants