Alasql: Drop trigger throws error

Created on 26 Jun 2019  路  4Comments  路  Source: agershun/alasql

The following program creates a table and a trigger on the table. An error is thrown when the trigger is dropped.

const alasql = require('alasql');
alasql.fn.onchange = function(r) {
    console.log('got event in trigger callback 1');
};
alasql('CREATE TABLE one (a INT)');
alasql('CREATE TRIGGER myTrigger AFTER INSERT ON one CALL onchange()');
alasql('INSERT INTO one VALUES (123)');  // This will fire onchange()
alasql('DROP TRIGGER myTrigger');
alasql('INSERT INTO one VALUES (231)');  // This should not fire onchange()
**Stacktrace:**
got event in trigger callback 1
<path>\node_modules\alasql\dist\alasql.fs.js:14848
        delete db.tables[tableid].beforeinsert[triggerid];
                                  ^
TypeError: Cannot read property 'beforeinsert' of undefined
    at yy.DropTrigger.execute (<path>\node_modules\alasql\dist\alasql.fs.js:14848:29)
    at Function.alasql.dexec (<path>\node_modules\alasql\dist\alasql.fs.js:4659:46)
    at Function.alasql.exec (<path>\node_modules\alasql\dist\alasql.fs.js:4607:17)
    at alasql (<path>\node_modules\alasql\dist\alasql.fs.js:138:16)
    at Object.<anonymous> (<path>\test9.js:8:1)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

Process finished with exit code 1
! Bug Code provided to reproduced Good first issue Help wanted SQL compliance

All 4 comments

So sorry to see you have to do things like https://github.com/Gippsman2017/node-red-contrib-redlink/commit/47bd90e197787812413e60a2b975f8c19ebf3c2d#diff-ef6ff4525efc31a46136931fbca91995R144 to work around this.

This would be a great first bug to look at for anyone.

Drop trigger throws error #1113

I have put a PR up for this issue.

The drop was trying to use the trigger as the table id and because that didn't exist it threw the error.

To resolve this I added the tableid to the trigger on creation and then when dropping it uses the tableid from the trigger to work out which tables to remove the trigger from.

Thanks @mathiasrw and @garynewelluk

@mathiasrw , @garynewelluk would it also be possible to look at https://github.com/agershun/alasql/issues/1119 ? It would greatly simplify our code if this were fixed too. I am currently working around this issue by doing a select to figure out which rows have actually changed in the trigger callback which is inefficent. Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mwhebert picture mwhebert  路  3Comments

mathiasrw picture mathiasrw  路  5Comments

AmyBlankenship picture AmyBlankenship  路  6Comments

arnemorken picture arnemorken  路  6Comments

cscan picture cscan  路  4Comments