BugsBiteBugs / sqlitepersistentobjects

Automatically exported from code.google.com/p/sqlitepersistentobjects
0 stars 0 forks source link

Cache SQL statements for increased efficiency #51

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
There might be some efficiency gain from caching the SQL statements.

You could have a mutable dictionary for the cache, with the keys being the 
query strings, and the 
values being the compiled statements (stored as NSData, perhaps).  When a query 
is needed, build 
the query string as now, then try to get that string from the dictionary via 
-objectForKey:.  If 
something is returned, use it.  Otherwise, prepare the statement and add it to 
the cache.  You could 
have one method to do that work.

I'm not sure what kind of performance gain that might give, but other SQL code 
samples seem to 
imply that caching statements is a worthwhile thing, and it seems like it'd be 
an easy thing to 
achieve.

Original issue reported on code.google.com by goo...@dejal.com on 7 Mar 2009 at 6:20