aboutsummaryrefslogtreecommitdiffstats
path: root/TablesList.m
diff options
context:
space:
mode:
authoravenjamin <avenjamin@gmail.com>2008-11-15 15:37:04 +0000
committeravenjamin <avenjamin@gmail.com>2008-11-15 15:37:04 +0000
commit5949920d5515fbbc1fc59f4ff2ee8c68ca7f6e18 (patch)
tree5134c1a2f6c2973a3fbab4290d78b4d620388ac1 /TablesList.m
parent309ffe4a7ebc4d22a88211706102d35538760eae (diff)
downloadsequelpro-5949920d5515fbbc1fc59f4ff2ee8c68ca7f6e18.tar.gz
sequelpro-5949920d5515fbbc1fc59f4ff2ee8c68ca7f6e18.tar.bz2
sequelpro-5949920d5515fbbc1fc59f4ff2ee8c68ca7f6e18.zip
General clean up.... more to come
Diffstat (limited to 'TablesList.m')
-rw-r--r--TablesList.m463
1 files changed, 226 insertions, 237 deletions
diff --git a/TablesList.m b/TablesList.m
index ee958d1d..0cad02c5 100644
--- a/TablesList.m
+++ b/TablesList.m
@@ -31,11 +31,13 @@
@implementation TablesList
-//IBAction methods
-- (IBAction)updateTables:(id)sender
+
+#pragma mark IBAction methods
+
/*
loads all table names in array tables and reload the tableView
*/
+- (IBAction)updateTables:(id)sender
{
CMMCPResult *theResult;
int i;
@@ -59,10 +61,10 @@ loads all table names in array tables and reload the tableView
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
}
-- (IBAction)addTable:(id)sender
/*
adds a new table to the tables-array (no changes in mysql-db)
*/
+- (IBAction)addTable:(id)sender
{
if ( ![tableSourceInstance selectionShouldChangeInTableView:nil] ||
![tableContentInstance selectionShouldChangeInTableView:nil] ||
@@ -76,11 +78,11 @@ adds a new table to the tables-array (no changes in mysql-db)
[tablesListView editColumn:0 row:[tables count]-1 withEvent:nil select:YES];
}
-- (IBAction)removeTable:(id)sender
/*
invoked when user hits the remove button
alert sheet to ask user if he really wants to delete the table
*/
+- (IBAction)removeTable:(id)sender
{
if ( ![tablesListView numberOfSelectedRows] )
return;
@@ -99,10 +101,10 @@ alert sheet to ask user if he really wants to delete the table
}
}
-- (IBAction)copyTable:(id)sender
/*
copies a table, if desired with content
*/
+- (IBAction)copyTable:(id)sender
{
CMMCPResult *queryResult;
NSScanner *scanner = [NSScanner alloc];
@@ -121,12 +123,15 @@ copies a table, if desired with content
return;
[tableWindow endEditingFor:nil];
-//open copyTableSheet
+ //open copyTableSheet
[copyTableNameField setStringValue:[NSString stringWithFormat:@"%@Copy", [tables objectAtIndex:[tablesListView selectedRow]]]];
[copyTableContentSwitch setState:NSOffState];
[NSApp beginSheet:copyTableSheet
- modalForWindow:tableWindow modalDelegate:self
- didEndSelector:nil contextInfo:nil];
+ modalForWindow:tableWindow
+ modalDelegate:self
+ didEndSelector:nil
+ contextInfo:nil];
+
code = [NSApp runModalForWindow:copyTableSheet];
[NSApp endSheet:copyTableSheet];
@@ -139,100 +144,68 @@ copies a table, if desired with content
return;
}
-//get table structure
+ //get table structure
queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE `%@`",
[tables objectAtIndex:[tablesListView selectedRow]]]];
+
if ( ![queryResult numOfRows] ) {
-//error while getting table structure
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"Couldn't get table information.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection getLastErrorMessage]]);
- } else {
-//insert new table name in create syntax and create new table
- [scanner initWithString:[[queryResult fetchRowAsDictionary] objectForKey:@"Create Table"]];
- [scanner scanUpToString:@"(" intoString:nil];
- [scanner scanUpToString:@"" intoString:&scanString];
- [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE `%@` %@", [copyTableNameField stringValue], scanString]];
- if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
-//error while creating new table
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"Couldn't create table.\nMySQL said: %@", @"message of panel when table cannot be created"), [mySQLConnection getLastErrorMessage]]);
- } else {
- if ( [copyTableContentSwitch state] == NSOnState ) {
-//copy table content
-/*
- queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT * FROM `%@`",
- [tables objectAtIndex:[tablesListView selectedRow]]]];
- fieldNames = [queryResult fetchFieldNames];
- rowCount = [queryResult numOfRows];
- for ( i = 0 ; i < rowCount ; i++ ) {
- [queryResult dataSeek:i];
- theRow = [queryResult fetchRowAsArray];
- fieldValues = [NSMutableArray array];
- for ( j = 0 ; j < [theRow count] ; j++ ) {
- if ( [[theRow objectAtIndex:j] isKindOfClass:[NSData class]] ) {
-// [rowValue setString:[[NSString alloc] initWithData:[theRow objectAtIndex:j]
-// encoding:[mySQLConnection encoding]]];
- [rowValue setString:[mySQLConnection prepareBinaryData:[theRow objectAtIndex:j]]];
- } else {
- [rowValue setString:[mySQLConnection prepareString:[[theRow objectAtIndex:j] description]]];
- }
-*/
-/*
- //escape special characters
- for ( u = 0 ; u < [rowValue length] ; u++ ) {
- if ( [rowValue characterAtIndex:u] == '\\' ) {
- [rowValue insertString:@"\\" atIndex:u];
- u++;
- } else if ( [rowValue characterAtIndex:u] == '"' ) {
- [rowValue insertString:@"\\" atIndex:u];
- u++;
- }
- }
-*/
-/*
- if ( [[theRow objectAtIndex:j] isKindOfClass:[NSNull class]] ) {
- [fieldValues addObject:@"NULL"];
- } else {
-// [fieldValues addObject:[NSString stringWithFormat:@"\"%@\"", [mySQLConnection prepareString:rowValue]]];
-// [fieldValues addObject:[NSString stringWithFormat:@"\"%@\"", rowValue]];
-// [fieldValues addObject:[NSString stringWithFormat:@"'%@'", [mySQLConnection prepareString:rowValue]]];
- [fieldValues addObject:[NSString stringWithFormat:@"'%@'", rowValue]];
-
- }
- }
- [mySQLConnection queryString:[NSString stringWithFormat:@"INSERT INTO `%@` (`%@`) VALUES (%@)",
- [copyTableNameField stringValue], [fieldNames componentsJoinedByString:@"`,`"],
- [fieldValues componentsJoinedByString:@","]]];
- if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
- errors = YES;
- }
- }
- if ( errors )
- NSBeginAlertSheet(@"Warning", @"OK", nil, nil, tableWindow, self, nil, nil, nil,
- @"There have been errors while copying table content. Please control the new table.");
-*/
- [mySQLConnection queryString:[NSString stringWithFormat:@"INSERT INTO `%@` SELECT * FROM `%@`",
- [copyTableNameField stringValue], [tables objectAtIndex:[tablesListView selectedRow]]]];
- if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
- NSBeginAlertSheet(NSLocalizedString(@"Warning", @"warning"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil,
- NSLocalizedString(@"There have been errors while copying table content. Please control the new table.", @"message of panel when table content cannot be copied"));
- }
- }
- [tables insertObject:[copyTableNameField stringValue] atIndex:[tablesListView selectedRow]+1];
- [tablesListView reloadData];
- [tablesListView selectRow:[tablesListView selectedRow]+1 byExtendingSelection:NO];
- [tablesListView scrollRowToVisible:[tablesListView selectedRow]];
- }
- }
+ //error while getting table structure
+ NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil,
+ [NSString stringWithFormat:NSLocalizedString(@"Couldn't get table information.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection getLastErrorMessage]]);
+
+ } else {
+ //insert new table name in create syntax and create new table
+ [scanner initWithString:[[queryResult fetchRowAsDictionary] objectForKey:@"Create Table"]];
+ [scanner scanUpToString:@"(" intoString:nil];
+ [scanner scanUpToString:@"" intoString:&scanString];
+ [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE `%@` %@", [copyTableNameField stringValue], scanString]];
+
+ if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
+ //error while creating new table
+ NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil,
+ [NSString stringWithFormat:NSLocalizedString(@"Couldn't create table.\nMySQL said: %@", @"message of panel when table cannot be created"), [mySQLConnection getLastErrorMessage]]);
+ } else {
+
+ if ( [copyTableContentSwitch state] == NSOnState ) {
+ //copy table content
+ [mySQLConnection queryString:[NSString stringWithFormat:
+ @"INSERT INTO `%@` SELECT * FROM `%@`",
+ [copyTableNameField stringValue],
+ [tables objectAtIndex:[tablesListView selectedRow]]
+ ]];
+
+ if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
+ NSBeginAlertSheet(
+ NSLocalizedString(@"Warning", @"warning"),
+ NSLocalizedString(@"OK", @"OK button"),
+ nil,
+ nil,
+ tableWindow,
+ self,
+ nil,
+ nil,
+ nil,
+ NSLocalizedString(@"There have been errors while copying table content. Please control the new table.", @"message of panel when table content cannot be copied")
+ );
+ }
+ }
+
+ [tables insertObject:[copyTableNameField stringValue] atIndex:[tablesListView selectedRow]+1];
+ [tablesListView reloadData];
+ [tablesListView selectRow:[tablesListView selectedRow]+1 byExtendingSelection:NO];
+ [tablesListView scrollRowToVisible:[tablesListView selectedRow]];
+ }
+ }
}
-//alert sheet methods
-- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
+#pragma mark Alert sheet methods
+
/*
method for alert sheets
invoked when user wants to delete a table
*/
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo
{
if ( [contextInfo isEqualToString:@"addRow"] ) {
alertSheetOpened = NO;
@@ -244,24 +217,25 @@ invoked when user wants to delete a table
}
}
-//copyTableSheet methods
-- (IBAction)closeCopyTableSheet:(id)sender
/*
closes copyTableSheet and stops modal session
*/
+- (IBAction)closeCopyTableSheet:(id)sender
{
[NSApp stopModalWithCode:[sender tag]];
}
-//additional methods
-- (void)removeTable;
+#pragma mark Additional methods
+
/*
removes selected table(s) from mysql-db and tableView
*/
+- (void)removeTable;
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
NSString *errorText;
BOOL error = FALSE;
+
// get last index
unsigned currentIndex = [indexes lastIndex];
while (currentIndex != NSNotFound)
@@ -269,21 +243,24 @@ removes selected table(s) from mysql-db and tableView
[mySQLConnection queryString:[NSString stringWithFormat:@"DROP TABLE `%@`", [tables objectAtIndex:currentIndex]]];
if ( [[mySQLConnection getLastErrorMessage] isEqualTo:@""] ) {
- //dropped table with success
+ //dropped table with success
[tables removeObjectAtIndex:currentIndex];
} else {
- //couldn't drop table
+ //couldn't drop table
error = TRUE;
errorText = [mySQLConnection getLastErrorMessage];
}
+
// get next index (beginning from the end)
currentIndex = [indexes indexLessThanIndex:currentIndex];
}
+
[tablesListView deselectAll:self];
-// [tableSourceInstance loadTable:nil];
-// [tableContentInstance loadTable:nil];
-// [tableStatusInstance loadTable:nil];
+ //[tableSourceInstance loadTable:nil];
+ //[tableContentInstance loadTable:nil];
+ //[tableStatusInstance loadTable:nil];
[tablesListView reloadData];
+
// set window title
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
[tableDocumentInstance host], [tableDocumentInstance database]]];
@@ -292,19 +269,20 @@ removes selected table(s) from mysql-db and tableView
[NSString stringWithFormat:NSLocalizedString(@"Couldn't remove table.\nMySQL said: %@", @"message of panel when table cannot be removed"), errorText]);
}
-- (void)setConnection:(CMMCPConnection *)theConnection
/*
sets the connection (received from TableDocument) and makes things that have to be done only once
*/
+- (void)setConnection:(CMMCPConnection *)theConnection
{
mySQLConnection = theConnection;
-// prefs = [[NSUserDefaults standardUserDefaults] retain];
+ //prefs = [[NSUserDefaults standardUserDefaults] retain];
-//set smallSystemFonts
-// [[[tablesListView tableColumnWithIdentifier:@"tables"] dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
-// [copyTableNameField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
-// if ( [prefs boolForKey:@"useMonospacedFonts"] ) {
+ //set smallSystemFonts
+ //[[[tablesListView tableColumnWithIdentifier:@"tables"] dataCell] setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ //[copyTableNameField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ //if ( [prefs boolForKey:@"useMonospacedFonts"] ) {
+
if ( [[NSUserDefaults standardUserDefaults] boolForKey:@"useMonospacedFonts"] ) {
[[[tablesListView tableColumnWithIdentifier:@"tables"] dataCell]
setFont:[NSFont fontWithName:@"Monaco" size:[NSFont smallSystemFontSize]]];
@@ -313,21 +291,22 @@ sets the connection (received from TableDocument) and makes things that have to
[self updateTables:self];
}
-- (void)doPerformQueryService:(NSString *)query
/*
selects customQuery tab and passes query to customQueryInstance
*/
+- (void)doPerformQueryService:(NSString *)query
{
[tabView selectTabViewItemAtIndex:2];
[customQueryInstance doPerformQueryService:query];
}
-//getter methods
-- (NSString *)table
+#pragma mark Getter methods
+
/*
returns the currently selected table or nil if no table or mulitple tables are selected
*/
+- (NSString *)table
{
if ( [tablesListView numberOfSelectedRows] == 1 ) {
return [tables objectAtIndex:[tablesListView selectedRow]];
@@ -338,32 +317,32 @@ returns the currently selected table or nil if no table or mulitple tables are s
}
}
-- (BOOL)structureLoaded
/*
returns YES if table source has already been loaded
*/
+- (BOOL)structureLoaded
{
return structureLoaded;
}
-- (BOOL)contentLoaded
/*
returns YES if table content has already been loaded
*/
+- (BOOL)contentLoaded
{
return contentLoaded;
}
-- (BOOL)statusLoaded
/*
returns YES if table status has already been loaded
*/
+- (BOOL)statusLoaded
{
return statusLoaded;
}
+#pragma mark Datasource methods
-//tableView datasource methods
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [tables count];
@@ -385,143 +364,149 @@ returns YES if table status has already been loaded
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
- if ( [[tables objectAtIndex:rowIndex] isEqualToString:@""] ) {
- //new table
- if ( [anObject isEqualToString:@""] ) {
- //table has no name
- alertSheetOpened = YES;
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self,
- @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", NSLocalizedString(@"Table must have a name.", @"message of panel when no name is given for table"));
- [tables removeObjectAtIndex:rowIndex];
- [tablesListView reloadData];
- } else {
+
+ if ( [[tables objectAtIndex:rowIndex] isEqualToString:@""] ) {
+ //new table
+ if ( [anObject isEqualToString:@""] ) {
+ //table has no name
+ alertSheetOpened = YES;
+ NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self,
+ @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", NSLocalizedString(@"Table must have a name.", @"message of panel when no name is given for table"));
+ [tables removeObjectAtIndex:rowIndex];
+ [tablesListView reloadData];
+ } else {
if ( [tableDocumentInstance supportsEncoding] ) {
[mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE `%@` (id int) DEFAULT CHARACTER SET %@", anObject, [tableDocumentInstance encoding]]];
- } else {
+ } else {
[mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE `%@` (id int)", anObject]];
}
+
if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
- //added table with success
- // NSLog(@"added new table with success");
- [tables replaceObjectAtIndex:rowIndex withObject:anObject];
- if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
- [tableSourceInstance loadTable:anObject];
- structureLoaded = YES;
- contentLoaded = NO;
- statusLoaded = NO;
- } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) {
- [tableSourceInstance loadTable:anObject];
- [tableContentInstance loadTable:anObject];
- structureLoaded = YES;
- contentLoaded = YES;
- statusLoaded = NO;
- } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) {
- [tableStatusInstance loadTable:anObject];
- statusLoaded = YES;
- structureLoaded = NO;
- contentLoaded = NO;
- } else {
- statusLoaded = NO;
- structureLoaded = NO;
- contentLoaded = NO;
- }
+ //added table with success
+ [tables replaceObjectAtIndex:rowIndex withObject:anObject];
+
+ if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
+ [tableSourceInstance loadTable:anObject];
+ structureLoaded = YES;
+ contentLoaded = NO;
+ statusLoaded = NO;
+ } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) {
+ [tableSourceInstance loadTable:anObject];
+ [tableContentInstance loadTable:anObject];
+ structureLoaded = YES;
+ contentLoaded = YES;
+ statusLoaded = NO;
+ } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) {
+ [tableStatusInstance loadTable:anObject];
+ statusLoaded = YES;
+ structureLoaded = NO;
+ contentLoaded = NO;
+ } else {
+ statusLoaded = NO;
+ structureLoaded = NO;
+ contentLoaded = NO;
+ }
+
// set window title
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
- [tableDocumentInstance host], [tableDocumentInstance database], anObject]];
- } else {
- //error while adding new table
- // NSLog(@"couldn't add new table");
- alertSheetOpened = YES;
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self,
- @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow",
- [NSString stringWithFormat:NSLocalizedString(@"Couldn't add table %@.\nMySQL said: %@", @"message of panel when table cannot be created with the given name"),
- anObject, [mySQLConnection getLastErrorMessage]]);
- [tables removeObjectAtIndex:rowIndex];
- [tablesListView reloadData];
- }
- }
- } else {
- //table modification
- if ( [[tables objectAtIndex:rowIndex] isEqualToString:anObject] ) {
- //no changes in table name
- // NSLog(@"no changes in table name");
- } else if ( [anObject isEqualToString:@""] ) {
- //table has no name
- // NSLog(@"name is nil");
- alertSheetOpened = YES;
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self,
- @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", NSLocalizedString(@"Table must have a name.", @"message of panel when no name is given for table"));
+ [tableDocumentInstance host], [tableDocumentInstance database], anObject]];
+ } else {
+
+ //error while adding new table
+ alertSheetOpened = YES;
+ NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self,
+ @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow",
+ [NSString stringWithFormat:NSLocalizedString(@"Couldn't add table %@.\nMySQL said: %@", @"message of panel when table cannot be created with the given name"),
+ anObject, [mySQLConnection getLastErrorMessage]]);
+ [tables removeObjectAtIndex:rowIndex];
+ [tablesListView reloadData];
+ }
+ }
} else {
- [mySQLConnection queryString:[NSString stringWithFormat:@"RENAME TABLE `%@` TO `%@`", [tables objectAtIndex:rowIndex], anObject]];
- if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
- // NSLog(@"renamed table with success");
- //renamed with success
- [tables replaceObjectAtIndex:rowIndex withObject:anObject];
- if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
- [tableSourceInstance loadTable:anObject];
- structureLoaded = YES;
- contentLoaded = NO;
- statusLoaded = NO;
- } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) {
- [tableSourceInstance loadTable:anObject];
- [tableContentInstance loadTable:anObject];
- structureLoaded = YES;
- contentLoaded = YES;
- statusLoaded = NO;
- } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) {
- [tableStatusInstance loadTable:anObject];
- structureLoaded = NO;
- contentLoaded = NO;
- statusLoaded = YES;
+
+ //table modification
+ if ( [[tables objectAtIndex:rowIndex] isEqualToString:anObject] ) {
+ //no changes in table name
+// NSLog(@"no changes in table name");
+ } else if ( [anObject isEqualToString:@""] ) {
+ //table has no name
+// NSLog(@"name is nil");
+ alertSheetOpened = YES;
+ NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self,
+ @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow", NSLocalizedString(@"Table must have a name.", @"message of panel when no name is given for table"));
} else {
- statusLoaded = NO;
- structureLoaded = NO;
- contentLoaded = NO;
- }
+ [mySQLConnection queryString:[NSString stringWithFormat:@"RENAME TABLE `%@` TO `%@`", [tables objectAtIndex:rowIndex], anObject]];
+ if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
+// NSLog(@"renamed table with success");
+ //renamed with success
+ [tables replaceObjectAtIndex:rowIndex withObject:anObject];
+
+ if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
+ [tableSourceInstance loadTable:anObject];
+ structureLoaded = YES;
+ contentLoaded = NO;
+ statusLoaded = NO;
+ } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) {
+ [tableSourceInstance loadTable:anObject];
+ [tableContentInstance loadTable:anObject];
+ structureLoaded = YES;
+ contentLoaded = YES;
+ statusLoaded = NO;
+ } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) {
+ [tableStatusInstance loadTable:anObject];
+ structureLoaded = NO;
+ contentLoaded = NO;
+ statusLoaded = YES;
+ } else {
+ statusLoaded = NO;
+ structureLoaded = NO;
+ contentLoaded = NO;
+ }
+
// set window title
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
- [tableDocumentInstance host], [tableDocumentInstance database], anObject]];
- } else {
- //error while renaming
- // NSLog(@"couldn't rename table");
- alertSheetOpened = YES;
- NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self,
- @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow",
- [NSString stringWithFormat:NSLocalizedString(@"Couldn't rename table.\nMySQL said: %@", @"message of panel when table cannot be renamed"),
- [mySQLConnection getLastErrorMessage]]);
- }
+ [tableDocumentInstance host], [tableDocumentInstance database], anObject]];
+ } else {
+ //error while renaming
+// NSLog(@"couldn't rename table");
+ alertSheetOpened = YES;
+ NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self,
+ @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addRow",
+ [NSString stringWithFormat:NSLocalizedString(@"Couldn't rename table.\nMySQL said: %@", @"message of panel when table cannot be renamed"),
+ [mySQLConnection getLastErrorMessage]]);
+ }
+ }
}
- }
}
-//tableView delegate methods
-- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command
+#pragma mark TableView delegate methods
+
/*
traps enter and esc and edit/cancel without entering next row
*/
+- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command
{
- if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) //trap enter
- {
+ if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) {
//save current line
[[control window] makeFirstResponder:control];
return TRUE;
- }
- else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] ||
- [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) //trap esc
- {
+
+ } else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] ||
+ [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) {
+
//abort editing
[control abortEditing];
+
if ( [[tables objectAtIndex:[tablesListView selectedRow]] isEqualToString:@""] ) {
//user added new table and then pressed escape
[tables removeObjectAtIndex:[tablesListView selectedRow]];
[tablesListView reloadData];
}
+
return TRUE;
- }
- else
- {
- return FALSE;
- }
+ } else{
+ return FALSE;
+ }
}
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
@@ -538,13 +523,13 @@ traps enter and esc and edit/cancel without entering next row
[cell endEditing:[tablesListView currentEditor]];
}
*/
-//end editing (otherwise problems when user hits reload button)
+ //end editing (otherwise problems when user hits reload button)
[tableWindow endEditingFor:nil];
if ( alertSheetOpened ) {
return NO;
}
-//we have to be sure that TableSource and TableContent have finished editing
+ //we have to be sure that TableSource and TableContent have finished editing
// if ( ![tableSourceInstance addRowToDB] || ![tableContentInstance addRowToDB] ) {
if ( ![tableSourceInstance selectionShouldChangeInTableView:nil] ||
![tableContentInstance selectionShouldChangeInTableView:nil] ) {
@@ -554,10 +539,10 @@ traps enter and esc and edit/cancel without entering next row
}
}
-- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
/*
loads a table in content or source view (if tab selected)
*/
+- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
if ( [tablesListView numberOfSelectedRows] == 1 ) {
if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
@@ -581,6 +566,7 @@ loads a table in content or source view (if tab selected)
contentLoaded = NO;
statusLoaded = NO;
}
+
// set window title
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
[tableDocumentInstance host], [tableDocumentInstance database], [tables objectAtIndex:[tablesListView selectedRow]]]];
@@ -592,43 +578,46 @@ loads a table in content or source view (if tab selected)
structureLoaded = NO;
contentLoaded = NO;
statusLoaded = NO;
+
// set window title
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@@%@/%@", [tableDocumentInstance mySQLVersion], [tableDocumentInstance user],
[tableDocumentInstance host], [tableDocumentInstance database]]];
}
}
-//tabView delegate methods
-- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
+#pragma mark TabView delegate methods
+
/*
loads structure or source if tab selected the first time
*/
+- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
- if ( [tablesListView numberOfSelectedRows] == 1 )
- {
- if ( ([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0) && !structureLoaded )
- {
+ if ( [tablesListView numberOfSelectedRows] == 1 ) {
+
+ if ( ([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0) && !structureLoaded ) {
+
[tableSourceInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
structureLoaded = YES;
}
- if ( ([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1) && !contentLoaded )
- {
+
+ if ( ([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1) && !contentLoaded ) {
+
if ( !structureLoaded ) {
[tableSourceInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
structureLoaded = YES;
}
+
[tableContentInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
contentLoaded = YES;
}
- if ( ([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3) && !statusLoaded )
- {
+
+ if ( ([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3) && !statusLoaded ) {
[tableStatusInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
statusLoaded = YES;
}
}
/*
- if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 )
- {
+ if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) {
[tableDumpInstance reloadTables:self];
}
*/
65'>1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749