From 4c3b208fad0572d8d1a79bba1bd1b8147fd0f8a6 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 10 Dec 2008 00:48:32 +0000 Subject: - Re-add the LIMIT FROM NSStepper - Allow Return or Enter pressed in the Limit From textbox to trigger a table filter - Reset the content table view position on filtering or limit - Refresh no longer clears the LIMIT FROM value if it's still valid - Resolves Issue #65 and partially addresses Issue #49. --- English.lproj/DBView.xib | 102 ++++++++++++---- TableContent.m | 298 +++++++++++++++++++++++++---------------------- 2 files changed, 240 insertions(+), 160 deletions(-) diff --git a/English.lproj/DBView.xib b/English.lproj/DBView.xib index c8102000..579fd61a 100644 --- a/English.lproj/DBView.xib +++ b/English.lproj/DBView.xib @@ -2728,35 +2728,27 @@ 265 - {{153, 512}, {86, 20}} + {{153, 509}, {86, 25}} YES -1539178944 1024 - + + LucidaGrande + 1.200000e+01 + 4883 + - -2038284033 + -2038415105 36 - 400 75 - - - is - - 1048576 - 2147483647 - 1 - - - _popUpItemAction: - - + YES @@ -2764,9 +2756,20 @@ YES - + + + is + + 1048576 + 2147483647 + + + _popUpItemAction: + + + -1 3 YES YES @@ -3086,6 +3089,22 @@ 75 + + + 265 + {{597, 511}, {15, 22}} + + YES + + 604896800 + 131072 + + + 1.000000e+02 + 1.000000e+00 + YES + + {{10, 7}, {638, 544}} @@ -11757,6 +11776,30 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 4685 + + + limitRowsStepper + + + + 4688 + + + + stepLimitRows: + + + + 4689 + + + + performClick: + + + + 4693 + @@ -14962,6 +15005,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + @@ -16783,6 +16827,20 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + 4686 + + + YES + + + + + + 4687 + + + @@ -17766,6 +17824,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 4665.IBPluginDependency 4676.IBPluginDependency 4677.IBPluginDependency + 4686.IBPluginDependency + 4687.IBPluginDependency 47.IBPluginDependency 47.ImportedFromIB2 495.IBAttributePlaceholdersKey @@ -19269,6 +19329,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin ToolTip @@ -19280,8 +19342,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin - {{299, 286}, {863, 550}} - {{299, 286}, {863, 550}} + {{92, 286}, {863, 550}} + {{92, 286}, {863, 550}} {{62, 352}, {845, 504}} @@ -19694,7 +19756,7 @@ Y2hhbmdlIHRoZSBvcmRlcg - 4685 + 4695 diff --git a/TableContent.m b/TableContent.m index c3238a3c..1aa939f2 100644 --- a/TableContent.m +++ b/TableContent.m @@ -269,7 +269,11 @@ // Enable or disable the limit fields according to preference setting if ( [prefs boolForKey:@"limitRows"] ) { - [limitRowsField setStringValue:@"1"]; + + // Attempt to preserve the limit value if it's still valid + if (!preserveCurrentView || [limitRowsField intValue] < 1 || [limitRowsField intValue] >= numRows) { + [limitRowsField setStringValue:@"1"]; + } [limitRowsField setEnabled:YES]; [limitRowsButton setEnabled:YES]; [limitRowsStepper setEnabled:YES]; @@ -419,9 +423,15 @@ NSMutableString *argument = [[NSMutableString alloc] initWithString:[argumentField stringValue]]; NSString *queryString; int i; + + // Update negative limits + if ( [limitRowsField intValue] <= 0 ) { + [limitRowsField setStringValue:@"1"]; + } - // If the filter field is empty or the selected filter is not looking for NULLs or 'not' NULLs, then don't allow filtering. - if (([argument length] == 0) && (![[[compareField selectedItem] title] hasSuffix:@"NULL"])) { + // 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. + if (([argument length] == 0) && (![[[compareField selectedItem] title] hasSuffix:@"NULL"]) && (![prefs boolForKey:@"limitRows"] || [limitRowsField intValue] == 1)) { [argument release]; [self showAll:sender]; return; @@ -432,153 +442,161 @@ BOOL doQuote = YES; BOOL ignoreArgument = NO; - - if ( ![compareType isEqualToString:@""] ) { - if ( [compareType isEqualToString:@"string"] ) { - //string comparision - switch ( tag ) { - case 0: - compareOperator = @"LIKE"; - break; - case 1: - compareOperator = @"NOT LIKE"; - break; - case 2: - compareOperator = @"LIKE"; - [argument setString:[[@"%" stringByAppendingString:argument] stringByAppendingString:@"%"]]; - break; - case 3: - compareOperator = @"NOT LIKE"; - [argument setString:[[@"%" stringByAppendingString:argument] stringByAppendingString:@"%"]]; - break; - case 4: - compareOperator = @"IN"; - doQuote = NO; - [argument setString:[[@"(" stringByAppendingString:argument] stringByAppendingString:@")"]]; - break; - case 5: - compareOperator = @"IS NULL"; - doQuote = NO; - ignoreArgument = YES; - break; - case 6: - compareOperator = @"IS NOT NULL"; - doQuote = NO; - ignoreArgument = YES; - break; - } - } else if ( [compareType isEqualToString:@"number"] ) { - //number comparision - switch ( tag ) { - case 0: - compareOperator = @"="; - break; - case 1: - compareOperator = @"!="; - break; - case 2: - compareOperator = @">"; - break; - case 3: - compareOperator = @"<"; - break; - case 4: - compareOperator = @">="; - break; - case 5: - compareOperator = @"<="; - break; - case 6: - compareOperator = @"IN"; - doQuote = NO; - [argument setString:[[@"(" stringByAppendingString:argument] stringByAppendingString:@")"]]; - break; - case 7: - compareOperator = @"IS NULL"; - doQuote = NO; - ignoreArgument = YES; - break; - case 8: - compareOperator = @"IS NOT NULL"; - doQuote = NO; - ignoreArgument = YES; - break; - } - } else if ( [compareType isEqualToString:@"date"] ) { - //date comparision - switch ( tag ) { - case 0: - compareOperator = @"="; - break; - case 1: - compareOperator = @"!="; - break; - case 2: - compareOperator = @"<"; - break; - case 3: - compareOperator = @">"; - break; - case 4: - compareOperator = @"<="; - break; - case 5: - compareOperator = @">="; - break; - case 6: - compareOperator = @"IS NULL"; - doQuote = NO; - ignoreArgument = YES; - break; - case 7: - compareOperator = @"IS NOT NULL"; - doQuote = NO; - ignoreArgument = YES; - break; - } - } - - if (doQuote) { - //escape special characters - for ( i = 0 ; i < [argument length] ; i++ ) { - if ( [argument characterAtIndex:i] == '\\' ) { - [argument insertString:@"\\" atIndex:i]; - i++; + + // Start building the query string + queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@`", + [self fieldListForQuery], selectedTable]; + + // Add filter if appropriate + if (([argument length] > 0) || [[[compareField selectedItem] title] hasSuffix:@"NULL"]) { + if ( ![compareType isEqualToString:@""] ) { + if ( [compareType isEqualToString:@"string"] ) { + //string comparision + switch ( tag ) { + case 0: + compareOperator = @"LIKE"; + break; + case 1: + compareOperator = @"NOT LIKE"; + break; + case 2: + compareOperator = @"LIKE"; + [argument setString:[[@"%" stringByAppendingString:argument] stringByAppendingString:@"%"]]; + break; + case 3: + compareOperator = @"NOT LIKE"; + [argument setString:[[@"%" stringByAppendingString:argument] stringByAppendingString:@"%"]]; + break; + case 4: + compareOperator = @"IN"; + doQuote = NO; + [argument setString:[[@"(" stringByAppendingString:argument] stringByAppendingString:@")"]]; + break; + case 5: + compareOperator = @"IS NULL"; + doQuote = NO; + ignoreArgument = YES; + break; + case 6: + compareOperator = @"IS NOT NULL"; + doQuote = NO; + ignoreArgument = YES; + break; } + } else if ( [compareType isEqualToString:@"number"] ) { + //number comparision + switch ( tag ) { + case 0: + compareOperator = @"="; + break; + case 1: + compareOperator = @"!="; + break; + case 2: + compareOperator = @">"; + break; + case 3: + compareOperator = @"<"; + break; + case 4: + compareOperator = @">="; + break; + case 5: + compareOperator = @"<="; + break; + case 6: + compareOperator = @"IN"; + doQuote = NO; + [argument setString:[[@"(" stringByAppendingString:argument] stringByAppendingString:@")"]]; + break; + case 7: + compareOperator = @"IS NULL"; + doQuote = NO; + ignoreArgument = YES; + break; + case 8: + compareOperator = @"IS NOT NULL"; + doQuote = NO; + ignoreArgument = YES; + break; + } + } else if ( [compareType isEqualToString:@"date"] ) { + //date comparision + switch ( tag ) { + case 0: + compareOperator = @"="; + break; + case 1: + compareOperator = @"!="; + break; + case 2: + compareOperator = @"<"; + break; + case 3: + compareOperator = @">"; + break; + case 4: + compareOperator = @"<="; + break; + case 5: + compareOperator = @">="; + break; + case 6: + compareOperator = @"IS NULL"; + doQuote = NO; + ignoreArgument = YES; + break; + case 7: + compareOperator = @"IS NOT NULL"; + doQuote = NO; + ignoreArgument = YES; + break; + } + } else { + doQuote = NO; + ignoreArgument = YES; + NSLog(@"ERROR: unknown compare type %@", compareType); } - [argument setString:[mySQLConnection prepareString:argument]]; - queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@` WHERE `%@` %@ \"%@\"", - [self fieldListForQuery], selectedTable, [fieldField titleOfSelectedItem], - compareOperator, argument]; - } else { - queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@` WHERE `%@` %@ %@", - [self fieldListForQuery], selectedTable, [fieldField titleOfSelectedItem], - compareOperator, (ignoreArgument) ? @"" : argument]; - } - if ( sortField ) { - // queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]]; - queryString = [NSString stringWithFormat:@"%@ ORDER BY `%@`", queryString, sortField]; - if ( isDesc ) - queryString = [queryString stringByAppendingString:@" DESC"]; - } - if ( [prefs boolForKey:@"limitRows"] ) { - if ( [limitRowsField intValue] <= 0 ) { - [limitRowsField setStringValue:@"1"]; + + if (doQuote) { + //escape special characters + for ( i = 0 ; i < [argument length] ; i++ ) { + if ( [argument characterAtIndex:i] == '\\' ) { + [argument insertString:@"\\" atIndex:i]; + i++; + } + } + [argument setString:[mySQLConnection prepareString:argument]]; + queryString = [NSString stringWithFormat:@"%@ WHERE `%@` %@ \"%@\"", + queryString, [fieldField titleOfSelectedItem], compareOperator, argument]; + } else { + queryString = [NSString stringWithFormat:@"%@ WHERE `%@` %@ %@", + queryString, [fieldField titleOfSelectedItem], + compareOperator, (ignoreArgument) ? @"" : argument]; } - queryString = [queryString stringByAppendingString: - [NSString stringWithFormat:@" LIMIT %d,%d", - [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]]; } - } else { - NSLog(@"ERROR: unknown compare type %@", compareType); - queryString = @""; } - + + // Add sorting details if appropriate + if ( sortField ) { + queryString = [NSString stringWithFormat:@"%@ ORDER BY `%@`", queryString, sortField]; + if ( isDesc ) + queryString = [queryString stringByAppendingString:@" DESC"]; + } + + // LIMIT if appropriate + if ( [prefs boolForKey:@"limitRows"] ) { + queryString = [NSString stringWithFormat:@"%@ LIMIT %d,%d", queryString, + [limitRowsField intValue]-1, [prefs integerForKey:@"limitRowsValue"]]; + } + theResult = [mySQLConnection queryString:queryString]; [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 + [tableContentView scrollPoint:NSMakePoint(0.0, 0.0)]; [tableContentView reloadData]; areShowingAllRows = NO; -- cgit v1.2.3