Skip to content

Commit

Permalink
修复bug.
Browse files Browse the repository at this point in the history
修复bug.
  • Loading branch information
huangzhibiao committed May 3, 2018
1 parent bdae086 commit b0fa9e0
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BGFMDB/ViewController.m"
timestampString = "543403640.977806"
timestampString = "547039803.062616"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "414"
endingLineNumber = "414"
startingLineNumber = "412"
endingLineNumber = "412"
landmarkName = "-testT"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -84,27 +84,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BGFMDB/ViewController.m"
timestampString = "543403640.978277"
timestampString = "547039803.063116"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "195"
endingLineNumber = "195"
landmarkName = "-viewDidLoad"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BGFMDB/ViewController.m"
timestampString = "543403640.978541"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "190"
endingLineNumber = "190"
startingLineNumber = "193"
endingLineNumber = "193"
landmarkName = "-viewDidLoad"
landmarkType = "7">
</BreakpointContent>
Expand Down
4 changes: 1 addition & 3 deletions BGFMDB/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ - (void)viewDidLoad {
直接存储字典.
*/
//[self testSaveDictionary];

/**
直接存储自定义对象.
*/
Expand Down Expand Up @@ -182,7 +181,6 @@ - (void)viewDidLoad {
说明: 本次更新版本号必须 大于 上次的版本号,否则不会更新.
*/
// [People bg_update:bg_tablename version:1];

/**
当数据量巨大时采用分页范围查询.
*/
Expand All @@ -196,7 +194,7 @@ - (void)viewDidLoad {
}

//顺便取第一个对象数据测试
if(i==0){
if(i==1){
People* lastP = arr.lastObject;
_showImage.image = lastP.image;
_showLab.attributedText = lastP.attriStr;
Expand Down
9 changes: 0 additions & 9 deletions BGFMDB/libs/BG/BGDB.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
*/
#define SQLITE_NAME @"BGFMDB.db"

/**
日志输出
*/
#ifdef DEBUG
#define bg_log(...) NSLog(__VA_ARGS__)
#else
#define bg_log(...)
#endif

#define bg_debug(param) do{\
if(self.debug){bg_log(@"调试输出: %@",param);}\
}while(0)
Expand Down
13 changes: 9 additions & 4 deletions BGFMDB/libs/BG/BGTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
#import <Foundation/Foundation.h>
#import <objc/runtime.h>

/**
日志输出
*/
#ifdef DEBUG
#define bg_log(...) NSLog(__VA_ARGS__)
#else
#define bg_log(...)
#endif

#define bg_completeBlock(obj) !complete?:complete(obj);

#define BG @"BG_"
Expand Down Expand Up @@ -40,10 +49,6 @@ typedef NS_ENUM(NSInteger,bg_getModelInfoType){//过滤数据类型
@onlyKey YES:紧紧返回key,NO:在key后面添加type.
*/
+(NSArray* _Nonnull)getClassIvarList:(__unsafe_unretained _Nonnull Class)cla Object:(_Nullable id)object onlyKey:(BOOL)onlyKey;
/**
判断系统类型与否
*/
+(BOOL)isKindOfSystemType:(NSString* _Nonnull)type;
/**
抽取封装条件数组处理函数.
*/
Expand Down
104 changes: 44 additions & 60 deletions BGFMDB/libs/BG/BGTool.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ @implementation BGTool

if ([value isKindOfClass:[NSNumber class]]) {
return value;
}

NSString* type = [NSString stringWithFormat:@"@\"%@\"",NSStringFromClass([value class])];
value = [BGTool getSqlValue:value type:type encode:YES];
if ([value isKindOfClass:[NSString class]]) {
}else if ([value isKindOfClass:[NSNumber class]]){
return [NSString stringWithFormat:@"'%@'",value];
}else{
return value;
NSString* type = [NSString stringWithFormat:@"@\"%@\"",NSStringFromClass([value class])];
value = [BGTool getSqlValue:value type:type encode:YES];
if ([value isKindOfClass:[NSString class]]) {
return [NSString stringWithFormat:@"'%@'",value];
}else{
return value;
}
}

}

/**
Expand Down Expand Up @@ -392,10 +393,15 @@ +(NSString*)getSqlType:(NSString*)type{
+(NSString *)jsonStringWithObject:(id)object{
NSMutableDictionary* keyValueDict = [NSMutableDictionary dictionary];
NSArray* keyAndTypes = [BGTool getClassIvarList:[object class] Object:object onlyKey:NO];
//忽略属性
NSArray* ignoreKeys = [BGTool executeSelector:bg_ignoreKeysSelector forClass:[object class]];
for(NSString* keyAndType in keyAndTypes){
NSArray* arr = [keyAndType componentsSeparatedByString:@"*"];
NSString* propertyName = arr[0];
NSString* propertyType = arr[1];

if([ignoreKeys containsObject:propertyName])continue;

if(![propertyName isEqualToString:bg_primaryKey]){
id propertyValue = [object valueForKey:propertyName];
if (propertyValue){
Expand Down Expand Up @@ -506,49 +512,49 @@ +(NSString*)jsonStringWithNSHashTable:(NSHashTable*)hashTable{
//NSDate转字符串,格式: yyyy-MM-dd HH:mm:ss
+(NSString*)stringWithDate:(NSDate*)date{
NSDateFormatter* formatter = [NSDateFormatter new];
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSS";
return [formatter stringFromDate:date];
}
//跟value和数据类型type 和编解码标志 返回编码插入数据库的值,或解码数据库的值.
+(id)getSqlValue:(id)value type:(NSString*)type encode:(BOOL)encode{
if(!value || [value isKindOfClass:[NSNull class]])return nil;

if([type containsString:@"String"]){
if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"String"]){
if([type containsString:@"AttributedString"]){//处理富文本.
if(encode) {
return [[NSKeyedArchiver archivedDataWithRootObject:value] base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength];
return [[NSKeyedArchiver archivedDataWithRootObject:value] base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}else{
NSData* data = [[NSData alloc] initWithBase64EncodedString:value options:NSDataBase64DecodingIgnoreUnknownCharacters];
NSData* data = [[NSData alloc] initWithBase64EncodedString:value options:NSDataBase64DecodingIgnoreUnknownCharacters];
return [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
}else{
return value;
}
}else if([type containsString:@"Number"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"Number"]){
if(encode) {
return [NSString stringWithFormat:@"%@",value];
}else{
return [[NSNumberFormatter new] numberFromString:value];
}
}else if([type containsString:@"Array"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"Array"]){
if(encode){
return [self jsonStringWithArray:value];
}else{
return [self arrayFromJsonString:value];
}
}else if([type containsString:@"Dictionary"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"Dictionary"]){
if(encode){
return [self jsonStringWithDictionary:value];
}else{
return [self dictionaryFromJsonString:value];
}
}else if([type containsString:@"Set"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"Set"]){
if(encode){
return [self jsonStringWithArray:value];
}else{
return [self arrayFromJsonString:value];
}
}else if([type containsString:@"Data"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"Data"]){
if(encode){
NSData* data = value;
NSNumber* maxLength = MaxData;
Expand All @@ -557,31 +563,31 @@ +(id)getSqlValue:(id)value type:(NSString*)type encode:(BOOL)encode{
}else{
return [[NSData alloc] initWithBase64EncodedString:value options:NSDataBase64DecodingIgnoreUnknownCharacters];
}
}else if([type containsString:@"NSMapTable"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"MapTable"]){
if(encode){
return [self jsonStringWithMapTable:value];
}else{
return [self mapTableFromJsonString:value];
}
}else if ([type containsString:@"NSHashTable"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"HashTable"]){
if(encode){
return [self jsonStringWithNSHashTable:value];
}else{
return [self hashTableFromJsonString:value];
}
}else if ([type containsString:@"NSDate"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"Date"]){
if(encode){
return [self stringWithDate:value];
}else{
return [self dateFromString:value];
}
}else if ([type containsString:@"NSURL"]){
}else if(([type hasPrefix:@"@\"NS"]||[type hasPrefix:@"@\"__NS"])&&[type containsString:@"URL"]){
if(encode){
return [value absoluteString];
}else{
return [NSURL URLWithString:value];
}
}else if ([type containsString:@"UIImage"]){
}else if(([type hasPrefix:@"@\"UI"]||[type hasPrefix:@"@\"__UI"])&&[type containsString:@"Image"]){
if(encode){
NSData* data = UIImageJPEGRepresentation(value, 1);
NSNumber* maxLength = MaxData;
Expand All @@ -590,7 +596,7 @@ +(id)getSqlValue:(id)value type:(NSString*)type encode:(BOOL)encode{
}else{
return [UIImage imageWithData:[[NSData alloc] initWithBase64EncodedString:value options:NSDataBase64DecodingIgnoreUnknownCharacters]];
}
}else if ([type containsString:@"UIColor"]){
}else if(([type hasPrefix:@"@\"UI"]||[type hasPrefix:@"@\"__UI"])&&[type containsString:@"Color"]){
if(encode){
CGFloat r, g, b, a;
[value getRed:&r green:&g blue:&b alpha:&a];
Expand Down Expand Up @@ -634,45 +640,23 @@ +(id)getSqlValue:(id)value type:(NSString*)type encode:(BOOL)encode{
[type isEqualToString:@"d"]||[type isEqualToString:@"D"]){
return value;
}else{

if(encode){
return [self jsonStringWithArray:@[value]];
NSBundle *bundle = [NSBundle bundleForClass:[value class]];
if(bundle == [NSBundle mainBundle]){//自定义的类
return [self jsonStringWithArray:@[value]];
}else{//特殊类型
return [[NSKeyedArchiver archivedDataWithRootObject:value] base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}
}else{
return [self arrayFromJsonString:value].firstObject;
if([value containsString:BGModel]){//自定义的类
return [self arrayFromJsonString:value].firstObject;
}else{//特殊类型
NSData* data = [[NSData alloc] initWithBase64EncodedString:value options:NSDataBase64DecodingIgnoreUnknownCharacters];
return [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
}
}
}
/**
判断系统类型与否
*/
+(BOOL)isKindOfSystemType:(NSString*)type{

if([type containsString:@"String"]||
[type containsString:@"Number"]||
[type containsString:@"Array"]||
[type containsString:@"Dictionary"]||
[type containsString:@"Set"]||
[type containsString:@"Data"]||
[type containsString:@"NSMapTable"]||
[type containsString:@"NSHashTable"]||
[type containsString:@"NSDate"]||
[type containsString:@"NSURL"]||
[type containsString:@"UIImage"]||
[type containsString:@"UIColor"]||
[type containsString:@"NSRange"]||
([type containsString:@"CGRect"]&&[type containsString:@"CGPoint"]&&[type containsString:@"CGSize"])||
(![type containsString:@"CGRect"]&&[type containsString:@"CGPoint"]&&![type containsString:@"CGSize"])||
(![type containsString:@"CGRect"]&&![type containsString:@"CGPoint"]&&[type containsString:@"CGSize"])||
[type isEqualToString:@"i"]||[type isEqualToString:@"I"]||
[type isEqualToString:@"s"]||[type isEqualToString:@"S"]||
[type isEqualToString:@"q"]||[type isEqualToString:@"Q"]||
[type isEqualToString:@"b"]||[type isEqualToString:@"B"]||
[type isEqualToString:@"c"]||[type isEqualToString:@"C"]||
[type isEqualToString:@"l"]||[type isEqualToString:@"L"]||
[type isEqualToString:@"f"]||[type isEqualToString:@"F"]||
[type isEqualToString:@"d"]||[type isEqualToString:@"D"]){
return YES;
}else{
return NO;

}
}

Expand Down Expand Up @@ -706,7 +690,7 @@ +(id)objectFromJsonStringWithTableName:(NSString* _Nonnull)tablename class:(__un
NSString* type = [arrKT lastObject];

if ([tempSqlKey isEqualToString:key]){
NSString* tempValue = valueDict[sqlKey];
id tempValue = valueDict[sqlKey];
id ivarValue = [self getSqlValue:tempValue type:type encode:NO];
!ivarValue?:[object setValue:ivarValue forKey:key];
[keyAndTypes removeObject:keyAndType];
Expand Down Expand Up @@ -957,7 +941,7 @@ +(NSDate*)dateFromString:(NSString*)jsonString{
if(!jsonString || [jsonString isKindOfClass:[NSNull class]])return nil;

NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSS";
NSDate *date = [formatter dateFromString:jsonString];
return date;
}
Expand Down
1 change: 1 addition & 0 deletions BGFMDB/libs/BG/NSObject+BGModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ NSMutableData,UIImage,NSDate,NSURL,NSRange,CGRect,CGSize,CGPoint,自定义对象
2017-07-19 16 即查询2017年7月19日16时的数据
2017-07-19 16:17 即查询2017年7月19日16时17分的数据
2017-07-19 16:17:53 即查询2017年7月19日16时17分53秒的数据
2017-07-19 16:17:53.350 即查询2017年7月19日16时17分53秒350毫秒的数据
*/
+(NSArray* _Nullable)bg_find:(NSString* _Nullable)tablename type:(bg_dataTimeType)type dateTime:(NSString* _Nonnull)dateTime;

Expand Down
1 change: 1 addition & 0 deletions BGFMDB/libs/BG/NSObject+BGModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ +(void)bg_findAsync:(NSString* _Nullable)tablename where:(NSString* _Nullable)wh
2017-07-19 16 即查询2017年7月19日16时的数据
2017-07-19 16:17 即查询2017年7月19日16时17分的数据
2017-07-19 16:17:53 即查询2017年7月19日16时17分53秒的数据
2017-07-19 16:17:53.350 即查询2017年7月19日16时17分53秒350毫秒的数据
*/
+(NSArray* _Nullable)bg_find:(NSString* _Nullable)tablename type:(bg_dataTimeType)type dateTime:(NSString* _Nonnull)dateTime{
if(tablename == nil) {
Expand Down
4 changes: 3 additions & 1 deletion BGFMDB/people.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ @implementation People
@end

@implementation User

//+(NSArray *)bg_ignoreKeys{
// return @[@"attri",@"userNumer",@"student",@"userP"];
//}
@end

@implementation Student
Expand Down

0 comments on commit b0fa9e0

Please sign in to comment.