Sqlite subquery not working properly

In this code, the external sqlite query will complete its work first, then it will switch to the internal sqlite query. Please explain to me why this is happening and also give a solution to my request.

/*Outer Sqlite Query*/ db.transaction(function(transaction){ transaction.executeSql('SELECT * FROM OuterTable;', [], function(transaction,results){ if (results != null && results.rows != null) { for (var i = 0; i < results.rows.length; i++) { /*My work is going here*/ /*Inner Sqlite Query Inside lor loop*/ db.transaction(function(transaction){ transaction.executeSql('SELECT * FROM MyInnerTable;',[], function(transaction, result){ if (result != null && result.rows != null) { for (var j = 0; j < result.rows.length; j++) { /* My Work is Going here */ } } },errorHandler); } ,errorHandler,nullHandler); /*Inner Sqlite End Here*/ } } },errorHandler); } ,errorHandler,nullHandler); /*Outer Sqlite End Here*/ 

The problem is that here
First ---> Outer Sqlite Work Running, then Inner Sqlite running, but my Requirement is like for every value Outer Sqlite Inner Sqlite will work

for example: -

 for(int i=0;i<=10;i++){ for(int j=0;j<=10;j++){ // here inner for loop will work for every value of outer for loop } } 

Thanks in advance

+4
source share
1 answer

Your requirement to fulfill an internal request for each external request cannot be achieved like this. Because SELECT queries are asynchronous calls.

Even the outer for loop does not wait for the completion of your query in the previous index. It will continue to execute and simultaneously run SELECT queries.

However, you can use recursion to achieve this.

If each outer loop calls a selection request, the success callback implements the inner query and the inner query success callback recursively calls the inner query for the required number of times with the desired index and sends the number of times (inner loop for the condition) it will call the external query implementer with the index with the extension .

Hope this helps.

0
source

Source: https://habr.com/ru/post/1494425/


All Articles