Skip to content

Trigger function does not give changed value in callback #1119

Closed

Description

@umasudhan

As an example, see the code for Example B at https://github.com/agershun/alasql/wiki/TRIGGER:

alasql.fn.onchange = function(r) {
        if(r.a == 123) console.log('Observable event!');
    };;
    alasql('CREATE TABLE one (a INT)');
    alasql('CREATE TRIGGER two BEFORE INSERT ON one CALL onchange()');
    alasql('INSERT INTO one VALUES (123)');  // This will fire onchange()

Executing this throws an error:

  • TypeError: Cannot read property 'a' of undefined. The parameter r is undefined

Activity

  1. changed the title [-]Trigger function does not give value in callback[/-] [+]Trigger function does not give changed value in callback[/+] on Jul 17, 2019
  2. mathiasrw commented on Jan 2, 2020

    @mathiasrw
    Member

    This is terrible. Thank you for letting us know.

  3. retorquere commented on Mar 20, 2025

    @retorquere

    Wow this bug still exists almost 6 years later?

  4. added a commit that references this issue on Mar 31, 2025
  5. retorquere commented on Apr 3, 2025

    @retorquere
    this.expression.toJS('({})', '', null)
    

    inside execute(databaseid, params, cb) returns

    alasql.fn["onchange"]()
    

    so the trigger function is always called without arguments

  6. retorquere commented on Apr 4, 2025

    @retorquere

    #1220 seems to offer a workaround. At the very least the documentation at https://github.com/AlaSQL/alasql/wiki/TRIGGER ought to be updated.

  7. mathiasrw commented on Oct 21, 2026

    @mathiasrw
    Member

    Is confirmed working in v4.20.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions