From 16aee03a9c48ffdaf33fd3f2c99f7b5a933ca0ee Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 6 Apr 2009 15:47:20 +0000 Subject: =?UTF-8?q?=E2=80=A2=20FIXED:=20"Limit=20from"=20NSStepper=20retai?= =?UTF-8?q?ns=20the=20old=20value=20if=20the=20new=20value=20would=20be=20?= =?UTF-8?q?greater=20than=20the=20total=20number=20of=20rows=20of=20the=20?= =?UTF-8?q?current=20table=20=E2=80=A2=20FIXED:=20if=20the=20user=20enters?= =?UTF-8?q?=20into=20"Limit=20from"=20a=20number=20which=20is=20greater=20?= =?UTF-8?q?than=20the=20total=20number=20of=20rows=20of=20the=20current=20?= =?UTF-8?q?table,=20show=20the=20last=20pref's=20"limitRowsValue"=20number?= =?UTF-8?q?=20of=20rows=20instead=20=E2=80=A2=20FIXED:=20if=20the=20user?= =?UTF-8?q?=20has=20already=20filtered=20the=20current=20table=20by=20spec?= =?UTF-8?q?ifying=20"Limit=20from"=20>=201=20and=20afterwards=20the=20user?= =?UTF-8?q?=20applied=20a=20new=20filter=20the=20filtering=20will=20be=20r?= =?UTF-8?q?epeated=20for=20LIMIT=200,=20"limitRowsValue"=20if=20nothing=20?= =?UTF-8?q?was=20found?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableContent.h | 2 +- Source/TableContent.m | 28 +++++++++++++++++++++++++++- 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]; -- cgit v1.2.3