diff options
author | bamse16 <marius@marius.me.uk> | 2009-03-23 18:48:15 +0000 |
---|---|---|
committer | bamse16 <marius@marius.me.uk> | 2009-03-23 18:48:15 +0000 |
commit | 7a43632673b88630644c8b352f584267d3a7fffc (patch) | |
tree | c7f9a5cd7c5d7e1cc7c6ac7490f7a5e7a85c1200 /Source/TableContent.m | |
parent | 3d58dc8578c5a48e254f3ffa2394ed875c83a60e (diff) | |
download | sequelpro-7a43632673b88630644c8b352f584267d3a7fffc.tar.gz sequelpro-7a43632673b88630644c8b352f584267d3a7fffc.tar.bz2 sequelpro-7a43632673b88630644c8b352f584267d3a7fffc.zip |
Issue 201: Duplicating a row resets values of text/blob fields in the new row
Fixed - If you attempt to duplicate a row in tables where blob/text data is present but hidden and there are no
keys, SP correctly pops up the dialog but then continues execution, and so crashes.
Fixed - If the row being duplicated contains NULL data, exceptions triggered by [NSNull length] are thrown, and SP
stops responding.
Thanks to Rowan for code review
Diffstat (limited to 'Source/TableContent.m')
-rw-r--r-- | Source/TableContent.m | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m index 3502813a..bec112ff 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -675,7 +675,11 @@ [filteredResult insertObject:tempRow atIndex:[tableContentView selectedRow]+1]; //if we don't show blobs, read data for this duplicate column from db - if ( [prefs boolForKey:@"dontShowBlob"] && [[self argumentForRow:[tableContentView selectedRow]] length]>0) { + if ([prefs boolForKey:@"dontShowBlob"]) { + // Abort if there are no indices on this table - argumentForRow will display an error. + if (![[self argumentForRow:[tableContentView selectedRow]] length]){ + return; + } //if we have indexes, use argumentForRow queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT * FROM `%@` WHERE %@", selectedTable, [self argumentForRow:[tableContentView selectedRow]]]]; dbDataRow = [queryResult fetchRowAsDictionary]; @@ -690,9 +694,16 @@ if ( [[row objectForKey:@"Extra"] isEqualToString:@"auto_increment"] ) { [tempRow setObject:[prefs stringForKey:@"nullValue"] forKey:[row objectForKey:@"Field"]]; } else if ( [tableDataInstance columnIsBlobOrText:[row objectForKey:@"Field"]] && [prefs boolForKey:@"dontShowBlob"] && dbDataRow) { - [tempRow setObject:[dbDataRow objectForKey:[row objectForKey:@"Field"]] forKey:[row objectForKey:@"Field"]]; + NSString *nullValue = nil; + //if what we read from DB is NULL (NSNull), we replace it with the string NULL + if([[dbDataRow objectForKey:[row objectForKey:@"Field"]] isKindOfClass:[NSNull class]]) + nullValue = @"NULL"; + else + nullValue = [dbDataRow objectForKey:[row objectForKey:@"Field"]]; + [tempRow setObject:nullValue forKey:[row objectForKey:@"Field"]]; } } + //select row and go in edit mode [tableContentView reloadData]; [tableContentView selectRow:[tableContentView selectedRow]+1 byExtendingSelection:NO]; @@ -1186,7 +1197,6 @@ // Get the field values for ( i = 0 ; i < [columnNames count] ; i++ ) { rowObject = [[filteredResult objectAtIndex:currentlyEditingRow] objectForKey:[columnNames objectAtIndex:i]]; - // Convert the object to a string (here we can add special treatment for date-, number- and data-fields) if ( [[rowObject description] isEqualToString:[prefs stringForKey:@"nullValue"]] || ([rowObject isMemberOfClass:[NSString class]] && [[rowObject description] isEqualToString:@""]) ) { @@ -1867,7 +1877,7 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn // If the table does contain blob or text fields, load the values ready for editing. if ( [self tableContainsBlobOrTextColumns] ) { wherePart = [NSString stringWithString:[self argumentForRow:[tableContentView selectedRow]]]; - if([wherePart length]== 0) + if([wherePart length]==0) return NO; query = [NSString stringWithFormat:@"SELECT * FROM `%@` WHERE %@", selectedTable, wherePart]; tempResult = [mySQLConnection queryString:query]; |