fmdb icon indicating copy to clipboard operation
fmdb copied to clipboard

EXC_BAD_ACCESS in line 434

Open aliparlar opened this issue 9 years ago • 5 comments

Hello,

FMDatabase works perfectly most of the time but rarely I get a EXC_BAD_ACCESS in below line

        rc      = sqlite3_prepare_v2(db, [sql UTF8String], -1, &pStmt, 0);

This line inserts a row into the DB. the code is downloading about 100 images, saving it to the DB and file system. Today I noticed the net connection was very slow when this happened. Normally the codes executes very fast and flawlessly. I am not sure if the slow internet has anything to do with this.

aliparlar avatar Sep 14 '15 11:09 aliparlar

I don't think sqlite does a thing with network connections, so that's probably not it.

I'm not sure what you'd look for though. A stack trace would be nice to see.

ccgus avatar Sep 14 '15 17:09 ccgus

I had this issue probably for 4 - 5 times during the development of an app during a 2-3 months period. Tough to catch.. I will get out as much as I can next time it happens but also do let me know if I can set specific traps in advance. Sorry its my first iOS app so I am not very keen on error catching, I followed some guides which show me the line of code that breaks but thats about all.

On Mon, Sep 14, 2015 at 8:04 PM, ccgus [email protected] wrote:

I don't think sqlite does a thing with network connections, so that's probably not it.

I'm not sure what you'd look for though. A stack trace would be nice to see.

— Reply to this email directly or view it on GitHub https://github.com/ccgus/fmdb/issues/406#issuecomment-140145340.

Ali Parlar

aliparlar avatar Sep 14 '15 17:09 aliparlar

aliparlar, if you're having problems when doing long network requests, I'd make sure that:

  • If doing asynchronous network calls, make sure you're not using the same FMDatabase instance across multiple threads (you can solve this by dispatching database interaction back to the main thread, or by using FMDatabaseQueue);
  • If using FMDatabaseQueue already, make sure you're not doing any synchronous network requests.

Admittedly, neither of these issues should be causing the sorts problem you describe, but they're still the sort of thing you want to be careful about when doing multithreaded code (and often when writing networking code, you often find yourself writing multithreaded code, even if it's not obvious). Writing thread-safe code is pretty complicated, but using FMDatabaseQueue rather than FMDatabase can simplify that process a bit.

Bottom line, there's nowhere near enough here to diagnose the problem. And frankly, assuming the root of the problem is multithreaded code rather than FMDB, this question might be better suited for a forum like Stack Overflow, making sure you provide short code snippets that illustrate how you're doing your network calls (NSURLSession? NSURLConnection? AFNetworking? Alamofire?) and describe the lifecycle of the FMDatabase and/or FMDatabaseQueue objects.

robertmryan avatar Sep 15 '15 06:09 robertmryan

Thanks for the pointers

On Tue, Sep 15, 2015 at 9:32 AM, Rob Ryan [email protected] wrote:

aliparlar, if you're having problems when doing long network requests, I'd make sure that:

If doing asynchronous network calls, make sure you're not using the same FMDatabase instance across multiple threads (you can solve this by dispatching database interaction back to the main thread, or by using FMDatabaseQueue);

If using FMDatabaseQueue already, make sure you're not doing any synchronous network requests.

Admittedly, neither of these issues should be causing the sorts problem you describe, but they're still the sort of thing you want to be careful about when doing multithreaded code (and often when writing networking code, you often find yourself writing multithreaded code, even if it's not obvious). Writing thread-safe code is pretty complicated, but using FMDatabaseQueue rather than FMDatabase can simplify that process a bit.

Bottom line, there's nowhere near enough here to diagnose the problem. And frankly, assuming the root of the problem is multithreaded code rather than FMDB, this question might be better suited for a forum like Stack Overflow http://stackoverflow.com, making sure you provide short code snippets that illustrate how you're doing your network calls (NSURLSession? NSURLConnection? AFNetworking? Alamofire?) and describe the lifecycle of the FMDatabase and/or FMDatabaseQueue objects.

— Reply to this email directly or view it on GitHub https://github.com/ccgus/fmdb/issues/406#issuecomment-140293996.

Ali Parlar

aliparlar avatar Sep 15 '15 07:09 aliparlar

databasequeqe.inDatabase({ (db) in db.open() ...... db.close() }) try this !

Lojii avatar Jul 19 '18 12:07 Lojii