Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 4, 2011, 04:42 PM   #1
tdog09
macrumors member
 
Join Date: Jul 2008
SQLITE Busy Handling

Hey guys, need a little bit of help.

I'm using sqlite3 and updating a few tables throughout the use of my app.

My typical update code goes like this (after opening the database):

Code:
char *errorMsg;
NSString *update = [[NSString alloc] initWithFormat: @"Update PRSN_POINTS SET POINTS = 3"];

if (sqlite3_exec (database, [update UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK){

  NSAssert1(0, @"Error updating table:, %s", errorMsg);
)
This works fine, but since my app is Multi Threaded () every now and then I find that two threads will be trying to access and update the same table at the same time. The error code I get back is SQLITE_BUSY as it cannot contain a DB LOCK.

My question is what is the correct way to handle this? I would think that I should have it sleep for a just a little, then retry. I'm not quite sure how to accomplish this, so any suggestions and code inserts would be great. Also I haven't looked a whole lot into Core Data, but would it have any advantages in this area? My code's quite infused with SQLITE, and I would rather not have to scrap it.

Thanks!
tdog09 is offline   0 Reply With Quote
Old Feb 5, 2011, 06:26 PM   #2
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
I believe that FMDB manages this. If you don't want to use FMDB directly then you can look at its code.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 7, 2011, 07:48 PM   #3
tdog09
Thread Starter
macrumors member
 
Join Date: Jul 2008
Quote:
Originally Posted by PhoneyDeveloper View Post
I believe that FMDB manages this. If you don't want to use FMDB directly then you can look at its code.
Thanks, are there more resources on how to use FMDB?
tdog09 is offline   0 Reply With Quote
Old Feb 7, 2011, 09:39 PM   #4
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Unfortunately documentation is a weak point for FMDB. On the good side it's not very much code and you get all of the code to read yourself.

There is one example file that shows the basics.

To use an FMDB database from a thread all you do is create another database object on each thread. It should "just work" in that case. I've had no problems using it from multiple threads concurrently.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 8, 2011, 01:48 PM   #5
tdog09
Thread Starter
macrumors member
 
Join Date: Jul 2008
Quote:
Originally Posted by PhoneyDeveloper View Post
Unfortunately documentation is a weak point for FMDB. On the good side it's not very much code and you get all of the code to read yourself.

There is one example file that shows the basics.

To use an FMDB database from a thread all you do is create another database object on each thread. It should "just work" in that case. I've had no problems using it from multiple threads concurrently.
Thanks for help! I started looking at it and using it in my code. Question, does an AutoRelease Pool need to be created each time I create a new database object? Thanks!
tdog09 is offline   0 Reply With Quote
Old Feb 8, 2011, 02:00 PM   #6
PhoneyDeveloper
macrumors 68020
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
I don't think so. Why do you ask?

If you're asking about a db on a thread then the normal memory management for threads applies. It's certainly possible that iterating over a result set will generate a lot of autoreleased objects and you might use a local autorelease pool for that. If that's what you're asking.
PhoneyDeveloper is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Using UUID as pkey in sqlite db mraheel iPhone/iPad Programming 9 Dec 2, 2011 01:28 PM
Bulk storing in SQLite while parsing in iOS ashwinr87 iPhone/iPad Programming 6 Oct 31, 2011 10:27 AM
sqlite problem ghousemd iPhone/iPad Programming 0 Jul 6, 2011 04:50 AM
sqlite problem ghousemd iPhone/iPad Programming 1 Jul 5, 2011 01:40 AM
Designing an SQLite backend, workups for a todo app mraheel iPhone/iPad Programming 0 Feb 6, 2011 04:24 AM


All times are GMT -5. The time now is 10:11 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC