aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableData.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2013-01-21 00:51:01 +0000
committerrowanbeentje <rowan@beent.je>2013-01-21 00:51:01 +0000
commitfb74197b3affc05405439458d01e2f45eec47816 (patch)
treec0963a1b3aeed9d01b27e058e396670fd4c97f62 /Source/SPTableData.m
parenta192312d3060c37c9451ac05e1a939293db5b941 (diff)
downloadsequelpro-fb74197b3affc05405439458d01e2f45eec47816.tar.gz
sequelpro-fb74197b3affc05405439458d01e2f45eec47816.tar.bz2
sequelpro-fb74197b3affc05405439458d01e2f45eec47816.zip
- Fix a problem where the row count for InnoDB would not be displayed as an accurate value, whatever the Preferences setting, if the Content table was not selected
- Clean up code slightly - Remove an unneccessary query being used for the table information view, speeding up display slightly
Diffstat (limited to 'Source/SPTableData.m')
-rw-r--r--Source/SPTableData.m58
1 files changed, 58 insertions, 0 deletions
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.