Phonegap - Assemble with a query result from another query - Sqlite Query

335 Views Asked by At

I can not make a selection via the result of the first

Goal is: Do the query on the table "line" pick up your ID and search customers that line the "customer" table

This is my code:

    db = window.openDatabase("test", "1.0", "Test DB", 1000000);          
    db.transaction(SelectData,erroSelect,sucessSelect);

    function SelectData(tx)
    {
       tx.executeSql("select id from linha",[],function(tx, response)
       {
            for(i=0; i<response.rows.length; i++)
            {
                tx.executeSql("SELECT * FROM customers WHERE line= ?", [response.rows.item(i).id], 
                function (tx, results)
                {
                    for(r=0; r<results.rows.length; r++)
                    {
                        alert(results.rows.item(r).nome); //never worked
                    }   
                }
            }
        },SelectError);
    } 
1

There are 1 best solutions below

1
frank On BEST ANSWER

It is diffcult to understand from your post, where is the actual error.
Have you tried using console.log() call inside each tx.executeSql() to ascertain that the function is being executed.
Alternatively you can use a single query instead of using two SELECT statements.

Replace

select id from linha

with

SELECT customers.columnName1, customers.columnName2 
FROM customers INNER JOIN linha ON customers.line = linha.id