aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMCopyTable.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-10-10 00:06:52 +0000
committerrowanbeentje <rowan@beent.je>2009-10-10 00:06:52 +0000
commit0371f943f790d4c20ba5947a90db6cbe41669710 (patch)
tree53834dfe68b609773a0c9b0f0ccb79b3114a44af /Source/CMCopyTable.m
parenta65889bc725c192813f568f606071268693fce5d (diff)
downloadsequelpro-0371f943f790d4c20ba5947a90db6cbe41669710.tar.gz
sequelpro-0371f943f790d4c20ba5947a90db6cbe41669710.tar.bz2
sequelpro-0371f943f790d4c20ba5947a90db6cbe41669710.zip
Improve handling of NULL and "(not loaded)" placeholders:
- Rewrite TableContent and CustomQuery to store NSNull and SPNotLoaded objects in the data arrays where appropriate, rather than providing string conversion on data load. Faster, simpler comparisons and processing code, slightly lower memory usage, and reduces the chance of bugs caused by inadvertantly processing the string values; we can now also distinguish easily between NULL and "NULL" etc, and further paves the ground for image representations of special values. - Fix a bug caused by consistent value reloading when editing BLOB/TEXT columns with deferred loading - if editing a row and revisiting an edited cell, the original value was restored; the original value is now only loaded once. This addresses the rest of Issue #423.
Diffstat (limited to 'Source/CMCopyTable.m')
-rw-r--r--Source/CMCopyTable.m24
1 files changed, 17 insertions, 7 deletions
diff --git a/Source/CMCopyTable.m b/Source/CMCopyTable.m
index f42ff783..23bf7804 100644
--- a/Source/CMCopyTable.m
+++ b/Source/CMCopyTable.m
@@ -29,6 +29,7 @@
#import "SPStringAdditions.h"
#import "TableContent.h"
#import "CustomQuery.h"
+#import "SPNotLoaded.h"
int MENU_EDIT_COPY_WITH_COLUMN = 2001;
int MENU_EDIT_COPY_AS_SQL = 2002;
@@ -131,7 +132,12 @@ int MENU_EDIT_COPY_AS_SQL = 2002;
if ( nil != rowData )
{
- [result appendString:[NSString stringWithFormat:@"%@\t", [rowData description] ] ];
+ if ([rowData isNSNull])
+ [result appendString:[NSString stringWithFormat:@"%@\t", [prefs objectForKey:@"nullValue"]]];
+ else if ([rowData isSPNotLoaded])
+ [result appendString:[NSString stringWithFormat:@"%@\t", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")]];
+ else
+ [result appendString:[NSString stringWithFormat:@"%@\t", [rowData description] ] ];
}
else
{
@@ -175,7 +181,6 @@ int MENU_EDIT_COPY_AS_SQL = 2002;
NSUInteger numColumns = [columns count];
NSIndexSet *selectedRows = [self selectedRowIndexes];
- NSString *spNULL = [prefs objectForKey:@"NullValue"];
NSMutableString *value = [NSMutableString stringWithCapacity:10];
NSArray *dbDataRow;
NSMutableArray *columnMappings;
@@ -227,8 +232,8 @@ int MENU_EDIT_COPY_AS_SQL = 2002;
{
rowData = [[tableData objectAtIndex:rowIndex] objectAtIndex:[[columnMappings objectAtIndex:c] intValue]];
- // Check for NULL value - TODO this is not safe!!
- if([[rowData description] isEqualToString:spNULL]){
+ // Check for NULL value
+ if([rowData isNSNull]) {
[value appendString:@"NULL, "];
continue;
}
@@ -243,7 +248,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002;
[mySQLConnection prepareString:[rowData description]]]];
break;
case 2: // blob
- if (![[self delegate] isKindOfClass:[CustomQuery class]] && [prefs boolForKey:@"LoadBlobsAsNeeded"]) {
+ if (![[self delegate] isKindOfClass:[CustomQuery class]] && [rowData isSPNotLoaded]) {
// Abort if there are no indices on this table or if there's no table name given.
if (![[tableInstance argumentForRow:rowIndex] length] || selectedTable == nil)
@@ -253,7 +258,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002;
dbDataRow = [[mySQLConnection queryString:
[NSString stringWithFormat:@"SELECT * FROM %@ WHERE %@",
[selectedTable backtickQuotedString], [tableInstance argumentForRow:rowIndex]]] fetchRowAsArray];
- if([[dbDataRow objectAtIndex:[[columnMappings objectAtIndex:c] intValue]] isKindOfClass:[NSNull class]])
+ if([[dbDataRow objectAtIndex:[[columnMappings objectAtIndex:c] intValue]] isNSNull])
[value appendString:@"NULL, "];
else
[value appendString:[NSString stringWithFormat:@"X'%@', ",
@@ -365,7 +370,12 @@ int MENU_EDIT_COPY_AS_SQL = 2002;
if ( nil != rowData )
{
- [result appendString:[NSString stringWithFormat:@"%@\t", [rowData description] ] ];
+ if ([rowData isNSNull])
+ [result appendString:[NSString stringWithFormat:@"%@\t", [prefs objectForKey:@"nullValue"]]];
+ else if ([rowData isSPNotLoaded])
+ [result appendString:[NSString stringWithFormat:@"%@\t", NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields")]];
+ else
+ [result appendString:[NSString stringWithFormat:@"%@\t", [rowData description] ] ];
}
else
{