How to perform database inserts/updates on a separate thread?

You must Login before you can answer or comment on any questions.

Our iPhone application syncs with a server with a lot of data with cross relationships. Connecting to our API is easy and seamless, but as soon as the request is received successfully the GUI and application locks up.

I assume these updates are performed on the same thread as the rest of the application, so is it possible to trigger a new thread to perform the database inserts and updates?

— asked 7 months ago by Dallas Clark
1 Comment
  • Alternatively, as majority of the data is replicated into the database from the API. Is it best to simply delete existing content and do all new inserts?

    — commented 7 months ago by Dallas Clark

2 Answers

I don't think it's possible. Try using db transaction, it should speedup things a lot. You can also postpone db import until UI is rendered (and that way make illusion things are working fast).

— answered 7 months ago by Ivan Škugor
answer permalink
1 Comment
  • Just had a look into DB Transactions, this would be great if I didn't have to collect auto insert IDs generated by the database.

    The GUI is rendered before the database performs it's updates, however as soon as the database does begin updates, it freezes the application, which stops the user from navigating to other sections available.

    — commented 7 months ago by Dallas Clark

Using JAVA Script, to run something on different thread. i found to use a different function call for your database query... but check the documentation also for this.

— answered 7 months ago by Ashish Nigam
answer permalink
1 Comment
  • Thanks but the API sync and database updates are already performed in separate functions. I have one callback function for the API request, it then calls a separate function to update each table necessary.

    — commented 7 months ago by Dallas Clark

Your Answer

Think you can help? Login to answer this question!