From 7b9d0404e46078c3b9e215bb7db2a8d272fc551e Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 11 Jan 2011 00:31:34 +0000 Subject: - Fix default population for NOT NULL numeric fields when adding rows - When saving rows, convert empty strings for NOT NULL numeric fields to 0 rather than NULL to prevent errors --- Source/SPTableContent.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Source/SPTableContent.m') diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 8e2bde89..3db3917b 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -1604,6 +1604,12 @@ column = NSArrayObjectAtIndex(dataColumns, i); if ([column objectForKey:@"default"] == nil || [column objectForKey:@"default"] == [NSNull null]) { [newRow addObject:[NSNull null]]; + } else if ([[column objectForKey:@"default"] isEqualToString:@""] + && ![[column objectForKey:@"null"] boolValue] + && ([[column objectForKey:@"typegrouping"] isEqualToString:@"float"] + || [[column objectForKey:@"typegrouping"] isEqualToString:@"integer"])) + { + [newRow addObject:@"0"]; } else { [newRow addObject:[column objectForKey:@"default"]]; } @@ -2394,9 +2400,11 @@ NSMutableArray *rowFieldsToSave = [[NSMutableArray alloc] initWithCapacity:[dataColumns count]]; NSMutableArray *rowValuesToSave = [[NSMutableArray alloc] initWithCapacity:[dataColumns count]]; NSInteger i; + NSDictionary *fieldDefinition; id rowObject; for (i = 0; i < [dataColumns count]; i++) { rowObject = [tableValues cellDataAtRow:currentlyEditingRow column:i]; + fieldDefinition = NSArrayObjectAtIndex(dataColumns, i); // Skip "not loaded" cells entirely - these only occur when editing tables when the // preference setting is enabled, and don't need to be saved back to the table. @@ -2408,13 +2416,13 @@ // Prepare to derive the value to save NSString *fieldValue; - NSString *fieldTypeGroup = [NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"typegrouping"]; + NSString *fieldTypeGroup = [fieldDefinition objectForKey:@"typegrouping"]; // Use NULL when the user has entered the nullValue string defined in the preferences, // or when a numeric field is empty. if ([rowObject isNSNull] || (([fieldTypeGroup isEqualToString:@"float"] || [fieldTypeGroup isEqualToString:@"integer"]) - && [[rowObject description] isEqualToString:@""])) + && [[rowObject description] isEqualToString:@""] && [[fieldDefinition objectForKey:@"null"] boolValue])) { fieldValue = @"NULL"; @@ -2449,7 +2457,7 @@ } // Store the key and value in the ordered arrays for saving. - [rowFieldsToSave addObject:[NSArrayObjectAtIndex(dataColumns, i) objectForKey:@"name"]]; + [rowFieldsToSave addObject:[fieldDefinition objectForKey:@"name"]]; [rowValuesToSave addObject:fieldValue]; } -- cgit v1.2.3 From 7d2238af04e18999b4dc83a92d82ac1944c0916d Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 11 Jan 2011 19:24:52 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20several=20issues=20for=20validation?= =?UTF-8?q?=20and=20other=20stuff=20while=20editing=20of=20MySQL=20data=20?= =?UTF-8?q?tables=20if=20user=20re-ordered=20columns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTableContent.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'Source/SPTableContent.m') diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 3db3917b..6213549d 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -2792,7 +2792,7 @@ * -2 for other errors * and the used WHERE clause to identify */ -- (NSArray*)fieldEditStatusForRow:(NSInteger)rowIndex andColumn:(NSInteger)columnIndex +- (NSArray*)fieldEditStatusForRow:(NSInteger)rowIndex andColumn:(NSNumber *)columnIndex { NSDictionary *columnDefinition = nil; @@ -2927,10 +2927,12 @@ NSInteger row = -1; NSInteger column = -1; + NSInteger editedColumn = -1; if(contextInfo) { row = [[contextInfo objectForKey:@"row"] integerValue]; column = [[contextInfo objectForKey:@"column"] integerValue]; + editedColumn = [[contextInfo objectForKey:@"editedColumn"] integerValue]; } if (data && contextInfo) { @@ -2966,8 +2968,8 @@ [[tableDocumentInstance parentWindow] makeFirstResponder:tableContentView]; - if(row > -1 && column > -1) - [tableContentView editColumn:column row:row withEvent:nil select:YES]; + if(row > -1 && editedColumn > -1) + [tableContentView editColumn:editedColumn row:row withEvent:nil select:YES]; } #pragma mark - @@ -4058,6 +4060,12 @@ if ([cellValue isNSNull]) cellValue = [NSString stringWithString:[prefs objectForKey:SPNullValue]]; + NSInteger editedColumn = 0; + for(NSTableColumn* col in [tableContentView tableColumns]) { + if([[col identifier] isEqualToNumber:[aTableColumn identifier]]) break; + editedColumn++; + } + [fieldEditor editWithObject:cellValue fieldName:[[aTableColumn headerCell] stringValue] usingEncoding:[mySQLConnection stringEncoding] @@ -4068,6 +4076,7 @@ contextInfo:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger:rowIndex], @"row", [aTableColumn identifier], @"column", + [NSNumber numberWithInteger:editedColumn], @"editedColumn", [NSNumber numberWithBool:isFieldEditable], @"isFieldEditable", nil]]; -- cgit v1.2.3 From eec292b2a6a348f061630bebc5bfd7d39aa57ea0 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Fri, 14 Jan 2011 01:04:22 +0000 Subject: - Fix problems correctly resetting state when a query affects no rows on creating new tables; this could be responsible for -release errors in SPDataStorage, as well as out-of-bounds errors in SPDataStorage or SPTableContent. - Fix incorrect reporting of affected rows in MCPKit due to the use of meta/status queries; only track affected rows for framework-usage queries (already largely implemented in previous revisions) --- Source/SPTableContent.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Source/SPTableContent.m') diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 6213549d..064b08f1 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -2498,10 +2498,19 @@ } else { NSBeep(); } - [tableValues replaceRowAtIndex:currentlyEditingRow withRowContents:oldRow]; + + // If creating a new row, remove the row; otherwise revert the row contents + if (isEditingNewRow) { + tableRowsCount--; + [tableValues removeRowAtIndex:currentlyEditingRow]; + [self updateCountText]; + isEditingNewRow = NO; + } else { + [tableValues replaceRowAtIndex:currentlyEditingRow withRowContents:oldRow]; + } isEditingRow = NO; - isEditingNewRow = NO; currentlyEditingRow = -1; + [tableContentView reloadData]; [[SPQueryController sharedQueryController] showErrorInConsole:NSLocalizedString(@"/* WARNING: No rows have been affected */\n", @"warning shown in the console when no rows have been affected after writing to the db") connection:[tableDocumentInstance name]]; return YES; -- cgit v1.2.3 From f1b7ccbcdd139a040adb8caae3366f998b2df75a Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 24 Jan 2011 11:55:00 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20minor=20issue=20for=20filterTable?= =?UTF-8?q?=20approach=20in=20Content=20-=20prepared=20some=20stuff=20for?= =?UTF-8?q?=20table=20state=20history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTableContent.m | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'Source/SPTableContent.m') diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 064b08f1..b136d90a 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -3297,6 +3297,25 @@ [self setFiltersToRestore:nil]; } +- (void) setFilterTableData:(NSData*)arcData +{ + if(!arcData) return; + NSDictionary *filterData = [NSUnarchiver unarchiveObjectWithData:arcData]; + [filterTableData removeAllObjects]; + [filterTableData addEntriesFromDictionary:filterData]; + [filterTableWindow makeKeyAndOrderFront:nil]; + // [filterTableView reloadData]; +} + +- (NSData*) filterTableData +{ + if(![filterTableWindow isVisible]) return nil; + + [filterTableView deselectAll:nil]; + + return [NSArchiver archivedDataWithRootObject:filterTableData]; +} + #pragma mark - #pragma mark Table drawing and editing @@ -3513,8 +3532,9 @@ return c; } else return NSArrayObjectAtIndex([[filterTableData objectForKey:[NSNumber numberWithInteger:rowIndex]] objectForKey:@"filter"], [[aTableColumn identifier] integerValue]-1); - else + else { return NSArrayObjectAtIndex([[filterTableData objectForKey:[aTableColumn identifier]] objectForKey:@"filter"], rowIndex); + } } else if(aTableView == tableContentView) { @@ -4470,6 +4490,8 @@ NSString *re1 = @"^\\s*(<[=>]?|>=?|!?=|≠|≤|≥)\\s*(.*?)\\s*$"; NSString *re2 = @"^\\s*(.*)\\s+(.*?)\\s*$"; NSCharacterSet *whiteSpaceCharSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + NSInteger editedRow = [filterTableView editedRow]; + if(currentValue == filterTableGearLookAllFields) { numberOfRows = 1; @@ -4503,7 +4525,7 @@ } // Take value from currently edited table cell } else if([currentValue isKindOfClass:[NSString class]]){ - if(index == [filterTableView editedColumn] && i == [filterTableView editedRow]) + if(i == editedRow && index == [[NSArrayObjectAtIndex([filterTableView tableColumns], [filterTableView editedColumn]) identifier] integerValue]) filterCell = (NSString*)currentValue; else filterCell = NSArrayObjectAtIndex([filterCellData objectForKey:@"filter"], i); -- cgit v1.2.3