2828#import " Constants.h"
2929#import < sqlite3.h>
3030
31- #define ERROR_COUNT_TO_RECREATE_SQLITE 25
32-
3331static sqlite3 *sqlite;
3432static BOOL retryOnCorrupt;
3533static BOOL willSendErrorLog;
36- static NSInteger errorCount;
3734
3835@implementation LPDatabase
3936
@@ -42,7 +39,6 @@ - (id)init
4239 if (self = [super init ]) {
4340 retryOnCorrupt = NO ;
4441 willSendErrorLog = NO ;
45- errorCount = 0 ;
4642 [self initSQLite ];
4743 }
4844 return self;
@@ -60,7 +56,6 @@ - (sqlite3 *)initSQLite
6056 return nil ;
6157 }
6258 retryOnCorrupt = NO ;
63- errorCount = 0 ;
6459
6560 // Create tables.
6661 [self runQuery: @" CREATE TABLE IF NOT EXISTS event ("
@@ -103,13 +98,11 @@ - (void)handleSQLiteError:(NSString *)errorName errorResult:(int)result query:(N
10398 }
10499 LPLog (LPError, @" %@ : %@ " , errorName, reason);
105100
106- // If SQLite is corrupted or if there are too many errors , create a new one.
101+ // If SQLite is corrupted, create a new one.
107102 // Using retryOnCorrupt to prevent infinite loop.
108- errorCount++;
109- if ((result == SQLITE_CORRUPT || errorCount >= ERROR_COUNT_TO_RECREATE_SQLITE) && !retryOnCorrupt) {
103+ if (result == SQLITE_CORRUPT && !retryOnCorrupt) {
110104 [[NSFileManager defaultManager ] removeItemAtPath: [LPDatabase sqliteFilePath ] error: nil ];
111105 retryOnCorrupt = YES ;
112- errorCount = 0 ;
113106 [self initSQLite ];
114107 }
115108}
@@ -132,7 +125,6 @@ - (sqlite3_stmt *)sqliteStatementFromQuery:(NSString *)query
132125 [self handleSQLiteError: @" SQLite fail to prepare" errorResult: result query: query];
133126 return nil ;
134127 }
135- errorCount = 0 ;
136128
137129 // Bind objects.
138130 // It is recommended to use this instead of making a full query in NSString to
@@ -149,8 +141,6 @@ - (sqlite3_stmt *)sqliteStatementFromQuery:(NSString *)query
149141 if (result != SQLITE_OK) {
150142 NSString *message = [NSString stringWithFormat: @" SQLite fail to bind %@ to %ld " , obj, idx+1 ];
151143 [self handleSQLiteError: message errorResult: result query: query];
152- } else {
153- errorCount = 0 ;
154144 }
155145 }];
156146
@@ -178,8 +168,6 @@ - (void)runQuery:(NSString *)query bindObjects:(NSArray *)objectsToBind
178168 int result = sqlite3_step (statement);
179169 if (result != SQLITE_DONE) {
180170 [self handleSQLiteError: @" SQLite fail to run query" errorResult: result query: query];
181- } else {
182- errorCount = 0 ;
183171 }
184172 willSendErrorLog = NO ;
185173 sqlite3_finalize (statement);
@@ -232,7 +220,6 @@ - (NSArray *)rowsFromQuery:(NSString *)query bindObjects:(NSArray *)objectsToBin
232220 [rows addObject: columnData];
233221 }
234222 sqlite3_finalize (statement);
235- errorCount = 0 ;
236223 return rows;
237224 }
238225 return @[];
0 commit comments