B4J Question Jobdone not succesful SQL-

david13

Member
Licensed User
Hi All,

I'm using a remote database to save my data, when I use SELECT In the Query I dont have any problem, because when the query is executed, all the table is rthather loaded or not, so I can reload all the table if it was not .
However, with the INSERT query, I am using a loop ( for) for each row of the table, the problem is some qeuries are sucessful and others are not so some cells are INSERTED into the remote database and others are not! it's a headache to know what are the data that were not sent to send them again!

My quetion is is there any method to INSERT all the table without a loop!

this is what i'm using:
Sub Fetch_Select

ExecuteRemoteQuery(SELECT......)

End Sub


Sub Fetch_INSERT

For i=0 To TableView1.Items.Size-1

ExecuteRemoteQuery(INSERT......)

Next
End Sub


this is the log error I have!

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE> 508 Resource Limit Is Reached</TITLE>
</HEAD><BODY>
<H1>Resource Limit Is Reached</H1>
The website is temporarily unable to service your request as it exceeded resource limit.
Please try again later.
</BODY></HTML>
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Are you using shared hosting? If not then you should switch to jRDC2.

The PHP script handles a single insert command every request. You can wait for the result inside the loop: [B4X] OkHttpUtils2 with Wait For

This way it will send the requests one by one.
 
Upvote 0

david13

Member
Licensed User
Please use [code]code here...[/code] tags when posting code.

Are you using shared hosting? If not then you should switch to jRDC2.

The PHP script handles a single insert command every request. You can wait for the result inside the loop: [B4X] OkHttpUtils2 with Wait For

This way it will send the requests one by one.


Thanks a lot Erel , Yes I'm Using hostinger, I'm developing a stock manager software for a costumer,

I changed my code as following:
B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String)
  
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://www......", Query)
    Wait For (job) JobDone(job As HttpJob)
    If job.Success Then

before it was :
B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String)
  
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://www........", Query)
End Sub



Sub JobDone(Job As HttpJob)

    If Job.Success Then

Am I doin it correctly! I have to do tests to see if it's ok!

Thank you so much for Resumable Subs, very logic and useful idea,
 
Upvote 0

david13

Member
Licensed User
It looks correct. JobName is no longer needed.

You might also need to add Sleep between the requests. Depending on your server configuration.
After some tests, I had the same error message, I'm using jobName as followinn:
B4X:
Select job.JobName
            Case .......
                ......
                         case .......
                         .......
I'll add a sleep of 100 ms as followin:
B4X:
For i=0 To TableView1.Items.Size-1
        Sleep(100)
        
        ExecuteRemoteQuery("INSERT INTO ......)
        
        End If
    
    Next

I'll do tests again!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your code is not correct. You should either remove ExceuteRemoteQuery and put the relevant code in the loop or change it to:
B4X:
Sub ExecuteRemoteQuery(Query As String, JobName As String) As ResumableSub
 '...
 Return True
End Sub
Now call it with:
B4X:
For i=0 To TableView1.Items.Size-1
        Sleep(100)
       
        Wait For (ExecuteRemoteQuery("INSERT INTO ......")) Complete (Result As Boolean)
       
        End If
   
    Next
[B4X] Resumable subs that return values (ResumableSub)
 
Upvote 0

david13

Member
Licensed User
Warm Thank Erel!

Now it working very well, now even a row is not inserted i know its position!! so I store it localy or send it again! I was not very confotable how it was working before, now it's very simple to manage!! hope it will help others!
 
Upvote 0
Top