DB Async method

  1. 5 years ago

    Joel_Eisenstat

    30 Aug 2018 User since 2016

    Good morning,
    In changing to the recommended async method I am running into a problem with obtain record set values with dot notation. Previously when using rs = PostgreSQL.select(sql) the values were obtained with rs.id , rs.name , etc.
    However using async and closures PostgreSQL.select (sql, onSuccess,onError) a runtime error is generated for rs.id in the onSuccess closure.
    Runtime Error
    Unable to find id into class Closure
    ===========
    CALL FRAME:
    ===========
    onSuccess (Button1)

    Do all the db columns need to be declared in the func onSuccess ?

    code snippet :
    var material = "Tetric EveCeram"

    func onSuccess(db,rs) {
    Console.write(rs.id); ---> runtime error
    //Label1.text = rs.id;
    }
    func onError (db) {
    var alert = Alert("Error", "Error: \(db.errorMessage)", ["OK"]);
    alert.show();
    }
    PostgreSQL1.connect(onSuccess, onError); // insure conection
    var sql = 'SELECT * FROM "Chart_Odont_Material" WHERE "name" = $$\(material)$$';
    PostgreSQL1.select(sql, onSuccess, onError);
    Thanks
    joel

  2. marco

    30 Aug 2018 Administrator User since 2016

    @Joel_Eisenstat you can't share the same onSuccess closure for both the connect and the select method.
    The onSuccess closure related to the connect method does not have an rs parameter. I am quite sure that the runtime error you are experiencing is due to this issue.

    Your code should looks like:

    var material = "Tetric EveCeram"
    
    func onConnect(db) {
        Console.write("Connection successfully established.");
    }
    
    func onSuccess(db,rs) {
        Console.write(rs.id);
        Label1.text = rs.id;
    }
    
    func onError (db) {
        var alert = Alert("Error", "Error: \(db.errorMessage)", ["OK"]);
        alert.show();
    }
    
    PostgreSQL1.connect(onConnect, onError); // insure conection
    var sql = 'SELECT * FROM "Chart_Odont_Material" WHERE "name" = $$\(material)$$';
    PostgreSQL1.select(sql, onSuccess, onError);
  3. Joel_Eisenstat

    30 Aug 2018 User since 2016

    Yup , that works !
    Thanks again

or Sign Up to reply!