From 4ae24d7753c5699eea62da16d5b1be251c6aeb4e Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 17 Jul 2009 16:46:19 +0000 Subject: =?UTF-8?q?=E2=80=A2=20changed=20in=20Custom=20Query:=20-=20make?= =?UTF-8?q?=20usage=20of=20SPFieldEditor=20for=20displaying=20result=20dat?= =?UTF-8?q?a=20field=20(incl.=20blob=20data)=20-=20set=20to=20non-editable?= =?UTF-8?q?=20yet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/FieldEditorSheet.xib | 6 +- Source/CustomQuery.m | 124 ++++++++++---------------- Source/SPFieldEditorController.m | 13 +-- 3 files changed, 57 insertions(+), 86 deletions(-) diff --git a/Interfaces/English.lproj/FieldEditorSheet.xib b/Interfaces/English.lproj/FieldEditorSheet.xib index e4f5ccdf..7a19f1a6 100644 --- a/Interfaces/English.lproj/FieldEditorSheet.xib +++ b/Interfaces/English.lproj/FieldEditorSheet.xib @@ -464,6 +464,7 @@ {667, 370} + @@ -496,6 +497,7 @@ {{0, 39}, {667, 370}} + 528 @@ -612,6 +614,7 @@ {667, 370} + @@ -641,6 +644,7 @@ {{0, 39}, {667, 370}} + 528 @@ -684,7 +688,7 @@ {{0, 0}, {1280, 778}} {560, 222} {3.40282e+38, 3.40282e+38} - SPEditSheet + diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 461dfba8..1626c6e5 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -34,6 +34,7 @@ #import "TableDocument.h" #import "TablesList.h" #import "RegexKitLite.h" +#import "SPFieldEditorController.h" #define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@" #define SP_HELP_SEARCH_IN_MYSQL 0 @@ -1541,94 +1542,59 @@ // Check if the field can identified bijectively if ( aTableView == customQueryView ) { - // TODO: only for testing - if([[NSApp currentEvent] modifierFlags] & NSCommandKeyMask) { - if(!tempAlertWasShown) { - NSRunCriticalAlertPanel ( - @"ATTENTION – ONLY FOR TESTING", - @"Editing result fields in Custom Query is a BETA feature!\n\nPlease DO NOT USE that feature in production!\n\nAnyway we'd be glad if you take a bit time to test that feature on TEST data.\n\nThank you very much for testing.\n\nThe Sequel-Pro team", - @"OK", - nil, - nil); - tempAlertWasShown = YES; - } - NSDictionary *columnDefinition; + NSDictionary *columnDefinition; + BOOL noTableName = NO; + BOOL isBlob; - // Retrieve the column defintion - for(id c in cqColumnDefinition) { - if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:[aTableColumn identifier]]) { - columnDefinition = [NSDictionary dictionaryWithDictionary:c]; - break; - } + // Retrieve the column defintion + for(id c in cqColumnDefinition) { + if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:[aTableColumn identifier]]) { + columnDefinition = [NSDictionary dictionaryWithDictionary:c]; + break; } + } + // Check if current field is a blob + if([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"textdata"] + || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"blobdata"]) { + isBlob = YES; + } else { + isBlob = NO; + } - // Check if current field is a blob - if([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"textdata"] - || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"blobdata"]) { - [errorText setStringValue:@"Editing blob data not yet supported."]; - NSBeep(); - return NO; - } - - // Resolve the original table name for current column if AS was used - NSString *tableForColumn = [columnDefinition objectForKey:@"org_table"]; - - // No table name found indicates that the field's column contains data from more than one table as for UNION - // or the field data are not bound to any table as in SELECT 1 - if(!tableForColumn || ![tableForColumn length]) { - [errorText setStringValue:[NSString stringWithFormat:@"Couldn't identify field origin unambiguously. The column '%@' contains data from more or less than one table.", [columnDefinition objectForKey:@"name"]]]; - NSBeep(); - return NO; - } - - NSString *fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn]; + // Resolve the original table name for current column if AS was used + NSString *tableForColumn = [columnDefinition objectForKey:@"org_table"]; - // Actual check whether field can be identified bijectively - int numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(*) FROM %@ %@", [tableForColumn backtickQuotedString], fieldIDQueryString]] fetchRowAsArray] objectAtIndex:0] intValue]; - if (numberOfPossibleUpdateRows == 1) - return YES; - else { - [errorText setStringValue:[NSString stringWithFormat:@"Field is not editable. Couldn't identify field origin unambiguously (%d match%@).", numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?@"es":@""]]; - NSBeep(); - return NO; - } - } - // TODO: keep old behaviour for testing - else { - id theRow; - NSString *theValue; - - //get the value - theRow = [fullResult objectAtIndex:rowIndex]; - - if ( [[theRow objectAtIndex:[[aTableColumn identifier] intValue]] isKindOfClass:[NSData class]] ) { - theValue = [[NSString alloc] initWithData:[theRow objectAtIndex:[[aTableColumn identifier] intValue]] - encoding:[mySQLConnection encoding]]; - if (theValue == nil) { - theValue = [[NSString alloc] initWithData:[theRow objectAtIndex:[[aTableColumn identifier] intValue]] - encoding:NSASCIIStringEncoding]; - } - [theValue autorelease]; - } else if ( [[theRow objectAtIndex:[[aTableColumn identifier] intValue]] isMemberOfClass:[NSNull class]] ) { - theValue = [prefs objectForKey:@"NullValue"]; - } else { - theValue = [theRow objectAtIndex:[[aTableColumn identifier] intValue]]; - } - - [valueTextField setString:[theValue description]]; - [valueTextField selectAll:self]; - [NSApp beginSheet:valueSheet - modalForWindow:tableWindow modalDelegate:self - didEndSelector:nil contextInfo:nil]; - [NSApp runModalForWindow:valueSheet]; + // No table name found indicates that the field's column contains data from more than one table as for UNION + // or the field data are not bound to any table as in SELECT 1 + if(!tableForColumn || ![tableForColumn length]) + noTableName = YES; - [NSApp endSheet:valueSheet]; - [valueSheet orderOut:nil]; + NSString *fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn]; - return NO; + // Actual check whether field can be identified bijectively + int numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(*) FROM %@ %@", [tableForColumn backtickQuotedString], fieldIDQueryString]] fetchRowAsArray] objectAtIndex:0] intValue]; + + BOOL isFieldEditable = (!noTableName && numberOfPossibleUpdateRows == 1) ? YES : NO; + + // if(!isFieldEditable) + // [errorText setStringValue:[NSString stringWithFormat:@"Field is not editable. Couldn't identify field origin unambiguously (%d match%@).", numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?@"es":@""]]; + + SPFieldEditorController *fieldEditor = [[SPFieldEditorController alloc] init]; + id editData = [[fieldEditor editWithObject:[[fullResult objectAtIndex:rowIndex] objectAtIndex:[[aTableColumn identifier] intValue]] + usingEncoding:[mySQLConnection encoding] isObjectBlob:isBlob isEditable:NO withWindow:tableWindow] retain]; + + if ( editData ) { + } + + [fieldEditor release]; + + if ( editData ) [editData release]; + + return NO; + } else { return YES; } diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index af5addf9..085a4933 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -72,16 +72,14 @@ if(!isEditable) { [editSheetOkButton setTitle:NSLocalizedString(@"Close", @"close button title")]; + [editSheetOkButton setKeyEquivalent:@"\033"]; // ESC key [editSheetCancelButton setHidden:YES]; [editSheetOpenButton setEnabled:NO]; - } else { - [editSheetOkButton setTitle:NSLocalizedString(@"OK", @"ok button title")]; - [editSheetCancelButton setHidden:NO]; - [editSheetOpenButton setEnabled:YES]; } editSheetWillBeInitialized = YES; + encoding = anEncoding; isBlob = isFieldBlob; @@ -100,10 +98,13 @@ [editSheetSegmentControl setHidden:(!isBlob)]; // Set window's min size since no segment and quicklook buttons are hidden - if(isBlob) + if(isBlob) { + [editSheet setFrameAutosaveName:@"SPFieldEditorBlobSheet"]; [editSheet setMinSize:NSMakeSize(560, 200)]; - else + } else { + [editSheet setFrameAutosaveName:@"SPFieldEditorTextSheet"]; [editSheet setMinSize:NSMakeSize(340, 150)]; + } [editTextView setEditable:isEditable]; [editImage setEditable:isEditable]; -- cgit v1.2.3