diff options
-rw-r--r-- | English.lproj/DBView.xib | 102 | ||||
-rw-r--r-- | 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 @@ <object class="NSPopUpButton" id="744029762"> <reference key="NSNextResponder" ref="1013108064"/> <int key="NSvFlags">265</int> - <string key="NSFrame">{{153, 512}, {86, 20}}</string> + <string key="NSFrame">{{153, 509}, {86, 25}}</string> <reference key="NSSuperview" ref="1013108064"/> <bool key="NSEnabled">YES</bool> <object class="NSPopUpButtonCell" key="NSCell" id="105542136"> <int key="NSCellFlags">-1539178944</int> <int key="NSCellFlags2">1024</int> - <reference key="NSSupport" ref="790379580"/> + <object class="NSFont" key="NSSupport"> + <string key="NSName">LucidaGrande</string> + <double key="NSSize">1.200000e+01</double> + <int key="NSfFlags">4883</int> + </object> <reference key="NSControlView" ref="744029762"/> - <int key="NSButtonFlags">-2038284033</int> + <int key="NSButtonFlags">-2038415105</int> <int key="NSButtonFlags2">36</int> - <reference key="NSAlternateImage" ref="790379580"/> <string key="NSAlternateContents"/> <object class="NSMutableString" key="NSKeyEquivalent"> <characters key="NS.bytes"/> </object> <int key="NSPeriodicDelay">400</int> <int key="NSPeriodicInterval">75</int> - <object class="NSMenuItem" key="NSMenuItem" id="129836593"> - <reference key="NSMenu" ref="1000166734"/> - <string key="NSTitle">is</string> - <string key="NSKeyEquiv"/> - <int key="NSKeyEquivModMask">1048576</int> - <int key="NSMnemonicLoc">2147483647</int> - <int key="NSState">1</int> - <reference key="NSOnImage" ref="685805499"/> - <reference key="NSMixedImage" ref="400866889"/> - <string key="NSAction">_popUpItemAction:</string> - <reference key="NSTarget" ref="105542136"/> - </object> + <nil key="NSMenuItem"/> <bool key="NSMenuItemRespectAlignment">YES</bool> <object class="NSMenu" key="NSMenu" id="1000166734"> <object class="NSMutableString" key="NSTitle"> @@ -2764,9 +2756,20 @@ </object> <object class="NSMutableArray" key="NSMenuItems"> <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="129836593"/> + <object class="NSMenuItem" id="129836593"> + <reference key="NSMenu" ref="1000166734"/> + <string key="NSTitle">is</string> + <string key="NSKeyEquiv"/> + <int key="NSKeyEquivModMask">1048576</int> + <int key="NSMnemonicLoc">2147483647</int> + <reference key="NSOnImage" ref="685805499"/> + <reference key="NSMixedImage" ref="400866889"/> + <string key="NSAction">_popUpItemAction:</string> + <reference key="NSTarget" ref="105542136"/> + </object> </object> </object> + <int key="NSSelectedIndex">-1</int> <int key="NSPreferredEdge">3</int> <bool key="NSUsesItemFromMenu">YES</bool> <bool key="NSAltersState">YES</bool> @@ -3086,6 +3089,22 @@ <int key="NSPeriodicInterval">75</int> </object> </object> + <object class="NSStepper" id="531095296"> + <reference key="NSNextResponder" ref="1013108064"/> + <int key="NSvFlags">265</int> + <string key="NSFrame">{{597, 511}, {15, 22}}</string> + <reference key="NSSuperview" ref="1013108064"/> + <bool key="NSEnabled">YES</bool> + <object class="NSStepperCell" key="NSCell" id="45017564"> + <int key="NSCellFlags">604896800</int> + <int key="NSCellFlags2">131072</int> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="531095296"/> + <double key="NSMaxValue">1.000000e+02</double> + <double key="NSIncrement">1.000000e+00</double> + <bool key="NSAutorepeat">YES</bool> + </object> + </object> </object> <string key="NSFrame">{{10, 7}, {638, 544}}</string> <reference key="NSSuperview" ref="714795046"/> @@ -11757,6 +11776,30 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <int key="connectionID">4685</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">limitRowsStepper</string> + <reference key="source" ref="392169872"/> + <reference key="destination" ref="531095296"/> + </object> + <int key="connectionID">4688</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">stepLimitRows:</string> + <reference key="source" ref="392169872"/> + <reference key="destination" ref="531095296"/> + </object> + <int key="connectionID">4689</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">performClick:</string> + <reference key="source" ref="983589239"/> + <reference key="destination" ref="572483755"/> + </object> + <int key="connectionID">4693</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -14962,6 +15005,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <reference ref="744029762"/> <reference ref="377771536"/> <reference ref="983589239"/> + <reference ref="531095296"/> </object> <reference key="parent" ref="624106058"/> </object> @@ -16783,6 +16827,20 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <reference key="object" ref="322691380"/> <reference key="parent" ref="983589239"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">4686</int> + <reference key="object" ref="531095296"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="45017564"/> + </object> + <reference key="parent" ref="1013108064"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">4687</int> + <reference key="object" ref="45017564"/> + <reference key="parent" ref="531095296"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -17766,6 +17824,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>4665.IBPluginDependency</string> <string>4676.IBPluginDependency</string> <string>4677.IBPluginDependency</string> + <string>4686.IBPluginDependency</string> + <string>4687.IBPluginDependency</string> <string>47.IBPluginDependency</string> <string>47.ImportedFromIB2</string> <string>495.IBAttributePlaceholdersKey</string> @@ -19269,6 +19329,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <object class="NSMutableDictionary"> <string key="NS.key.0">ToolTip</string> @@ -19280,8 +19342,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> - <string>{{299, 286}, {863, 550}}</string> - <string>{{299, 286}, {863, 550}}</string> + <string>{{92, 286}, {863, 550}}</string> + <string>{{92, 286}, {863, 550}}</string> <reference ref="9"/> <reference ref="9"/> <string>{{62, 352}, {845, 504}}</string> @@ -19694,7 +19756,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">4685</int> + <int key="maxID">4695</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> 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; |