Skip to content

Commit

Permalink
[feature]为是否持久化增加宏定义
Browse files Browse the repository at this point in the history
  • Loading branch information
coderyi committed Sep 25, 2016
1 parent d87522b commit 48b38e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions NetworkEye/NetworkEye/NEHTTPModelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
//

#import <Foundation/Foundation.h>
#if FMDB_SQLCipher
#import "FMDB.h"
#endif
#import "NEHTTPEye.h"
@class NEHTTPModel;
@interface NEHTTPModelManager : NSObject
{
#if FMDB_SQLCipher
FMDatabaseQueue *sqliteDatabase;
#endif
NSMutableArray *allRequests;
BOOL enablePersistent;
}
Expand Down
27 changes: 21 additions & 6 deletions NetworkEye/NetworkEye/NEHTTPModelManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

#import "NEShakeGestureManager.h"
#import "NEHTTPModel.h"
#if FMDB_SQLCipher
#include "sqlite3.h"

#endif
#define kSTRDoubleMarks @"\""
#define kSQLDoubleMarks @"\"\""
#define kSTRShortMarks @"'"
Expand All @@ -25,6 +26,12 @@ - (id)init {
_sqlitePassword=kSQLitePassword;
self.saveRequestMaxCount=kSaveRequestMaxCount;
allRequests = [NSMutableArray arrayWithCapacity:1];
#if FMDB_SQLCipher
enablePersistent = YES;
#else
enablePersistent = NO;

#endif
}
return self;
}
Expand Down Expand Up @@ -52,13 +59,14 @@ - (void)createTable {

NSMutableString *init_sqls=[NSMutableString stringWithCapacity:1024];
[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);"];

#if FMDB_SQLCipher

FMDatabaseQueue *queue= [FMDatabaseQueue databaseQueueWithPath:[NEHTTPModelManager filename]];
[queue inDatabase:^(FMDatabase *db) {
[db setKey:_sqlitePassword];
[db executeUpdate:init_sqls];
}];
#endif
}

- (void)addModel:(NEHTTPModel *) aModel {
Expand All @@ -81,11 +89,14 @@ - (void)addModel:(NEHTTPModel *) aModel {
receiveJSONData=[self stringToSQLFilter:aModel.receiveJSONData];
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];
if (enablePersistent) {
#if FMDB_SQLCipher

FMDatabaseQueue *queue= [FMDatabaseQueue databaseQueueWithPath:[NEHTTPModelManager filename]];
[queue inDatabase:^(FMDatabase *db) {
[db setKey:_sqlitePassword];
[db executeUpdate:sql];
}];
#endif
}else {
[allRequests addObject:aModel];
}
Expand All @@ -102,7 +113,8 @@ - (NSMutableArray *)allobjects {
}
return allRequests;
}

#if FMDB_SQLCipher

FMDatabaseQueue *queue= [FMDatabaseQueue databaseQueueWithPath:[NEHTTPModelManager filename]];
NSString *sql =[NSString stringWithFormat:@"select * from nenetworkhttpeyes order by myID desc"];
NSMutableArray *array=[NSMutableArray array];
Expand Down Expand Up @@ -136,7 +148,8 @@ - (NSMutableArray *)allobjects {
}

return array;

#endif
return nil;
}

- (void) deleteAllItem {
Expand All @@ -146,14 +159,16 @@ - (void) deleteAllItem {
return;
}
NSString *sql=[NSString stringWithFormat:@"delete from nenetworkhttpeyes"];
#if FMDB_SQLCipher

FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:[NEHTTPModelManager filename]];
[queue inDatabase:^(FMDatabase *db) {
[db setKey:_sqlitePassword];
[db executeUpdate:sql];
}];

return ;
#endif
}


Expand Down

0 comments on commit 48b38e5

Please sign in to comment.