aboutsummaryrefslogtreecommitdiffstats
path: root/TableContent.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2008-12-10 00:48:32 +0000
committerrowanbeentje <rowan@beent.je>2008-12-10 00:48:32 +0000
commit4c3b208fad0572d8d1a79bba1bd1b8147fd0f8a6 (patch)
tree88447b9f902962343acf7b8e7f515050666c4072 /TableContent.m
parentb20568e9498db7725ea887caca63837bd4337f91 (diff)
downloadsequelpro-4c3b208fad0572d8d1a79bba1bd1b8147fd0f8a6.tar.gz
sequelpro-4c3b208fad0572d8d1a79bba1bd1b8147fd0f8a6.tar.bz2
sequelpro-4c3b208fad0572d8d1a79bba1bd1b8147fd0f8a6.zip
- 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.
Diffstat (limited to 'TableContent.m')
-rw-r--r--TableContent.m298
1 files changed, 158 insertions, 140 deletions
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;