Code Monkey home page Code Monkey logo

Comments (12)

zaplitny avatar zaplitny commented on June 27, 2024

I had the same issue, so had to turn statement caching off

from fmdb.

ccgus avatar ccgus commented on June 27, 2024

Besides turning off statement caching, are there any proposed fixes? I'm not sure that there is real solution to this. Nested result sets list this just aren't going to work without removing the benefits of cached statements. At least, that's the conclusion I've come to with a tiny bit of thought involved. I'm fine with being proven wrong :)

from fmdb.

mattstevens avatar mattstevens commented on June 27, 2024

I'm probably missing something important but had a couple ideas:

A simple fix is to allow passing a custom key to use for the cached statement. If each level of nesting uses a unique key things should work as expected.

It may also be possible to handle this automatically:

  • FMStatement has a weak reference to the object using it.
  • The owning object (FMResultSet) zeros the reference on dealloc, happens automatically in some environments.
  • cachedStatements has an NSArray for each query. When fetching a statement it finds the first that has a nil owner. If there isn't one a new statement is created for the same query and added to the pool. (Since this is an edge case a class test could be used to only switch to an array when needed).

The danger here is if a lot of FMResultSets are created in a loop and not released until the loop ends you'll get a bunch of cached statements you don't need. But if you run this loop multiple times it will be fast :-)

from fmdb.

ccgus avatar ccgus commented on June 27, 2024

Yea, it could probably have some sort of flag that says "I'm in use right now".

Since there's a reasonable workaround for now, it won't be a high priority for me. But if you do end up writing a patch, let me know.

from fmdb.

TomSwift avatar TomSwift commented on June 27, 2024

My feeling is that FMDB should have a mechanism for exposing the FMStatement to the app, which the app can reuse as desired. Then there is no need to have "statement caching" at all.

Something like this:

  • (FMStatement_) statementForSql: (NSString_) sql;
  • (FMResultSet_) executeStatement: (FMStatement_) statement, ...;

from fmdb.

ChristianKienle avatar ChristianKienle commented on June 27, 2024

Suggestion: Mention the issues with the caching in the tutorial. We just spent 6 hours debugging and then found out it was FMDBs caching that caused problems...

from fmdb.

ccarse avatar ccarse commented on June 27, 2024

Is this still an issue?

from fmdb.

ccgus avatar ccgus commented on June 27, 2024

Yes, it's still an issue.

from fmdb.

noamtm avatar noamtm commented on June 27, 2024

This issue was reported 2.5 years ago.
We started using FMDB in a highly multithreaded, database driven, iOS application 1.5 years ago.

And we just spent about 2 days debugging our code, until someone thought it might be related to statement caching, disabled it, and found this issue here.

Is there a chance of it being fixed like @TomSwift suggests, or at least mentioning the issue in the tutorial as suggested by @ChristianKienle?
If we contribute the code, will it be added to master?

from fmdb.

ccgus avatar ccgus commented on June 27, 2024

If the code is reasonable, has tests, and doesn't break existing installs, then yes I would be happy to add it to the master branch.

from fmdb.

scottcc avatar scottcc commented on June 27, 2024

Curious - did issue #191 fix this?

from fmdb.

ccgus avatar ccgus commented on June 27, 2024

Yep, looks like it. I'll close this bug.

from fmdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.