Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Wait for DB Call

I have two functions both making select calls on the database.

I run the first call and get a value (tested by sending the value to the console).

When I use the value I got from the first in the second within the function is says the variable is undefined.

Anyone know a proper way to handle this? I don't really want to use setTimeout.

— asked August 17th 2010 by John Welch
  • settimeout
  • undefined
0 Comments

3 Answers

  • Anyone know?

    — answered August 18th 2010 by John Welch
    permalink
    0 Comments
  • Hi
    Can you show us some code?

    — answered August 18th 2010 by Dan Tamas
    permalink
    0 Comments
  • Try storing the database resultset in a variable and do two seperate queries.

    var query = null;
    var result = null;
    
    // First query
    query = my_db.execute('SELECT * FROM ...');
    if (query.isValidRow()) {
        result = query.getFieldByName('my_column');
    }
    query.close();
    
    if (result !== null) {
        // Second query
        query = my_db.execute('SELECT * FROM ...');
        // Do stuff
    }
    
    — answered August 18th 2010 by Richard Venneman
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.