|
@@ -163,8 +163,8 @@ - (BOOL)close {
|
|
|
|
|
|
|
|
- (void)clearCachedStatements {
|
|
- (void)clearCachedStatements {
|
|
|
|
|
|
|
|
- for (FMStatement *cachedStmt in [_cachedStatements objectEnumerator]) {
|
|
|
|
|
- [cachedStmt close];
|
|
|
|
|
|
|
+ for (NSMutableSet *statements in [_cachedStatements objectEnumerator]) {
|
|
|
|
|
+ [statements makeObjectsPerformSelector:@selector(close)];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[_cachedStatements removeAllObjects];
|
|
[_cachedStatements removeAllObjects];
|
|
@@ -195,21 +195,35 @@ - (void)resultSetDidClose:(FMResultSet *)resultSet {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (FMStatement*)cachedStatementForQuery:(NSString*)query {
|
|
- (FMStatement*)cachedStatementForQuery:(NSString*)query {
|
|
|
- return [_cachedStatements objectForKey:query];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableSet* statements = [_cachedStatements objectForKey:query];
|
|
|
|
|
+
|
|
|
|
|
+ return [[statements objectsPassingTest:^BOOL(FMStatement* statement, BOOL *stop) {
|
|
|
|
|
+
|
|
|
|
|
+ *stop = ![statement inUse];
|
|
|
|
|
+ return *stop;
|
|
|
|
|
+
|
|
|
|
|
+ }] anyObject];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
- (void)setCachedStatement:(FMStatement*)statement forQuery:(NSString*)query {
|
|
- (void)setCachedStatement:(FMStatement*)statement forQuery:(NSString*)query {
|
|
|
|
|
|
|
|
query = [query copy]; // in case we got handed in a mutable string...
|
|
query = [query copy]; // in case we got handed in a mutable string...
|
|
|
-
|
|
|
|
|
[statement setQuery:query];
|
|
[statement setQuery:query];
|
|
|
|
|
|
|
|
- [_cachedStatements setObject:statement forKey:query];
|
|
|
|
|
|
|
+ NSMutableSet* statements = [_cachedStatements objectForKey:query];
|
|
|
|
|
+ if (!statements) {
|
|
|
|
|
+ statements = [NSMutableSet set];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [statements addObject:statement];
|
|
|
|
|
+
|
|
|
|
|
+ [_cachedStatements setObject:statements forKey:query];
|
|
|
|
|
|
|
|
FMDBRelease(query);
|
|
FMDBRelease(query);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- (BOOL)rekey:(NSString*)key {
|
|
- (BOOL)rekey:(NSString*)key {
|
|
|
NSData *keyData = [NSData dataWithBytes:(void *)[key UTF8String] length:(NSUInteger)strlen([key UTF8String])];
|
|
NSData *keyData = [NSData dataWithBytes:(void *)[key UTF8String] length:(NSUInteger)strlen([key UTF8String])];
|
|
|
|
|
|
|
@@ -1212,6 +1226,7 @@ @implementation FMStatement
|
|
|
@synthesize statement=_statement;
|
|
@synthesize statement=_statement;
|
|
|
@synthesize query=_query;
|
|
@synthesize query=_query;
|
|
|
@synthesize useCount=_useCount;
|
|
@synthesize useCount=_useCount;
|
|
|
|
|
+@synthesize inUse=_inUse;
|
|
|
|
|
|
|
|
- (void)finalize {
|
|
- (void)finalize {
|
|
|
[self close];
|
|
[self close];
|
|
@@ -1231,12 +1246,16 @@ - (void)close {
|
|
|
sqlite3_finalize(_statement);
|
|
sqlite3_finalize(_statement);
|
|
|
_statement = 0x00;
|
|
_statement = 0x00;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ _inUse = NO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)reset {
|
|
- (void)reset {
|
|
|
if (_statement) {
|
|
if (_statement) {
|
|
|
sqlite3_reset(_statement);
|
|
sqlite3_reset(_statement);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ _inUse = NO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)description {
|
|
- (NSString*)description {
|