aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPCustomQuery.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-08-26 18:53:33 +0000
committerBibiko <bibiko@eva.mpg.de>2010-08-26 18:53:33 +0000
commit85290111df9004529db698745acc98a21a8d1996 (patch)
treea07537e62e6fd64e31c60ec652e37e28ed0e89d1 /Source/SPCustomQuery.m
parent09b1063c73206cffb1819530498ef209e393a1a3 (diff)
downloadsequelpro-85290111df9004529db698745acc98a21a8d1996.tar.gz
sequelpro-85290111df9004529db698745acc98a21a8d1996.tar.bz2
sequelpro-85290111df9004529db698745acc98a21a8d1996.zip
• removed onMainThread for [Content/CustomTable makeFirstResponder] to avoid the trampoline exceptions
• unified error message while cell editing • in Custom Query table cell editing errors are displayed as tooltips and added these message if edit event comes from the keyboard • fixed: check edit status in Content Tables only for views to avoid unnecessary queries • used [SPCustomQuery fieldEditStatusForRow:andColumn:] consequently to simplify code
Diffstat (limited to 'Source/SPCustomQuery.m')
-rw-r--r--Source/SPCustomQuery.m137
1 files changed, 84 insertions, 53 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index adb806ad..f8729074 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -1808,9 +1808,6 @@
{
if (aTableView == customQueryView) {
- // Field editing
- if (fieldIDQueryString == nil) return;
-
NSDictionary *columnDefinition;
// Retrieve the column defintion
@@ -1837,9 +1834,8 @@
fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]];
// Check if the IDstring identifies the current field bijectively
- NSInteger numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@.%@ %@", [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], fieldIDQueryString]] fetchRowAsArray] objectAtIndex:0] integerValue];
+ NSInteger numberOfPossibleUpdateRows = [self fieldEditStatusForRow:rowIndex andColumn:[aTableColumn identifier]];
if(numberOfPossibleUpdateRows == 1) {
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
NSString *newObject = nil;
if ( [anObject isKindOfClass:[NSCalendarDate class]] ) {
@@ -1865,10 +1861,8 @@
[mySQLConnection queryString:
[NSString stringWithFormat:@"UPDATE %@.%@ SET %@.%@.%@ = %@ %@ LIMIT 1",
- [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString],
- [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], [columnName backtickQuotedString], newObject, fieldIDQueryString]];
-
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
+ [[columnDefinition objectForKey:@"db"] backtickQuotedString], [[columnDefinition objectForKey:@"org_table"] backtickQuotedString],
+ [[columnDefinition objectForKey:@"db"] backtickQuotedString], [[columnDefinition objectForKey:@"org_table"] backtickQuotedString], [columnName backtickQuotedString], newObject, fieldIDQueryString]];
// Check for errors while UPDATE
if ([mySQLConnection queryErrored]) {
@@ -1878,7 +1872,6 @@
return;
}
-
// This shouldn't happen – for safety reasons
if ( ![mySQLConnection affectedRows] ) {
if ( [prefs boolForKey:SPShowNoAffectedRowsError] ) {
@@ -1894,17 +1887,15 @@
if ([prefs boolForKey:SPReloadAfterEditingRow]) {
reloadingExistingResult = YES;
[self storeCurrentResultViewForRestoration];
-
[self performQueries:[NSArray arrayWithObject:lastExecutedQuery] withCallback:NULL];
-
} else {
// otherwise, just update the data in the data storage
SPDataStorageReplaceObjectAtRowAndColumn(resultData, rowIndex, [[aTableColumn identifier] intValue], anObject);
}
} else {
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"Updating field content failed. Couldn't identify field origin unambiguously (%ld match%@). It's very likely that while editing this field the table `%@` was changed by an other user.", @"message of panel when error while updating field to db after enabling it"),
- (long)numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?@"es":@"", tableForColumn]);
+ [NSString stringWithFormat:NSLocalizedString(@"Updating field content failed. Couldn't identify field origin unambiguously (%ld match%@). It's very likely that while editing this field of table `%@` was changed.", @"message of panel when error while updating field to db after enabling it"),
+ (long)numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?@"es":@"", [columnDefinition objectForKey:@"org_table"]]);
}
@@ -2189,12 +2180,9 @@
// Check if the field can identified bijectively
if ( aTableView == customQueryView ) {
-
NSDictionary *columnDefinition;
- BOOL noTableName = NO;
- BOOL isFieldEditable;
- BOOL isBlob;
- NSInteger numberOfPossibleUpdateRows = -1;
+ BOOL isFieldEditable = NO;
+ BOOL isBlob = NO;
// Retrieve the column defintion
for(id c in cqColumnDefinition) {
@@ -2211,39 +2199,52 @@
else
isBlob = NO;
- // Resolve the original table name for current column if AS was used
- NSString *tableForColumn = [columnDefinition objectForKey:@"org_table"];
-
- // Get the database name which the field belongs to
- NSString *dbForColumn = [columnDefinition objectForKey:@"db"];
-
- // No table/database 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 or if column database is unset
- if(!tableForColumn || ![tableForColumn length] || ![dbForColumn length])
- noTableName = YES;
-
- if(!noTableName) {
- // if table and database name are given check if field can be identified unambiguously
- fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]];
-
- // Actual check whether field can be identified bijectively
- numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@.%@ %@", [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], fieldIDQueryString]] fetchRowAsArray] objectAtIndex:0] integerValue];
+ // Check if the clicked table field is editable
+ NSInteger numberOfPossibleUpdateRows = [self fieldEditStatusForRow:rowIndex andColumn:[aTableColumn identifier]];
+ isFieldEditable = (numberOfPossibleUpdateRows == 1) ? YES : NO;
+ NSPoint pos = [NSEvent mouseLocation];
+ pos.y -= 20;
+ switch(numberOfPossibleUpdateRows) {
+ case -1:
+ isFieldEditable = NO;
+ fieldIDQueryString = nil;
+ [SPTooltip showWithObject:kCellEditorErrorNoMultiTabDb
+ atLocation:pos
+ ofType:@"text"];
+ isFieldEditable = NO;
+ // Allow to display blobs even it's not editable
+ if(!isBlob && [multipleLineEditingButton state] == NSOffState)
+ return NO;
+ break;
- isFieldEditable = (numberOfPossibleUpdateRows == 1) ? YES : NO;
+ case 0:
+ [SPTooltip showWithObject:[NSString stringWithFormat:kCellEditorErrorNoMatch, [columnDefinition objectForKey:@"org_table"]]
+ atLocation:pos
+ ofType:@"text"];
+ isFieldEditable = NO;
+ // Allow to display blobs even it's not editable
+ if(!isBlob && [multipleLineEditingButton state] == NSOffState)
+ return NO;
+ break;
- if(!isFieldEditable)
- if(numberOfPossibleUpdateRows == 0)
- [errorText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Field is not editable. No matching record found. Try to add the primary key field or more fields in your SELECT statement for table '%@' to identify field origin unambiguously.", @"Custom Query result editing error - could not identify original row"), tableForColumn]];
- else
- [errorText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Field is not editable. Couldn't identify field origin unambiguously (%ld match%@).", @"Custom Query result editing error - could not match row being edited uniquely"), (long)numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?NSLocalizedString(@"es", @"Plural suffix for row count, eg 4 match*es*"):@""]];
+ case 1:
+ isFieldEditable = YES;
+ if(!isBlob && [multipleLineEditingButton state] == NSOffState)
+ return YES;
+ break;
- } else {
- // no table/databse name are given
+ default:
+ [SPTooltip showWithObject:[NSString stringWithFormat:kCellEditorErrorTooManyMatches, (long)numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?NSLocalizedString(@"es", @"Plural suffix for row count, eg 4 match*es*"):@""]
+ atLocation:pos
+ ofType:@"text"];
isFieldEditable = NO;
- fieldIDQueryString = nil;
- [errorText setStringValue:NSLocalizedString(@"Field is not editable. Field has no or multiple table or database origin(s).",@"field is not editable due to no table/database")];
+ // Allow to display blobs even it's not editable
+ if(!isBlob && [multipleLineEditingButton state] == NSOffState)
+ return NO;
+
}
+
if ([multipleLineEditingButton state] == NSOnState || isBlob) {
SPFieldEditorController *fieldEditor = [[SPFieldEditorController alloc] init];
@@ -3414,6 +3415,10 @@
prefs = [NSUserDefaults standardUserDefaults];
+ kCellEditorErrorNoMatch = NSLocalizedString(@"Field is not editable. No matching record found. Reload data, check encoding, or try to add a primary key field or more fields in your SELECT statement for table '%@' to identify field origin unambiguously.", @"Custom Query result editing error - could not identify original row");
+ kCellEditorErrorNoMultiTabDb = NSLocalizedString(@"Field is not editable. Field has no or multiple table or database origin(s).",@"field is not editable due to no table/database");
+ kCellEditorErrorTooManyMatches = NSLocalizedString(@"Field is not editable. Couldn't identify field origin unambiguously (%ld match%@).", @"Custom Query result editing error - could not match row being edited uniquely");
+
}
return self;
@@ -3460,17 +3465,11 @@
{
NSUInteger row, column;
+ NSDictionary *columnDefinition = nil;
row = [customQueryView editedRow];
column = [customQueryView editedColumn];
- if([self fieldEditStatusForRow:row andColumn:[NSArrayObjectAtIndex([customQueryView tableColumns], column) identifier]] != 1)
- return NO;
-
- NSString *fieldType;
-
- NSDictionary *columnDefinition = nil;
-
// Retrieve the column defintion
for(id c in cqColumnDefinition) {
if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:[NSNumber numberWithInteger:column]]) {
@@ -3481,6 +3480,35 @@
if(!columnDefinition) return NO;
+ NSInteger numberOfPossibleUpdateRows = [self fieldEditStatusForRow:row andColumn:[NSArrayObjectAtIndex([customQueryView tableColumns], column) identifier]];
+ NSPoint pos = [[tableDocumentInstance parentWindow] convertBaseToScreen:[customQueryView convertPoint:[customQueryView frameOfCellAtColumn:column row:row].origin toView:nil]];
+ pos.y -= 20;
+ switch(numberOfPossibleUpdateRows) {
+ case -1:
+ [SPTooltip showWithObject:kCellEditorErrorNoMultiTabDb
+ atLocation:pos
+ ofType:@"text"];
+ return NO;
+ break;
+ case 0:
+ [SPTooltip showWithObject:[NSString stringWithFormat:kCellEditorErrorNoMatch, [columnDefinition objectForKey:@"org_table"]]
+ atLocation:pos
+ ofType:@"text"];
+ return NO;
+ break;
+
+ case 1:
+ break;
+
+ default:
+ [SPTooltip showWithObject:[NSString stringWithFormat:kCellEditorErrorTooManyMatches, (long)numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?NSLocalizedString(@"es", @"Plural suffix for row count, eg 4 match*es*"):@""]
+ atLocation:pos
+ ofType:@"text"];
+ return NO;
+ }
+
+ NSString *fieldType;
+
BOOL isBlob = NO;
// Check if current field is a blob
@@ -3506,6 +3534,9 @@
}
+ // Set editing color to black for NULL values while editing
+ [fieldEditor setTextColor:[NSColor blackColor]];
+
return YES;
}