aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPConstants.h1
-rw-r--r--Source/SPConstants.m1
-rw-r--r--Source/SPDatabaseViewController.m18
-rw-r--r--Source/SPExtendedTableInfo.m13
-rw-r--r--Source/SPTableContent.h1
-rw-r--r--Source/SPTableContent.m61
-rw-r--r--Source/SPTableData.h1
-rw-r--r--Source/SPTableData.m58
-rw-r--r--Source/SPTableInfo.m4
9 files changed, 106 insertions, 52 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index bcf0d5b3..91e2492f 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -408,6 +408,7 @@ extern NSString *SPQueryHistory;
extern NSString *SPQueryHistoryReplacesContent;
extern NSString *SPQuickLookTypes;
extern NSString *SPTableChangedNotification;
+extern NSString *SPTableInfoChangedNotification;
extern NSString *SPBlobTextEditorSpellCheckingEnabled;
extern NSString *SPUniqueSchemaDelimiter;
extern NSString *SPLastImportIntoNewTableEncoding;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index 2bc3f39d..24065072 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -214,6 +214,7 @@ NSString *SPQueryHistory = @"queryHistory";
NSString *SPQueryHistoryReplacesContent = @"QueryHistoryReplacesContent";
NSString *SPQuickLookTypes = @"QuickLookTypes";
NSString *SPTableChangedNotification = @"SPTableSelectionChanged";
+NSString *SPTableInfoChangedNotification = @"SPTableInformationChanged";
NSString *SPBlobTextEditorSpellCheckingEnabled = @"BlobTextEditorSpellCheckingEnabled";
NSString *SPUniqueSchemaDelimiter = @"￸"; // U+FFF8
NSString *SPLastImportIntoNewTableEncoding = @"LastImportIntoNewTableEncoding";
diff --git a/Source/SPDatabaseViewController.m b/Source/SPDatabaseViewController.m
index defc8e26..2f6af2e7 100644
--- a/Source/SPDatabaseViewController.m
+++ b/Source/SPDatabaseViewController.m
@@ -180,9 +180,7 @@
[mainToolbar setSelectedItemIdentifier:SPMainToolbarTableInfo];
[spHistoryControllerInstance updateHistoryEntries];
- // Refresh data
- if([self table] && [[self table] length]) {
- [tableDataInstance resetAllData];
+ if ([[self table] length]) {
[extendedTableInfoInstance loadTable:[self table]];
}
@@ -230,11 +228,15 @@
*/
- (void)setStructureRequiresReload:(BOOL)reload
{
+ BOOL reloadRequired = reload;
+
#ifndef SP_REFACTOR
- if (reload && selectedTableName && [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == SPTableViewStructure) {
-#else
- if (reload && selectedTableName ) {
+ if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == SPTableViewStructure) {
+ reloadRequired = NO;
+ }
#endif
+
+ if (reloadRequired && selectedTableName) {
[tableSourceInstance loadTable:selectedTableName];
} else {
structureLoaded = !reload;
@@ -525,6 +527,10 @@
if (!statusLoaded) [[extendedTableInfoInstance onMainThread] loadTable:nil];
if (!triggersLoaded) [[tableTriggersInstance onMainThread] resetInterface];
+ // If the table row counts an inaccurate and require updating, trigger an update - no
+ // action will be performed if not necessary
+ [tableDataInstance updateAccurateNumberOfRowsForCurrentTableForcingUpdate:NO];
+
#ifndef SP_REFACTOR /* show Create Table syntax */
// Update the "Show Create Syntax" window if it's already opened
// according to the selected table/view/proc/func
diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m
index edb3fd23..6f4f9ae8 100644
--- a/Source/SPExtendedTableInfo.m
+++ b/Source/SPExtendedTableInfo.m
@@ -49,6 +49,7 @@ static NSString *SPUpdateTableTypeNewType = @"SPUpdateTableTypeNewType";
@interface SPExtendedTableInfo ()
+- (void)_updateDisplayedInfo:(NSNotification *)aNotification;
- (void)_changeCurrentTableTypeFrom:(NSString *)currentType to:(NSString *)newType;
- (NSString *)_formatValueWithKey:(NSString *)key inDictionary:(NSDictionary *)statusDict;
@@ -72,6 +73,10 @@ static NSString *SPUpdateTableTypeNewType = @"SPUpdateTableTypeNewType";
selector:@selector(endDocumentTaskForTab:)
name:SPDocumentTaskEndNotification
object:tableDocumentInstance];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(_updateDisplayedInfo:)
+ name:SPTableInfoChangedNotification
+ object:tableDocumentInstance];
}
#pragma mark -
@@ -617,6 +622,14 @@ static NSString *SPUpdateTableTypeNewType = @"SPUpdateTableTypeNewType";
#pragma mark Private API
/**
+ * Trigger an update to a display in reaction to changes in external data
+ */
+- (void)_updateDisplayedInfo:(NSNotification *)aNotification
+{
+ [self loadTable:selectedTable];
+}
+
+/**
* Changes the current table's storage engine to the supplied type.
*/
- (void)_changeCurrentTableTypeFrom:(NSString *)currentType to:(NSString *)newType
diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h
index 66aab772..3d191da4 100644
--- a/Source/SPTableContent.h
+++ b/Source/SPTableContent.h
@@ -272,7 +272,6 @@
- (BOOL)tableContainsBlobOrTextColumns;
- (NSString *)fieldListForQuery;
- (void)updateNumberOfRows;
-- (NSInteger)fetchNumberOfRows;
- (void)autosizeColumns;
- (BOOL)saveRowOnDeselect;
- (void)sortTableTaskWithColumn:(NSTableColumn *)tableColumn;
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 71657916..94e86694 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -4063,45 +4063,24 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper
[[[tableDocumentInstance valueForKey:@"extendedTableInfoInstance"] onMainThread] loadTable:selectedTable];
#endif
- // Otherwise, if the table status value is accurate, use it
- } else if ([[tableDataInstance statusValueForKey:@"RowsCountAccurate"] boolValue]) {
- maxNumRows = [[tableDataInstance statusValueForKey:@"Rows"] integerValue];
- maxNumRowsIsEstimate = NO;
- checkStatusCount = YES;
+ } else {
- // Choose whether to display an estimate, or to fetch the correct row count, based on prefs
- } else if (
-#ifndef SP_REFACTOR
- [[prefs objectForKey:SPTableRowCountQueryLevel] integerValue] == SPRowCountFetchAlways
- || ([[prefs objectForKey:SPTableRowCountQueryLevel] integerValue] == SPRowCountFetchIfCheap
- &&
-#endif
- [tableDataInstance statusValueForKey:@"Data_length"]
- &&
-#ifndef SP_REFACTOR
- [[prefs objectForKey:SPTableRowCountCheapSizeBoundary] integerValue]
-#else
- 5242880
-#endif
- > [[tableDataInstance statusValueForKey:@"Data_length"] integerValue])
-#ifndef SP_REFACTOR
- )
-#endif
- {
- maxNumRows = [self fetchNumberOfRows];
- maxNumRowsIsEstimate = NO;
- [tableDataInstance setStatusValue:[NSString stringWithFormat:@"%ld", (long)maxNumRows] forKey:@"Rows"];
- [tableDataInstance setStatusValue:@"y" forKey:@"RowsCountAccurate"];
-#ifndef SP_REFACTOR
- [[tableInfoInstance onMainThread] tableChanged:nil];
-#endif
- [[[tableDocumentInstance valueForKey:@"extendedTableInfoInstance"] onMainThread] loadTable:selectedTable];
+ // Trigger an update via the SPTableData instance if preferences require it, and if
+ // the state is not already accurate
+ [tableDataInstance updateAccurateNumberOfRowsForCurrentTableForcingUpdate:NO];
- // Use the estimate count
- } else {
- maxNumRows = [[tableDataInstance statusValueForKey:@"Rows"] integerValue];
- maxNumRowsIsEstimate = YES;
- checkStatusCount = YES;
+ // If the state is now accurate, use it
+ if ([[tableDataInstance statusValueForKey:@"RowsCountAccurate"] boolValue]) {
+ maxNumRows = [[tableDataInstance statusValueForKey:@"Rows"] integerValue];
+ maxNumRowsIsEstimate = NO;
+ checkStatusCount = YES;
+
+ // Otherwise, use the estimate count
+ } else {
+ maxNumRows = [[tableDataInstance statusValueForKey:@"Rows"] integerValue];
+ maxNumRowsIsEstimate = YES;
+ checkStatusCount = YES;
+ }
}
// Check whether the estimated count requires updating, ie if the retrieved count exceeds it
@@ -4136,14 +4115,6 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper
}
/**
- * Fetches the number of rows in the selected table using a "SELECT COUNT(1)" query and return it
- */
-- (NSInteger)fetchNumberOfRows
-{
- return [[mySQLConnection getFirstFieldFromQuery:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@", [selectedTable backtickQuotedString]]] integerValue];
-}
-
-/**
* Autosize all columns based on their content.
* Should be called on the main thread.
*/
diff --git a/Source/SPTableData.h b/Source/SPTableData.h
index 51f2fd73..0806bd8b 100644
--- a/Source/SPTableData.h
+++ b/Source/SPTableData.h
@@ -81,6 +81,7 @@
- (NSDictionary *) informationForView:(NSString *)viewName;
- (BOOL) updateStatusInformationForCurrentTable;
- (BOOL) updateTriggersForCurrentTable;
+- (BOOL) updateAccurateNumberOfRowsForCurrentTableForcingUpdate:(BOOL)alwaysUpdate;
- (NSDictionary *) parseFieldDefinitionStringParts:(NSArray *)definitionParts;
- (NSArray *) primaryKeyColumnNames;
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index 60c4b756..ad3416aa 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -1093,6 +1093,64 @@
}
/**
+ * Retrieve the number of rows in the current table if necessary; if a value has already been
+ * set for the current table/view, no update will occur. However, if the row count value
+ * is an estimate but the preferences are set to retrieve accurate row counts, this will
+ * run a COUNT query to retrieve an accurate value.
+ * Returns YES if the update was successful or not needed, or NO if the update failed
+ */
+- (BOOL) updateAccurateNumberOfRowsForCurrentTableForcingUpdate:(BOOL)alwaysUpdate
+{
+
+ // If no table is currently selected, return failure
+ if (![tableListInstance tableName]) {
+ return NO;
+ }
+
+ // No action needed for non-tables
+ if ([tableListInstance tableType] != SPTableTypeTable) {
+ return YES;
+ }
+
+ // Unless the force option was used, try to work out whether the update is needed
+ if (!alwaysUpdate) {
+
+ // If the row count is already accurate, no further work is required
+ if ([[self statusValueForKey:@"RowsCountAccurate"] boolValue]) {
+ return YES;
+ }
+
+ SPRowCountQueryUsageLevels rowCountLevel = SPRowCountFetchAlways;
+ NSInteger rowCountCheapBoundary = 5242880;
+#ifndef SP_REFACTOR
+ rowCountLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:SPTableRowCountQueryLevel] integerValue];
+ rowCountCheapBoundary = [[[NSUserDefaults standardUserDefaults] objectForKey:SPTableRowCountCheapSizeBoundary] integerValue];
+#endif
+
+ if (rowCountLevel == SPRowCountFetchNever
+ || (rowCountLevel == SPRowCountFetchIfCheap && [[self statusValueForKey:@"Data_length"] integerValue] >= rowCountCheapBoundary))
+ {
+ return YES;
+ }
+ }
+
+ // Fetch the number of rows
+ SPMySQLResult *rowResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@", [[tableListInstance tableName] backtickQuotedString]]];
+ if ([mySQLConnection queryErrored]) {
+ return NO;
+ }
+
+ // Store the number of rows
+ [status setObject:[[rowResult getRowAsArray] objectAtIndex:0] forKey:@"Rows"];
+ [status setObject:@"y" forKey:@"RowsCountAccurate"];
+
+ // Trigger an update to the table info pane and view
+ [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableInfoChangedNotification object:tableDocumentInstance];
+
+ return YES;
+}
+
+/**
* Parse an array of field definition parts - not including name but including type and optionally unsigned/zerofill/null
* and so forth - into a dictionary of parsed details. Intended for use both with CREATE TABLE syntax - with fuller
* details - and with the "type" column from SHOW COLUMNS.
diff --git a/Source/SPTableInfo.m b/Source/SPTableInfo.m
index 3ccb1515..bda2962e 100644
--- a/Source/SPTableInfo.m
+++ b/Source/SPTableInfo.m
@@ -67,6 +67,10 @@
selector:@selector(tableChanged:)
name:SPTableChangedNotification
object:tableDocumentInstance];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(tableChanged:)
+ name:SPTableInfoChangedNotification
+ object:tableDocumentInstance];
// Register activities update notifications for add/remove BASH commands etc.
[[NSNotificationCenter defaultCenter] addObserver:self