aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableSource.m
diff options
context:
space:
mode:
authoravenjamin <avenjamin@gmail.com>2009-05-20 09:10:05 +0000
committeravenjamin <avenjamin@gmail.com>2009-05-20 09:10:05 +0000
commitf0b3b6ac71d728c880616cc899b03265330fb06f (patch)
tree5f64fdcb57310617c9435ad0043c5e0d3915703d /Source/TableSource.m
parent9d186d35c19ab8eff4e2bc69c929dda2819ab0c5 (diff)
downloadsequelpro-f0b3b6ac71d728c880616cc899b03265330fb06f.tar.gz
sequelpro-f0b3b6ac71d728c880616cc899b03265330fb06f.tar.bz2
sequelpro-f0b3b6ac71d728c880616cc899b03265330fb06f.zip
- Added ability to insert field/column in structure mode.
- Inserts a field after the current selection or at the end if there is no field selected. - Resolves issue #30
Diffstat (limited to 'Source/TableSource.m')
-rw-r--r--Source/TableSource.m17
1 files changed, 12 insertions, 5 deletions
diff --git a/Source/TableSource.m b/Source/TableSource.m
index 7ac9212e..3cc31deb 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -236,16 +236,19 @@ reloads the table (performing a new mysql-query)
// Check whether a save of the current row is required.
if ( ![self saveRowOnDeselect] ) return;
- [tableFields addObject:[NSMutableDictionary
- dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"int", @"", @"0", @"0", @"0", ([prefs boolForKey:@"NewFieldsAllowNulls"]) ? @"YES" : @"NO", @"", [prefs stringForKey:@"NullValue"], @"None", nil]
- forKeys:[NSArray arrayWithObjects:@"Field", @"Type", @"Length", @"unsigned", @"zerofill", @"binary", @"Null", @"Key", @"Default", @"Extra", nil]]];
+ int insertIndex = ([tableSourceView numberOfSelectedRows] == 0 ? [tableSourceView numberOfRows] : [tableSourceView selectedRow] + 1);
+
+ [tableFields insertObject:[NSMutableDictionary
+ dictionaryWithObjects:[NSArray arrayWithObjects:@"", @"int", @"", @"0", @"0", @"0", ([prefs boolForKey:@"NewFieldsAllowNulls"]) ? @"YES" : @"NO", @"", [prefs stringForKey:@"NullValue"], @"None", nil]
+ forKeys:[NSArray arrayWithObjects:@"Field", @"Type", @"Length", @"unsigned", @"zerofill", @"binary", @"Null", @"Key", @"Default", @"Extra", nil]]
+ atIndex:insertIndex];
[tableSourceView reloadData];
- [tableSourceView selectRow:[tableSourceView numberOfRows]-1 byExtendingSelection:NO];
+ [tableSourceView selectRow:insertIndex byExtendingSelection:NO];
isEditingRow = YES;
isEditingNewRow = YES;
currentlyEditingRow = [tableSourceView selectedRow];
- [tableSourceView editColumn:0 row:[tableSourceView numberOfRows]-1 withEvent:nil select:YES];
+ [tableSourceView editColumn:0 row:insertIndex withEvent:nil select:YES];
}
/**
@@ -711,10 +714,14 @@ fetches the result as an array with a dictionary for each row in it
if ( code ) {
if ( [chooseKeyButton indexOfSelectedItem] == 0 ) {
[queryString appendString:@" PRIMARY KEY"];
+ [queryString appendString:[NSString stringWithFormat:@" AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"Field"] backtickQuotedString]]];
} else {
+ [queryString appendString:[NSString stringWithFormat:@" AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"Field"] backtickQuotedString]]];
[queryString appendString:[NSString stringWithFormat:@", ADD %@ (%@)", [chooseKeyButton titleOfSelectedItem], [[theRow objectForKey:@"Field"] backtickQuotedString]]];
}
}
+ } else {
+ [queryString appendString:[NSString stringWithFormat:@" AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"Field"] backtickQuotedString]]];
}
[mySQLConnection queryString:queryString];