aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-05 17:44:48 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-05 17:44:48 +0000
commit7b5f4d96727a505b67b7970e0b4f2ca1de0394a2 (patch)
tree79c322f805286c5cfa1e37c40da9e8e8278b458a
parent67a3148cec8bc7d1c6f52f60c8ce93a4fe0b8ece (diff)
downloadsequelpro-7b5f4d96727a505b67b7970e0b4f2ca1de0394a2.tar.gz
sequelpro-7b5f4d96727a505b67b7970e0b4f2ca1de0394a2.tar.bz2
sequelpro-7b5f4d96727a505b67b7970e0b4f2ca1de0394a2.zip
• reload table list, database pull-down menu according to user's statements in the Custom Query editor if necessary
- if statement begins with: use, create, alter, rename, drop • reload table list, database pull-down menu according to imported statements • sped up "Import MySQL Dump" • fixed some tiny issues of the last commit
-rw-r--r--Source/CMTextView.m5
-rw-r--r--Source/CustomQuery.m50
-rw-r--r--Source/TableDocument.h1
-rw-r--r--Source/TableDocument.m41
-rw-r--r--Source/TableDump.m78
-rw-r--r--Source/TablesList.m10
6 files changed, 135 insertions, 50 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 27df70ed..a6f7cabc 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -293,7 +293,10 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
[completionPopUp setCaretPos:pos];
[completionPopUp orderFront:self];
- [completionPopUp release];
+ //TODO : where to place the release??
+ // [completionPopUp release];
+
+
}
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index b678abfe..099757a4 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -29,6 +29,8 @@
#import "SPStringAdditions.h"
#import "SPTextViewAdditions.h"
#import "TableDocument.h"
+#import "TablesList.h"
+#import "RegexKitLite.h"
#define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@"
#define SP_HELP_SEARCH_IN_MYSQL 0
@@ -380,17 +382,21 @@
- (void)performQueries:(NSArray *)queries;
{
- NSArray *theColumns;
- NSTableColumn *theCol;
- CMMCPResult *theResult = nil;
- NSMutableArray *menuItems = [NSMutableArray array];
- NSMutableArray *tempResult = [NSMutableArray array];
- NSMutableString *errors = [NSMutableString string];
+ NSArray *theColumns;
+ NSTableColumn *theCol;
+ CMMCPResult *theResult = nil;
+ NSMutableArray *menuItems = [NSMutableArray array];
+ NSMutableArray *tempResult = [NSMutableArray array];
+ NSMutableString *errors = [NSMutableString string];
+
int i, totalQueriesRun = 0, totalAffectedRows = 0;
float executionTime = 0;
int firstErrorOccuredInQuery = -1;
BOOL suppressErrorSheet = NO;
- // NSString *delimiterMatch = @"^\\s*delimiter\\s*$|^\\s*delimiter\\s+\\S+\\s*$";
+ BOOL tableListNeedsReload = NO;
+ BOOL databaseWasChanged = NO;
+ BOOL queriesSeparatedByDelimiter = NO;
+
NSCharacterSet *whitespaceAndNewlineSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
// Notify listeners that a query has started
@@ -407,11 +413,9 @@
[customQueryView removeTableColumn:[theColumns objectAtIndex:0]];
}
- BOOL queriesSeparatedByDelimiter = NO;
-
// Perform the supplied queries in series
for ( i = 0 ; i < [queries count] ; i++ ) {
-
+
// Don't run blank queries, or queries which only contain whitespace.
if ([[[queries objectAtIndex:i] stringByTrimmingCharactersInSet:whitespaceAndNewlineSet] length] == 0)
continue;
@@ -427,12 +431,12 @@
// Store any error messages
if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
-
+
// If the query errored, append error to the error log for display at the end
if ( [queries count] > 1 ) {
if(firstErrorOccuredInQuery == -1)
firstErrorOccuredInQuery = i+1;
-
+
if(!suppressErrorSheet)
{
// Update error text for the user
@@ -459,7 +463,7 @@
[errors appendString:NSLocalizedString(@"Execution stopped!\n", @"execution stopped message")];
i = [queries count]; // break for loop; for safety reasons stop the execution of the following queries
}
-
+
} else {
[errors appendString:[NSString stringWithFormat:NSLocalizedString(@"[ERROR in query %d] %@\n", @"error text when multiple custom query failed"),
i+1,
@@ -468,8 +472,27 @@
} else {
[errors setString:[mySQLConnection getLastErrorMessage]];
}
+ } else {
+ // Check if table list needs an update
+ if(!tableListNeedsReload && [[queries objectAtIndex:i] isMatchedByRegex:@"(?i)^\\s*(create|alter|drop|rename)\\s"])
+ tableListNeedsReload = YES;
+ if(!databaseWasChanged && [[queries objectAtIndex:i] isMatchedByRegex:@"(?i)^\\s*(use|drop\\s+database|drop\\s+schema)\\s"])
+ databaseWasChanged = YES;
}
}
+
+ // Reload table list if at least one query began with drop, alter, rename, or create
+ if(tableListNeedsReload || databaseWasChanged) {
+ // Build database pulldown menu
+ [[tableWindow delegate] setDatabases:self];
+
+ if (databaseWasChanged)
+ // Reset the current database
+ [[tableWindow delegate] refreshCurrentDatabase];
+
+ // Reload table list
+ [[[tableWindow delegate] valueForKeyPath:@"tablesListInstance"] updateTables:self];
+ }
if(usedQuery)
[usedQuery release];
@@ -1813,6 +1836,7 @@
[searchInMySQL setTarget:self];
[webViewMenuItems insertObject:searchInMySQL atIndex:0];
[searchInMySQL release];
+
}
return webViewMenuItems;
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index f492a3bc..1a718b32 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -184,6 +184,7 @@
- (void)showVariables:(id)sender;
- (void)closeConnection;
- (NSWindow *)getCreateTableSyntaxWindow;
+- (void) refreshCurrentDatabase;
//getter methods
- (NSString *)name;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 192c93a5..cea86c3c 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -911,6 +911,47 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
[alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removedatabase"];
}
+/*
+ * Reset the current selected database name
+ */
+- (void) refreshCurrentDatabase
+{
+ NSString *dbName;
+
+ // Notify listeners that a query has started
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self];
+
+ CMMCPResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"];
+ if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
+ int i;
+ int r = [theResult numOfRows];
+ if (r) [theResult dataSeek:0];
+ for ( i = 0 ; i < r ; i++ ) {
+ dbName = [[theResult fetchRowAsArray] objectAtIndex:0];
+ }
+ if(![dbName isKindOfClass:[NSNull class]]) {
+ if(![dbName isEqualToString:selectedDatabase]) {
+ if (selectedDatabase) {
+ [selectedDatabase release];
+ selectedDatabase = nil;
+ }
+ selectedDatabase = [dbName retain];
+ [chooseDatabaseButton selectItemWithTitle:selectedDatabase];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@", mySQLVersion, [self name], selectedDatabase]];
+ }
+ } else {
+ [selectedDatabase release];
+ selectedDatabase = nil;
+ [chooseDatabaseButton selectItemAtIndex:0];
+ [tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/", mySQLVersion, [self name]]];
+ }
+ }
+
+ //query finished
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
+
+}
+
#pragma mark -
#pragma mark Console methods
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 5922ccd2..5466f42f 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -468,33 +468,47 @@
//get array with an object for each mysql-query
queries = [dumpFile splitSqlStringByCharacter:';'];
+ unsigned long queryCount = [queries count];
+
[singleProgressBar stopAnimation:self];
[singleProgressBar setUsesThreadedAnimation:NO];
[singleProgressBar setIndeterminate:NO];
+ [singleProgressText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Executing %d statements...", @"text showing that app is executing x statements"), queryCount]];
NSCharacterSet *whitespaceAndNewline = [NSCharacterSet whitespaceAndNewlineCharacterSet];
- unsigned long queryCount = [queries count];
//perform all mysql-queries
- for ( i = 0 ; i < queryCount ; i++ ) {
- [singleProgressBar setDoubleValue:((i+1)*100/queryCount)];
- [singleProgressBar displayIfNeeded];
+ if (importSQLAsUTF8)
+ for ( i = 0 ; i < queryCount ; i++ ) {
+ [singleProgressBar setDoubleValue:(i*100/queryCount)];
+ // [singleProgressBar displayIfNeeded];
- // Skip blank or whitespace-only queries to avoid errors
- if ([[[queries objectAtIndex:i] stringByTrimmingCharactersInSet:whitespaceAndNewline] length] == 0)
- continue;
+ // Skip blank or whitespace-only queries to avoid errors
+ NSString *q = [[queries objectAtIndex:i] stringByTrimmingCharactersInSet:whitespaceAndNewline];
+ if (![q length]) continue;
- if (importSQLAsUTF8) {
- [mySQLConnection queryString:[queries objectAtIndex:i] usingEncoding:NSUTF8StringEncoding];
- } else {
- [mySQLConnection queryString:[queries objectAtIndex:i]];
+ [mySQLConnection queryString:q usingEncoding:NSUTF8StringEncoding];
+
+ if ([[mySQLConnection getLastErrorMessage] length] && ![[mySQLConnection getLastErrorMessage] isEqualToString:@"Query was empty"]) {
+ [errors appendString:[NSString stringWithFormat:NSLocalizedString(@"[ERROR in query %d] %@\n", @"error text when multiple custom query failed"), (i+1),[mySQLConnection getLastErrorMessage]]];
+ }
}
-
- if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""] && ![[mySQLConnection getLastErrorMessage] isEqualToString:@"Query was empty"]) {
- [errors appendString:[NSString stringWithFormat:NSLocalizedString(@"[ERROR in query %d] %@\n", @"error text when multiple custom query failed"), (i+1),[mySQLConnection getLastErrorMessage]]];
+ else
+ for ( i = 0 ; i < queryCount ; i++ ) {
+ [singleProgressBar setDoubleValue:(i*100/queryCount)];
+ // [singleProgressBar displayIfNeeded];
+
+ // Skip blank or whitespace-only queries to avoid errors
+ NSString *q = [[queries objectAtIndex:i] stringByTrimmingCharactersInSet:whitespaceAndNewline];
+ if (![q length]) continue;
+
+ [mySQLConnection queryString:q];
+
+ if ([[mySQLConnection getLastErrorMessage] length] && ![[mySQLConnection getLastErrorMessage] isEqualToString:@"Query was empty"]) {
+ [errors appendString:[NSString stringWithFormat:NSLocalizedString(@"[ERROR in query %d] %@\n", @"error text when multiple custom query failed"), (i+1),[mySQLConnection getLastErrorMessage]]];
+ }
}
- }
-
+
//close progress sheet
[NSApp endSheet:singleProgressSheet];
[singleProgressSheet orderOut:nil];
@@ -507,20 +521,23 @@
modalDelegate:self
didEndSelector:nil
contextInfo:nil];
-
+
[NSApp runModalForWindow:errorsSheet];
-
+
[NSApp endSheet:errorsSheet];
[errorsSheet orderOut:nil];
}
-
- //update tables list
+
+ //update available databases
+ [tableDocumentInstance setDatabases:self];
+ //update current selected database
+ [tableDocumentInstance refreshCurrentDatabase];
+ //udpate current database tables
[tablesListInstance updateTables:self];
-
- ////////////////
- // IMPORT CSV //
- ////////////////
-
+
+ ////////////////
+ // IMPORT CSV //
+ ////////////////
} else if ( [fileType isEqualToString:@"CSV"] ) {
int code;
//open progress sheet
@@ -604,9 +621,9 @@
[buttonCell setFont:[NSFont labelFontOfSize:[NSFont smallSystemFontSize]]];
[buttonCell setBordered:NO];
[[fieldMappingTableView tableColumnWithIdentifier:@"value"] setDataCell:buttonCell];
- [buttonCell release];
[self updateFieldMappingButtonCell];
[fieldMappingTableView reloadData];
+ [buttonCell release];
// show fieldMapping sheet
[NSApp beginSheet:fieldMappingSheet
@@ -708,7 +725,6 @@
//free arrays
fieldMappingArray = nil;
importArray = nil;
-
}
// Import finished Growl notification
@@ -805,7 +821,8 @@
*/
- (BOOL)dumpSelectedTablesAsSqlToFileHandle:(NSFileHandle *)fileHandle
{
- int i,j,t,rowCount, colCount, progressBarWidth, lastProgressValue, queryLength;
+ int i,j,t,rowCount, colCount, lastProgressValue, queryLength;
+ // int progressBarWidth;
int tableType = SP_TABLETYPE_TABLE; //real tableType will be setup later
CMMCPResult *queryResult;
NSString *tableName, *tableColumnTypeGrouping, *previousConnectionEncoding;
@@ -1285,7 +1302,7 @@
lineEndString = [NSString stringWithString:tempLineEndString];
// Updating the progress bar can take >20% of processing time - store details to only update when required
- //progressBarWidth = (int)[singleProgressBar bounds].size.width;
+ progressBarWidth = (int)[singleProgressBar bounds].size.width;
lastProgressValue = 0;
[singleProgressBar setDoubleValue:0];
[singleProgressBar displayIfNeeded];
@@ -1602,7 +1619,8 @@
NSMutableString *xmlString = [NSMutableString string];
NSMutableString *xmlItem = [NSMutableString string];
NSString *dataConversionString;
- int i,j, startingRow, totalRows, progressBarWidth, lastProgressValue;
+ int i,j, startingRow, totalRows, lastProgressValue;
+ // int progressBarWidth;
if (queryResult != nil && [queryResult numOfRows]) [queryResult dataSeek:0];
diff --git a/Source/TablesList.m b/Source/TablesList.m
index b5536fd9..2d8ad1dc 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -52,7 +52,8 @@
NSInteger selectedRowIndex;
selectedRowIndex = [tablesListView selectedRow];
- if(selectedRowIndex > 0 && [tables count]){
+
+ if(selectedRowIndex > 0 && [tables count] && selectedRowIndex < [tables count]){
selectedTable = [NSString stringWithString:[tables objectAtIndex:selectedRowIndex]];
}
@@ -187,7 +188,7 @@
[tablesListView reloadData];
- //if the previous selected table still exists, select it
+ // if the previous selected table still exists, select it
if( selectedTable != nil && [tables indexOfObject:selectedTable] < [tables count]) {
[tablesListView selectRowIndexes:[NSIndexSet indexSetWithIndex:[tables indexOfObject:selectedTable]] byExtendingSelection:NO];
}
@@ -489,8 +490,6 @@
[scanner scanUpToString:@"" intoString:&scanString];
[mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE %@ %@", [[copyTableNameField stringValue] backtickQuotedString], scanString]];
}
- [scanner release];
-
else if(tblType == SP_TABLETYPE_FUNC || tblType == SP_TABLETYPE_PROC)
{
// get the create syntax
@@ -518,13 +517,13 @@
// replace the old name by the new one and drop the old one
[mySQLConnection queryString:[tableSyntax stringByReplacingOccurrencesOfRegex:[NSString stringWithFormat:@"(?<=%@ )(`[^`]+?`)", [tableType uppercaseString]] withString:[[copyTableNameField stringValue] backtickQuotedString]]];
[tableSyntax release];
-
if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil,
[NSString stringWithFormat:NSLocalizedString(@"Couldn't duplicate '%@'.\nMySQL said: %@", @"message of panel when an item cannot be renamed"), [copyTableNameField stringValue], [mySQLConnection getLastErrorMessage]]);
}
}
+ [scanner release];
if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) {
//error while creating new table
@@ -988,7 +987,6 @@
// replace the old name by the new one and drop the old one
[mySQLConnection queryString:[tableSyntax stringByReplacingOccurrencesOfRegex:[NSString stringWithFormat:@"(?<=%@ )(`[^`]+?`)", tableType] withString:[anObject backtickQuotedString]]];
[tableSyntax release];
-
if ([[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
if ([mySQLConnection isConnected]) {
[mySQLConnection queryString: [NSString stringWithFormat: @"DROP %@ %@", tableType, [[tables objectAtIndex:rowIndex] backtickQuotedString]]];