diff options
author | stuconnolly <stuart02@gmail.com> | 2009-03-01 13:39:43 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-03-01 13:39:43 +0000 |
commit | 33bf02039fc6902fa1951fef690fc0ee3b8d5cf9 (patch) | |
tree | 56c48ddb687b1c3c9a43c9719f0dedcb69dc6b73 /Source/TableContent.m | |
parent | 8441dab08d995615add28fecb06e07719edbe6a6 (diff) | |
download | sequelpro-33bf02039fc6902fa1951fef690fc0ee3b8d5cf9.tar.gz sequelpro-33bf02039fc6902fa1951fef690fc0ee3b8d5cf9.tar.bz2 sequelpro-33bf02039fc6902fa1951fef690fc0ee3b8d5cf9.zip |
Fix an issue where by selecting to view the content of a table without the option of fetching the accurate row count and limiting the result, results in the displayed row count being zero. Caused by fetching the count as the number of items in the fullResult array which hadn't been populated yet. If we are displaying the entire contents of the table set the count to the count of the fullResult array rather than relying on the numRows variable as the array is now populated.
Diffstat (limited to 'Source/TableContent.m')
-rw-r--r-- | Source/TableContent.m | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m index c2db04c2..b3044c94 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -48,13 +48,9 @@ return self; } -- (void)awakeFromNib -{ -} - /* - Loads aTable, retrieving column information and updating the tableViewColumns before - reloading table data into the fullResults array and redrawing the table. + * Loads aTable, retrieving column information and updating the tableViewColumns before + * reloading table data into the fullResults array and redrawing the table. */ - (void)loadTable:(NSString *)aTable { @@ -277,6 +273,7 @@ if ( isDesc ) query = [query stringByAppendingString:@" DESC"]; } + if ( [prefs boolForKey:@"limitRows"] ) { if ( [limitRowsField intValue] <= 0 ) { [limitRowsField setStringValue:@"1"]; @@ -285,20 +282,22 @@ [NSString stringWithFormat:@" LIMIT %d,%d", [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; } + queryResult = [mySQLConnection queryString:query]; if ( queryResult == nil ) { NSLog(@"Loading table data for %@ failed, query string was: %@", aTable, query); return; } + [fullResult setArray:[self fetchResultAsArray:queryResult]]; // Apply any filtering and update the row count - if ( !areShowingAllRows ) { + if (!areShowingAllRows) { [self filterTable:self]; [countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows of %d selected", @"text showing how many rows are in the filtered result"), [filteredResult count], numRows]]; } else { [filteredResult setArray:fullResult]; - [countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows in table", @"text showing how many rows are in the result"), numRows]]; + [countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows in table", @"text showing how many rows are in the result"), [fullResult count]]]; } // Reload the table data. @@ -308,7 +307,6 @@ [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self]; } - /* * Reloads the current table data, performing a new SQL query. Now attempts to preserve sort order, filters, and viewport. */ @@ -1520,29 +1518,29 @@ } } -- (int)getNumberOfRows /* - returns the number of rows in the selected table - queries the number from mysql if enabled in prefs and result is limited, otherwise just return the fullResult count + * Returns the number of rows in the selected table + * Queries the number from MySQL if enabled in prefs and result is limited, otherwise just return the fullResult count. */ +- (int)getNumberOfRows { - if ( [prefs boolForKey:@"limitRows"] && [prefs boolForKey:@"fetchRowCount"] ) { + if ([prefs boolForKey:@"limitRows"] && [prefs boolForKey:@"fetchRowCount"]) { numRows = [self fetchNumberOfRows]; } else { numRows = [fullResult count]; } + return numRows; } -- (int)fetchNumberOfRows /* - fetches the number of rows in the selected table using a "SELECT COUNT(1)" query and return it + * Fetches the number of rows in the selected table using a "SELECT COUNT(1)" query and return it */ +- (int)fetchNumberOfRows { return [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM `%@`", selectedTable]] fetchRowAsArray] objectAtIndex:0] intValue]; } - //tableView datasource methods - (int)numberOfRowsInTableView:(NSTableView *)aTableView { |