1010
1111#import " NEShakeGestureManager.h"
1212#import " NEHTTPModel.h"
13+ #if FMDB_SQLCipher
1314#include " sqlite3.h"
14-
15+ # endif
1516#define kSTRDoubleMarks @" \" "
1617#define kSQLDoubleMarks @" \"\" "
1718#define kSTRShortMarks @" '"
@@ -25,6 +26,12 @@ - (id)init {
2526 _sqlitePassword=kSQLitePassword ;
2627 self.saveRequestMaxCount =kSaveRequestMaxCount ;
2728 allRequests = [NSMutableArray arrayWithCapacity: 1 ];
29+ #if FMDB_SQLCipher
30+ enablePersistent = YES ;
31+ #else
32+ enablePersistent = NO ;
33+
34+ #endif
2835 }
2936 return self;
3037}
@@ -52,13 +59,14 @@ - (void)createTable {
5259
5360 NSMutableString *init_sqls=[NSMutableString stringWithCapacity: 1024 ];
5461 [init_sqls appendFormat: @" create table if not exists nenetworkhttpeyes(myID double primary key,startDateString text,endDateString text,requestURLString text,requestCachePolicy text,requestTimeoutInterval double,requestHTTPMethod text,requestAllHTTPHeaderFields text,requestHTTPBody text,responseMIMEType text,responseExpectedContentLength text,responseTextEncodingName text,responseSuggestedFilename text,responseStatusCode int,responseAllHeaderFields text,receiveJSONData text);" ];
55-
62+ #if FMDB_SQLCipher
63+
5664 FMDatabaseQueue *queue= [FMDatabaseQueue databaseQueueWithPath: [NEHTTPModelManager filename ]];
5765 [queue inDatabase: ^(FMDatabase *db) {
5866 [db setKey: _sqlitePassword];
5967 [db executeUpdate: init_sqls];
6068 }];
61-
69+ # endif
6270}
6371
6472- (void )addModel : (NEHTTPModel *) aModel {
@@ -81,11 +89,14 @@ - (void)addModel:(NEHTTPModel *) aModel {
8189 receiveJSONData=[self stringToSQLFilter: aModel.receiveJSONData];
8290 NSString *sql=[NSString stringWithFormat: @" insert into nenetworkhttpeyes values('%lf ','%@ ','%@ ','%@ ','%@ ','%lf ','%@ ','%@ ','%@ ','%@ ','%@ ','%@ ','%@ ','%d ','%@ ','%@ ')" ,aModel.myID,aModel.startDateString,aModel.endDateString,aModel.requestURLString,aModel.requestCachePolicy,aModel.requestTimeoutInterval,aModel.requestHTTPMethod,aModel.requestAllHTTPHeaderFields,aModel.requestHTTPBody,aModel.responseMIMEType,aModel.responseExpectedContentLength,aModel.responseTextEncodingName,aModel.responseSuggestedFilename,aModel.responseStatusCode,[self stringToSQLFilter: aModel.responseAllHeaderFields],receiveJSONData];
8391 if (enablePersistent) {
92+ #if FMDB_SQLCipher
93+
8494 FMDatabaseQueue *queue= [FMDatabaseQueue databaseQueueWithPath: [NEHTTPModelManager filename ]];
8595 [queue inDatabase: ^(FMDatabase *db) {
8696 [db setKey: _sqlitePassword];
8797 [db executeUpdate: sql];
8898 }];
99+ #endif
89100 }else {
90101 [allRequests addObject: aModel];
91102 }
@@ -102,7 +113,8 @@ - (NSMutableArray *)allobjects {
102113 }
103114 return allRequests;
104115 }
105-
116+ #if FMDB_SQLCipher
117+
106118 FMDatabaseQueue *queue= [FMDatabaseQueue databaseQueueWithPath: [NEHTTPModelManager filename ]];
107119 NSString *sql =[NSString stringWithFormat: @" select * from nenetworkhttpeyes order by myID desc" ];
108120 NSMutableArray *array=[NSMutableArray array ];
@@ -136,7 +148,8 @@ - (NSMutableArray *)allobjects {
136148 }
137149
138150 return array;
139-
151+ #endif
152+ return nil ;
140153}
141154
142155- (void ) deleteAllItem {
@@ -146,14 +159,16 @@ - (void) deleteAllItem {
146159 return ;
147160 }
148161 NSString *sql=[NSString stringWithFormat: @" delete from nenetworkhttpeyes" ];
162+ #if FMDB_SQLCipher
163+
149164 FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath: [NEHTTPModelManager filename ]];
150165 [queue inDatabase: ^(FMDatabase *db) {
151166 [db setKey: _sqlitePassword];
152167 [db executeUpdate: sql];
153168 }];
154169
155170 return ;
156-
171+ # endif
157172}
158173
159174
0 commit comments