aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-04-06 15:47:20 +0000
committerBibiko <bibiko@eva.mpg.de>2009-04-06 15:47:20 +0000
commit16aee03a9c48ffdaf33fd3f2c99f7b5a933ca0ee (patch)
tree84955e2c83372f5805cd1afa64f7e6565c377f91
parent2c5cc993e46a39e8ee15d82e21e88eaa7d5d602d (diff)
downloadsequelpro-16aee03a9c48ffdaf33fd3f2c99f7b5a933ca0ee.tar.gz
sequelpro-16aee03a9c48ffdaf33fd3f2c99f7b5a933ca0ee.tar.bz2
sequelpro-16aee03a9c48ffdaf33fd3f2c99f7b5a933ca0ee.zip
• FIXED: "Limit from" NSStepper retains the old value if the new value would be greater than the total number of rows of the current table
• FIXED: if the user enters into "Limit from" a number which is greater than the total number of rows of the current table, show the last pref's "limitRowsValue" number of rows instead • FIXED: if the user has already filtered the current table by specifying "Limit from" > 1 and afterwards the user applied a new filter the filtering will be repeated for LIMIT 0, "limitRowsValue" if nothing was found
-rw-r--r--Source/TableContent.h2
-rw-r--r--Source/TableContent.m28
2 files changed, 28 insertions, 2 deletions
diff --git a/Source/TableContent.h b/Source/TableContent.h
index 644a6b86..cc242aba 100644
--- a/Source/TableContent.h
+++ b/Source/TableContent.h
@@ -64,7 +64,7 @@
NSString *compareType, *sortField;
BOOL isEditingRow, isEditingNewRow, isSavingRow, isDesc, setLimit;
NSUserDefaults *prefs;
- int numRows, currentlyEditingRow;
+ int numRows, currentlyEditingRow, maxNumRowsOfCurrentTable;
bool areShowingAllRows;
}
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 2e192d4b..386c5092 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -136,6 +136,10 @@
// of the fieldListForQuery method, and also to decide whether or not to preserve the current filter/sort settings.
theColumns = [tableDataInstance columns];
columnNames = [tableDataInstance columnNames];
+
+ // Retrieve the total number of rows of the current table
+ // to adjustify "Limit From:"
+ maxNumRowsOfCurrentTable = [[[tableDataInstance statusValues] objectForKey:@"Rows"] intValue];
// Retrieve the number of rows in the table and initially mark all as being visible.
numRows = [self getNumberOfRows];
@@ -421,6 +425,13 @@
if ( [limitRowsField intValue] <= 0 ) {
[limitRowsField setStringValue:@"1"];
}
+
+ // If limitRowsField > number of total found rows show the last limitRowsValue rows
+ if ( [prefs boolForKey:@"limitRows"] && [limitRowsField intValue] >= maxNumRowsOfCurrentTable ) {
+ int newLimit = maxNumRowsOfCurrentTable - [prefs integerForKey:@"limitRowsValue"];
+ [limitRowsField setStringValue:[[NSNumber numberWithInt:(newLimit<1)?1:newLimit] stringValue]];
+ }
+
// If the filter field is empty, the limit field is at 1, and the selected filter is not looking
// for NULLs or NOT NULLs, then don't allow filtering.
@@ -576,8 +587,12 @@
queryString = [queryString stringByAppendingString:@" DESC"];
}
+ // retain the query before LIMIT
+ // to redo the query if nothing found for LIMIT > 1
+ NSString* tempQueryString;
// LIMIT if appropriate
if ( [prefs boolForKey:@"limitRows"] ) {
+ tempQueryString = [NSString stringWithString:queryString];
queryString = [NSString stringWithFormat:@"%@ LIMIT %d,%d", queryString,
[limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]];
}
@@ -585,6 +600,15 @@
theResult = [mySQLConnection queryString:queryString];
[filteredResult setArray:[self fetchResultAsArray:theResult]];
+ // try it again if theResult is empty and limitRowsField > 1 by setting LIMIT to 0, limitRowsValue
+ if([prefs boolForKey:@"limitRows"] && [limitRowsField intValue] > 1 && [filteredResult count] == 0) {
+ queryString = [NSString stringWithFormat:@"%@ LIMIT %d,%d", tempQueryString,
+ 0, [prefs integerForKey:@"limitRowsValue"]];
+ theResult = [mySQLConnection queryString:queryString];
+ [limitRowsField setStringValue:@"1"];
+ [filteredResult setArray:[self fetchResultAsArray:theResult]];
+ }
+
[countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows of %d selected", @"text showing how many rows are in the filtered result"), [filteredResult count], numRows]];
// Reset the table view
@@ -1113,7 +1137,9 @@
*/
{
if ( [limitRowsStepper intValue] > 0 ) {
- [limitRowsField setIntValue:[limitRowsField intValue]+[prefs integerForKey:@"limitRowsValue"]];
+ int newStep = [limitRowsField intValue]+[prefs integerForKey:@"limitRowsValue"];
+ // if newStep > the total number of rows in the current table retain the old value
+ [limitRowsField setIntValue:(newStep>maxNumRowsOfCurrentTable)?[limitRowsField intValue]:newStep];
} else {
if ( ([limitRowsField intValue]-[prefs integerForKey:@"limitRowsValue"]) < 1 ) {
[limitRowsField setIntValue:1];