aboutsummaryrefslogtreecommitdiffstats
path: root/TableContent.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2008-12-10 01:50:52 +0000
committerrowanbeentje <rowan@beent.je>2008-12-10 01:50:52 +0000
commitfeede753b44f9253b58f042e2281dcb1e6bb0caa (patch)
treea78d5db85b4777bc015f69a6c5d0cfbbc388cd57 /TableContent.m
parent5a57ab32d28a9c2b3538a73f2fd965558a39abe1 (diff)
downloadsequelpro-feede753b44f9253b58f042e2281dcb1e6bb0caa.tar.gz
sequelpro-feede753b44f9253b58f042e2281dcb1e6bb0caa.tar.bz2
sequelpro-feede753b44f9253b58f042e2281dcb1e6bb0caa.zip
- Merge in trunk fixes and improvements up to r254release-0.9.3
- Update Info.plist revision numbers to 254
Diffstat (limited to 'TableContent.m')
-rw-r--r--TableContent.m83
1 files changed, 62 insertions, 21 deletions
diff --git a/TableContent.m b/TableContent.m
index 1e5e898a..c3238a3c 100644
--- a/TableContent.m
+++ b/TableContent.m
@@ -420,7 +420,8 @@
NSString *queryString;
int i;
- if ([argument length] == 0) {
+ // 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"])) {
[argument release];
[self showAll:sender];
return;
@@ -430,6 +431,7 @@
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:self];
BOOL doQuote = YES;
+ BOOL ignoreArgument = NO;
if ( ![compareType isEqualToString:@""] ) {
if ( [compareType isEqualToString:@"string"] ) {
@@ -454,6 +456,16 @@
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
@@ -481,6 +493,16 @@
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
@@ -503,12 +525,19 @@
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;
}
}
- // queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@` WHERE `%@` %@ '%@'",
- // [self fieldListForQuery], selectedTable, [fieldField titleOfSelectedItem],
- // compareOperator, argument];
if (doQuote) {
//escape special characters
for ( i = 0 ; i < [argument length] ; i++ ) {
@@ -524,7 +553,7 @@
} else {
queryString = [NSString stringWithFormat:@"SELECT %@ FROM `%@` WHERE `%@` %@ %@",
[self fieldListForQuery], selectedTable, [fieldField titleOfSelectedItem],
- compareOperator, argument];
+ compareOperator, (ignoreArgument) ? @"" : argument];
}
if ( sortField ) {
// queryString = [queryString stringByAppendingString:[NSString stringWithFormat:@" ORDER BY `%@`", sortField]];
@@ -544,7 +573,7 @@
NSLog(@"ERROR: unknown compare type %@", compareType);
queryString = @"";
}
-
+
theResult = [mySQLConnection queryString:queryString];
[filteredResult setArray:[self fetchResultAsArray:theResult]];
@@ -570,6 +599,15 @@
[countText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"%d rows in table", @"text showing how many rows are in the result"), numRows]];
}
+/**
+ * Enables or disables the filter input field based on the selected filter type.
+ */
+- (IBAction)toggleFilterField:(id)sender
+{
+ // If the user is filtering for NULLs then disabled the filter field, otherwise enable it.
+ [argumentField setEnabled:(![[[compareField selectedItem] title] hasSuffix:@"NULL"])];
+}
+
//edit methods
- (IBAction)addRow:(id)sender
@@ -921,28 +959,24 @@
}
}
-- (IBAction)setCompareTypes:(id)sender
-/*
- sets the compare types for the filter and the appropriate formatter for the textField
+/**
+ * Sets the compare types for the filter and the appropriate formatter for the textField
*/
+- (IBAction)setCompareTypes:(id)sender
{
NSArray *stringFields = [NSArray arrayWithObjects:@"varstring", @"string", @"tinyblob", @"blob", @"mediumblob", @"longblob", @"set", @"enum", nil];
- NSArray *stringTypes = [NSArray arrayWithObjects:NSLocalizedString(@"is", @"popup menuitem for field IS value"), NSLocalizedString(@"is not", @"popup menuitem for field IS NOT value"), NSLocalizedString(@"contains", @"popup menuitem for field CONTAINS value"), NSLocalizedString(@"contains not", @"popup menuitem for field CONTAINS NOT value"), @"IN", nil];
+ NSArray *stringTypes = [NSArray arrayWithObjects:NSLocalizedString(@"is", @"popup menuitem for field IS value"), NSLocalizedString(@"is not", @"popup menuitem for field IS NOT value"), NSLocalizedString(@"contains", @"popup menuitem for field CONTAINS value"), NSLocalizedString(@"contains not", @"popup menuitem for field CONTAINS NOT value"), @"IN", nil];
NSArray *numberFields = [NSArray arrayWithObjects:@"tiny", @"short", @"long", @"int24", @"longlong", @"decimal", @"float", @"double", nil];
- NSArray *numberTypes = [NSArray arrayWithObjects:@"=", @"≠", @">", @"<", @"≥", @"≤", @"IN", nil];
- NSArray *dateFields = [NSArray arrayWithObjects:@"timestamp", @"date", @"time", @"datetime", @"year", nil];
- NSArray *dateTypes = [NSArray arrayWithObjects:NSLocalizedString(@"is", @"popup menuitem for field IS value"), NSLocalizedString(@"is not", @"popup menuitem for field IS NOT value"), NSLocalizedString(@"older than", @"popup menuitem for field OLDER THAN value"), NSLocalizedString(@"younger than", @"popup menuitem for field YOUNGER THAN value"), NSLocalizedString(@"older than or equal to", @"popup menuitem for field OLDER THAN OR EQUAL TO value"), NSLocalizedString(@"younger than or equal to", @"popup menuitem for field YOUNGER THAN OR EQUAL TO value"), nil];
- NSString *fieldType = [NSString stringWithString:[fieldTypes objectAtIndex:[[fieldField selectedItem] tag]]];
- // NSNumberFormatter *numberFormatter;
- int i;
+ NSArray *numberTypes = [NSArray arrayWithObjects:@"=", @"≠", @">", @"<", @"≥", @"≤", @"IN", nil];
+ NSArray *dateFields = [NSArray arrayWithObjects:@"timestamp", @"date", @"time", @"datetime", @"year", nil];
+ NSArray *dateTypes = [NSArray arrayWithObjects:NSLocalizedString(@"is", @"popup menuitem for field IS value"), NSLocalizedString(@"is not", @"popup menuitem for field IS NOT value"), NSLocalizedString(@"older than", @"popup menuitem for field OLDER THAN value"), NSLocalizedString(@"younger than", @"popup menuitem for field YOUNGER THAN value"), NSLocalizedString(@"older than or equal to", @"popup menuitem for field OLDER THAN OR EQUAL TO value"), NSLocalizedString(@"younger than or equal to", @"popup menuitem for field YOUNGER THAN OR EQUAL TO value"), nil];
+ NSString *fieldType = [NSString stringWithString:[fieldTypes objectAtIndex:[[fieldField selectedItem] tag]]];
- // numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
- // [numberFormatter setFormat:@"0.####################"];
+ int i;
[compareField removeAllItems];
- // [argumentField setStringValue:@""];
- //why do we get "string" for enum fields? (error in framework?)
+ // Why do we get "string" for enum fields? (error in framework?)
if ( [stringFields containsObject:fieldType] ) {
[compareField addItemsWithTitles:stringTypes];
compareType = @"string";
@@ -976,10 +1010,17 @@
NSLog(@"ERROR: unknown type for comparision: %@", fieldType);
}
+ // Add IS NULL and IS NOT NULL as they should always be available
+ [compareField addItemWithTitle:@"IS NULL"];
+ [compareField addItemWithTitle:@"IS NOT NULL"];
+
for ( i = 0 ; i < [compareField numberOfItems] ; i++ ) {
[[compareField itemAtIndex:i] setTag:i];
}
-
+
+ // Update the argumentField enabled state
+ [self toggleFilterField:self];
+
// set focus on argumentField
[argumentField selectText:self];
}