diff options
author | rowanbeentje <rowan@beent.je> | 2009-09-01 23:09:21 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-09-01 23:09:21 +0000 |
commit | 1a6b920d5982840a405a6a53e0c3928b79066a9b (patch) | |
tree | 1c228187e9f5bfe66681578aebb9fe9526999ffe | |
parent | c193919cacda828749f7a25cded79bf0ab870190 (diff) | |
download | sequelpro-1a6b920d5982840a405a6a53e0c3928b79066a9b.tar.gz sequelpro-1a6b920d5982840a405a6a53e0c3928b79066a9b.tar.bz2 sequelpro-1a6b920d5982840a405a6a53e0c3928b79066a9b.zip |
- Use long longs instead of ints when looking at table sizes, free space, and row counts for display, fixing overflow issues (this addresses Issue #394)
- Tweak the byte size formatter to also show TBs for very large numbers
- Improve row count and auto increment value formatting by using a number formatter (enhancements for Issue #394)
-rw-r--r-- | Source/SPExtendedTableInfo.m | 18 | ||||
-rw-r--r-- | Source/SPStringAdditions.h | 2 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 12 | ||||
-rw-r--r-- | Source/SPTableInfo.m | 10 |
4 files changed, 32 insertions, 10 deletions
diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m index 0ac716cb..54830e9b 100644 --- a/Source/SPExtendedTableInfo.m +++ b/Source/SPExtendedTableInfo.m @@ -359,7 +359,7 @@ [key isEqualToString:@"Index_length"] || [key isEqualToString:@"Data_free"]) { - value = [NSString stringForByteSize:[value intValue]]; + value = [NSString stringForByteSize:[value longLongValue]]; } // Format date strings to the user's long date format else if ([key isEqualToString:@"Create_time"] || @@ -375,9 +375,19 @@ value = [dateFormatter stringFromDate:[NSDate dateWithNaturalLanguageString:value]]; } - // Prefix number of rows with '~' if it is not an accurate count - else if ([key isEqualToString:@"Rows"] && ![[infoDict objectForKey:@"RowsCountAccurate"] boolValue]) { - value = [@"~" stringByAppendingString:value]; + // Format numbers + else if ([key isEqualToString:@"Rows"] || + [key isEqualToString:@"Avg_row_length"] || + [key isEqualToString:@"Auto_increment"]) { + NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; + + value = [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:[value longLongValue]]]; + + // Prefix number of rows with '~' if it is not an accurate count + if ([key isEqualToString:@"Rows"] && ![[infoDict objectForKey:@"RowsCountAccurate"] boolValue]) { + value = [@"~" stringByAppendingString:value]; + } } } diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h index 6ee941c2..8ae44b38 100644 --- a/Source/SPStringAdditions.h +++ b/Source/SPStringAdditions.h @@ -40,7 +40,7 @@ static inline const char* NSStringUTF8String(NSString* self) { @interface NSString (SPStringAdditions) -+ (NSString *)stringForByteSize:(int)byteSize; ++ (NSString *)stringForByteSize:(long long)byteSize; + (NSString *)stringForTimeInterval:(float)timeInterval; - (NSString *)backtickQuotedString; diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 5ddc14f3..fdd37514 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -35,7 +35,7 @@ /* * Returns a human readable version string of the supplied byte size. */ -+ (NSString *)stringForByteSize:(int)byteSize ++ (NSString *)stringForByteSize:(long long)byteSize { float size = byteSize; @@ -67,7 +67,15 @@ size = (size / 1024); - [numberFormatter setFormat:@"#,##0.0 GB"]; + if (size < 1023) { + [numberFormatter setFormat:@"#,##0.0 GB"]; + + return [numberFormatter stringFromNumber:[NSNumber numberWithFloat:size]]; + } + + size = (size / 1024); + + [numberFormatter setFormat:@"#,##0.0 TB"]; return [numberFormatter stringFromNumber:[NSNumber numberWithFloat:size]]; } diff --git a/Source/SPTableInfo.m b/Source/SPTableInfo.m index 07e6d895..800a87dd 100644 --- a/Source/SPTableInfo.m +++ b/Source/SPTableInfo.m @@ -71,6 +71,8 @@ - (void)tableChanged:(NSNotification *)notification { NSDictionary *tableStatus; + NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; + [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; [info removeAllObjects]; @@ -128,14 +130,16 @@ // Check for 'Rows' == NULL - information_schema database doesn't report row count for it's tables if (![[tableStatus objectForKey:@"Rows"] isNSNull]) { - [info addObject:[NSString stringWithFormat:[[tableStatus objectForKey:@"RowsCountAccurate"] boolValue] ? @"rows: %@" : @"rows: ~%@", [tableStatus objectForKey:@"Rows"]]]; + [info addObject:[NSString stringWithFormat:[[tableStatus objectForKey:@"RowsCountAccurate"] boolValue] ? @"rows: %@" : @"rows: ~%@", + [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:[[tableStatus objectForKey:@"Rows"] longLongValue]]]]]; } - [info addObject:[NSString stringWithFormat:@"size: %@", [NSString stringForByteSize:[[tableStatus objectForKey:@"Data_length"] intValue]]]]; + [info addObject:[NSString stringWithFormat:@"size: %@", [NSString stringForByteSize:[[tableStatus objectForKey:@"Data_length"] longLongValue]]]]; [info addObject:[NSString stringWithFormat:@"encoding: %@", [tableDataInstance tableEncoding]]]; if (![[tableStatus objectForKey:@"Auto_increment"] isNSNull]) { - [info addObject:[NSString stringWithFormat:@"auto_increment: %@", [tableStatus objectForKey:@"Auto_increment"]]]; + [info addObject:[NSString stringWithFormat:@"auto_increment: %@", + [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:[[tableStatus objectForKey:@"Auto_increment"] longLongValue]]]]]; } } } |