diff options
author | stuconnolly <stuart02@gmail.com> | 2009-08-21 16:27:34 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-08-21 16:27:34 +0000 |
commit | 24dc4d4ce7ff455be899c62e55c27e6e0ff03d4b (patch) | |
tree | 7c195e534abc0340ae3203f9c4c1c6f93863a31b | |
parent | abbd5a52c00538ef93f4222a3e2489ee5e4c23aa (diff) | |
download | sequelpro-24dc4d4ce7ff455be899c62e55c27e6e0ff03d4b.tar.gz sequelpro-24dc4d4ce7ff455be899c62e55c27e6e0ff03d4b.tar.bz2 sequelpro-24dc4d4ce7ff455be899c62e55c27e6e0ff03d4b.zip |
Add support for the BETWEEN operator when filtering a table's content. Implements issue #361. Note the sizing of the new controls still needs fine tuned.
-rw-r--r-- | Interfaces/English.lproj/DBView.xib | 254 | ||||
-rw-r--r-- | Source/TableContent.h | 31 | ||||
-rw-r--r-- | Source/TableContent.m | 160 |
3 files changed, 353 insertions, 92 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 48775ba0..38e8b39d 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -2,12 +2,13 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9J61</string> + <string key="IBDocument.SystemVersion">9L30</string> <string key="IBDocument.InterfaceBuilderVersion">677</string> - <string key="IBDocument.AppKitVersion">949.46</string> + <string key="IBDocument.AppKitVersion">949.54</string> <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> + <integer value="6305"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -46,7 +47,7 @@ <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string> <string key="NSWindowContentMinSize">{780, 480}</string> <object class="NSView" key="NSWindowView" id="579726586"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -2051,7 +2052,7 @@ <object class="NSTabViewItem" id="624106058"> <string key="NSIdentifier">content</string> <object class="NSView" key="NSView" id="1013108064"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder" ref="714795046"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -2596,7 +2597,6 @@ <reference ref="129836593"/> </object> </object> - <int key="NSSelectedIndex">-1</int> <int key="NSPreferredEdge">3</int> <bool key="NSUsesItemFromMenu">YES</bool> <bool key="NSAltersState">YES</bool> @@ -2676,6 +2676,144 @@ <bytes key="NSSearchFieldFlags">CAAAAA</bytes> </object> </object> + <object class="NSTextField" id="85531569"> + <reference key="NSNextResponder" ref="641645529"/> + <int key="NSvFlags">-2147483379</int> + <string key="NSFrame">{{93, 6}, {28, 14}}</string> + <reference key="NSSuperview" ref="641645529"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="194715102"> + <int key="NSCellFlags">68288064</int> + <int key="NSCellFlags2">272761856</int> + <string key="NSContents">AND</string> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="85531569"/> + <reference key="NSBackgroundColor" ref="62854682"/> + <reference key="NSTextColor" ref="454249633"/> + </object> + </object> + <object class="NSSearchField" id="722854793"> + <reference key="NSNextResponder" ref="641645529"/> + <int key="NSvFlags">-2147483378</int> + <string key="NSFrame">{{5, 4}, {83, 19}}</string> + <reference key="NSSuperview" ref="641645529"/> + <bool key="NSEnabled">YES</bool> + <object class="NSSearchFieldCell" key="NSCell" id="556901008"> + <int key="NSCellFlags">343014976</int> + <int key="NSCellFlags2">268567552</int> + <string key="NSContents"/> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="722854793"/> + <bool key="NSDrawsBackground">YES</bool> + <int key="NSTextBezelStyle">1</int> + <reference key="NSBackgroundColor" ref="480189472"/> + <reference key="NSTextColor" ref="454249633"/> + <object class="NSButtonCell" key="NSSearchButtonCell"> + <int key="NSCellFlags">130560</int> + <int key="NSCellFlags2">0</int> + <string key="NSContents">search</string> + <string key="NSAction">_searchFieldSearch:</string> + <reference key="NSTarget" ref="556901008"/> + <reference key="NSControlView" ref="722854793"/> + <int key="NSButtonFlags">138690815</int> + <int key="NSButtonFlags2">0</int> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">400</int> + <int key="NSPeriodicInterval">75</int> + </object> + <object class="NSButtonCell" key="NSCancelButtonCell"> + <int key="NSCellFlags">130560</int> + <int key="NSCellFlags2">0</int> + <string key="NSContents">clear</string> + <object class="NSMutableArray" key="NSAccessibilityOverriddenAttributes"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableDictionary"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>AXDescription</string> + <string>NSAccessibilityEncodedAttributesValueType</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>cancel</string> + <reference ref="9"/> + </object> + </object> + </object> + <string key="NSAction">_searchFieldCancel:</string> + <reference key="NSTarget" ref="556901008"/> + <reference key="NSControlView" ref="722854793"/> + <int key="NSButtonFlags">138690815</int> + <int key="NSButtonFlags2">0</int> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">400</int> + <int key="NSPeriodicInterval">75</int> + </object> + <int key="NSMaximumRecents">255</int> + </object> + </object> + <object class="NSSearchField" id="538700903"> + <reference key="NSNextResponder" ref="641645529"/> + <int key="NSvFlags">-2147483381</int> + <string key="NSFrame">{{127, 4}, {83, 19}}</string> + <reference key="NSSuperview" ref="641645529"/> + <bool key="NSEnabled">YES</bool> + <object class="NSSearchFieldCell" key="NSCell" id="564763515"> + <int key="NSCellFlags">343014976</int> + <int key="NSCellFlags2">268567552</int> + <string key="NSContents"/> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="538700903"/> + <bool key="NSDrawsBackground">YES</bool> + <int key="NSTextBezelStyle">1</int> + <reference key="NSBackgroundColor" ref="480189472"/> + <reference key="NSTextColor" ref="454249633"/> + <object class="NSButtonCell" key="NSSearchButtonCell"> + <int key="NSCellFlags">130560</int> + <int key="NSCellFlags2">0</int> + <string key="NSContents">search</string> + <string key="NSAction">_searchFieldSearch:</string> + <reference key="NSTarget" ref="564763515"/> + <reference key="NSControlView" ref="538700903"/> + <int key="NSButtonFlags">138690815</int> + <int key="NSButtonFlags2">0</int> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">400</int> + <int key="NSPeriodicInterval">75</int> + </object> + <object class="NSButtonCell" key="NSCancelButtonCell"> + <int key="NSCellFlags">130560</int> + <int key="NSCellFlags2">0</int> + <string key="NSContents">clear</string> + <object class="NSMutableArray" key="NSAccessibilityOverriddenAttributes"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableDictionary"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSMutableArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>AXDescription</string> + <string>NSAccessibilityEncodedAttributesValueType</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>cancel</string> + <reference ref="9"/> + </object> + </object> + </object> + <string key="NSAction">_searchFieldCancel:</string> + <reference key="NSTarget" ref="564763515"/> + <reference key="NSControlView" ref="538700903"/> + <int key="NSButtonFlags">138690815</int> + <int key="NSButtonFlags2">0</int> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">400</int> + <int key="NSPeriodicInterval">75</int> + </object> + <int key="NSMaximumRecents">255</int> + </object> + </object> </object> <string key="NSFrame">{{264, 0}, {211, 27}}</string> <reference key="NSSuperview" ref="231622333"/> @@ -2689,6 +2827,7 @@ </object> </object> <string key="NSFrame">{{10, 7}, {700, 544}}</string> + <reference key="NSSuperview" ref="714795046"/> </object> <string key="NSLabel">Content</string> <reference key="NSColor" ref="62854682"/> @@ -2697,7 +2836,7 @@ <object class="NSTabViewItem" id="105987292"> <string key="NSIdentifier">customQuery</string> <object class="NSView" key="NSView" id="746504912"> - <reference key="NSNextResponder" ref="714795046"/> + <nil key="NSNextResponder"/> <int key="NSvFlags">256</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -3489,7 +3628,6 @@ </object> </object> <string key="NSFrame">{{10, 7}, {700, 544}}</string> - <reference key="NSSuperview" ref="714795046"/> </object> <string key="NSLabel">Custom Query</string> <reference key="NSColor" ref="62854682"/> @@ -4529,14 +4667,14 @@ <reference key="NSTabView" ref="714795046"/> </object> </object> - <reference key="NSSelectedTabViewItem" ref="105987292"/> + <reference key="NSSelectedTabViewItem" ref="624106058"/> <reference key="NSFont" ref="26"/> <int key="NSTvFlags">134217731</int> <bool key="NSAllowTruncatedLabels">YES</bool> <bool key="NSDrawsBackground">YES</bool> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="746504912"/> + <reference ref="1013108064"/> </object> </object> </object> @@ -4552,6 +4690,7 @@ </object> </object> <string key="NSFrameSize">{944, 550}</string> + <reference key="NSSuperview"/> </object> <string key="NSScreenRect">{{0, 0}, {1920, 1178}}</string> <string key="NSMinSize">{780, 502}</string> @@ -9447,6 +9586,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string key="NSFrame">{{1, 1}, {198, 107}}</string> <reference key="NSSuperview" ref="27548452"/> + <reference key="NSNextKeyView" ref="29661959"/> <reference key="NSDocView" ref="29661959"/> <reference key="NSBGColor" ref="1024678221"/> <int key="NScvFlags">4</int> @@ -9474,6 +9614,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string key="NSFrame">{{20, 20}, {211, 109}}</string> <reference key="NSSuperview" ref="774289419"/> + <reference key="NSNextKeyView" ref="383807970"/> <int key="NSsFlags">18</int> <reference key="NSVScroller" ref="438736883"/> <reference key="NSHScroller" ref="721548430"/> @@ -14991,6 +15132,30 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <int key="connectionID">6357</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">betweenTextField</string> + <reference key="source" ref="392169872"/> + <reference key="destination" ref="85531569"/> + </object> + <int key="connectionID">6368</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">firstBetweenField</string> + <reference key="source" ref="392169872"/> + <reference key="destination" ref="722854793"/> + </object> + <int key="connectionID">6373</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">secondBetweenField</string> + <reference key="source" ref="392169872"/> + <reference key="destination" ref="538700903"/> + </object> + <int key="connectionID">6374</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -20928,6 +21093,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <object class="NSMutableArray" key="children"> <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="377771536"/> + <reference ref="85531569"/> + <reference ref="722854793"/> + <reference ref="538700903"/> </object> <reference key="parent" ref="231622333"/> </object> @@ -21168,6 +21336,48 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <reference key="object" ref="257935364"/> <reference key="parent" ref="953478607"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">6364</int> + <reference key="object" ref="85531569"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="194715102"/> + </object> + <reference key="parent" ref="641645529"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">6365</int> + <reference key="object" ref="194715102"/> + <reference key="parent" ref="85531569"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">6369</int> + <reference key="object" ref="722854793"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="556901008"/> + </object> + <reference key="parent" ref="641645529"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">6370</int> + <reference key="object" ref="556901008"/> + <reference key="parent" ref="722854793"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">6371</int> + <reference key="object" ref="538700903"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="564763515"/> + </object> + <reference key="parent" ref="641645529"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">6372</int> + <reference key="object" ref="564763515"/> + <reference key="parent" ref="538700903"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -22433,6 +22643,12 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>6356.IBPluginDependency</string> <string>6358.IBPluginDependency</string> <string>6359.IBPluginDependency</string> + <string>6364.IBPluginDependency</string> + <string>6365.IBPluginDependency</string> + <string>6369.IBPluginDependency</string> + <string>6370.IBPluginDependency</string> + <string>6371.IBPluginDependency</string> + <string>6372.IBPluginDependency</string> <string>654.IBPluginDependency</string> <string>654.ImportedFromIB2</string> <string>655.IBPluginDependency</string> @@ -22895,7 +23111,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> - <string>{{618, 746}, {92, 20}}</string> + <string>{{710, 843}, {89, 20}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{535, 926}, {92, 23}}</string> @@ -23461,9 +23677,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{219, 267}, {944, 550}}</string> + <string>{{280, 178}, {944, 550}}</string> <boolean value="NO"/> - <string>{{219, 267}, {944, 550}}</string> + <string>{{280, 178}, {944, 550}}</string> <reference ref="9"/> <reference ref="9"/> <string>{{62, 352}, {845, 504}}</string> @@ -24253,6 +24469,12 @@ aGUgYWN0aXZlIHNlbGVjdGlvbiAo4oyl4oyYUik</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> + <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"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> @@ -24472,7 +24694,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> </object> </object> <nil key="sourceID"/> - <int key="maxID">6359</int> + <int key="maxID">6374</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -25147,16 +25369,19 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <bool key="EncodedWithXMLCoder">YES</bool> <string>addButton</string> <string>argumentField</string> + <string>betweenTextField</string> <string>compareField</string> <string>copyButton</string> <string>countText</string> <string>fieldField</string> <string>filterButton</string> + <string>firstBetweenField</string> <string>limitRowsButton</string> <string>limitRowsField</string> <string>limitRowsStepper</string> <string>multipleLineEditingButton</string> <string>removeButton</string> + <string>secondBetweenField</string> <string>spHistoryControllerInstance</string> <string>tableContentView</string> <string>tableDataInstance</string> @@ -25179,6 +25404,9 @@ Y2hhbmdlIHRoZSBvcmRlcg</string> <string>id</string> <string>id</string> <string>id</string> + <string>id</string> + <string>id</string> + <string>id</string> <string>SPHistoryController</string> <string>CMCopyTable</string> <string>id</string> diff --git a/Source/TableContent.h b/Source/TableContent.h index e389c8df..03aaeafa 100644 --- a/Source/TableContent.h +++ b/Source/TableContent.h @@ -52,6 +52,9 @@ IBOutlet id limitRowsField; IBOutlet id limitRowsButton; IBOutlet id limitRowsStepper; + IBOutlet id firstBetweenField; + IBOutlet id secondBetweenField; + IBOutlet id betweenTextField; MCPConnection *mySQLConnection; @@ -85,17 +88,16 @@ - (NSString *) usedQuery; - (void) setUsedQuery:(NSString *)query; -//edit methods +// Edit methods - (IBAction)addRow:(id)sender; - (IBAction)copyRow:(id)sender; - (IBAction)removeRow:(id)sender; - -//getter methods +// Getter methods - (NSArray *)currentResult; - (NSArray *)currentDataResult; -//additional methods +// Additional methods - (void)setConnection:(MCPConnection *)theConnection; - (void)clickLinkArrow:(SPTextAndLinkCell *)theArrowCell; - (IBAction)setCompareTypes:(id)sender; @@ -125,25 +127,4 @@ - (void) storeCurrentDetailsForRestoration; - (void) clearDetailsToRestore; -//tableView datasource methods -- (int)numberOfRowsInTableView:(NSTableView *)aTableView; -- (id)tableView:(CMCopyTable *)aTableView -objectValueForTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex; -- (void)tableView:(NSTableView *)aTableView - setObjectValue:(id)anObject - forTableColumn:(NSTableColumn *)aTableColumn - row:(int)rowIndex; - -//tableView delegate methods -- (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)tableColumn; -- (void)tableViewSelectionDidChange:(NSNotification *)aNotification; -- (void)tableViewColumnDidResize:(NSNotification *)aNotification; -- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; -- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard; -- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command; - -//textView delegate methods -// - (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector; - @end diff --git a/Source/TableContent.m b/Source/TableContent.m index c504d759..9437d42b 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -147,10 +147,20 @@ [compareField setEnabled:NO]; [compareField removeAllItems]; [compareField addItemWithTitle:NSLocalizedString(@"is", @"popup menuitem for field IS value")]; + [argumentField setHidden:NO]; [argumentField setEnabled:NO]; + [firstBetweenField setEnabled:NO]; + [secondBetweenField setEnabled:NO]; + [firstBetweenField setStringValue:@""]; + [secondBetweenField setStringValue:@""]; [argumentField setStringValue:@""]; [filterButton setEnabled:NO]; - + + // Hide BETWEEN operator controls + [firstBetweenField setHidden:YES]; + [secondBetweenField setHidden:YES]; + [betweenTextField setHidden:YES]; + // Empty and disable the limit field [limitRowsField setStringValue:@""]; [limitRowsField setEnabled:NO]; @@ -400,6 +410,7 @@ // Add a filter string if appropriate filterString = [self tableFilterString]; + if (filterString) { [queryString appendFormat:@" WHERE %@", filterString]; isFiltered = YES; @@ -498,24 +509,33 @@ * ready to be dropped into a WHERE clause, or nil if no filtering * is active. */ -- (NSString *) tableFilterString +- (NSString *)tableFilterString { BOOL doQuote = YES; BOOL ignoreArgument = NO; - int i; - int tag = [[compareField selectedItem] tag]; NSString *filterString; NSString *compareOperator = @""; + int tag = [[compareField selectedItem] tag]; + + // Filter arguments NSMutableString *argument = [[NSMutableString alloc] initWithString:[argumentField stringValue]]; + NSString *firstBetweenArgument = [firstBetweenField stringValue]; + NSString *secondBetweenArgument = [secondBetweenField stringValue]; // If the filter field is empty and the selected filter is not looking // for NULLs or NOT NULLs, then no filtering is required - return nil. - if (([argument length] == 0) - && (![[[compareField selectedItem] title] hasSuffix:@"NULL"])) - { + if (([argument length] == 0) && (![[[compareField selectedItem] title] hasSuffix:@"NULL"]) && (![[[compareField selectedItem] title] isEqualToString:@"BETWEEN"])) { [argument release]; return nil; } + + // If we are using the BETWEEN operator and either of the argument fields are empty return nil. + if ([[[compareField selectedItem] title] isEqualToString:@"BETWEEN"]) { + if (([firstBetweenArgument length] == 0) || ([secondBetweenArgument length] == 0)) { + NSLog(@"reached"); + return nil; + } + } // Construct the filter string if (![compareType isEqualToString:@""]) { @@ -542,19 +562,25 @@ [argument setString:[[@"(" stringByAppendingString:argument] stringByAppendingString:@")"]]; break; case 5: + compareOperator = @"BETWEEN"; + doQuote = NO; + [argument setString:[NSString stringWithFormat:@"'%@' AND '%@'", [firstBetweenField stringValue], [secondBetweenField stringValue]]]; + break; + case 6: compareOperator = @"IS NULL"; doQuote = NO; ignoreArgument = YES; break; - case 6: + case 7: compareOperator = @"IS NOT NULL"; doQuote = NO; ignoreArgument = YES; break; } - } else if ( [compareType isEqualToString:@"number"] ) { - //number comparision - switch ( tag ) { + } + else if ([compareType isEqualToString:@"number"]) { + // Numeric comparision + switch (tag) { case 0: compareOperator = @"="; break; @@ -584,19 +610,25 @@ ignoreArgument = YES; break; case 8: + compareOperator = @"BETWEEN"; + doQuote = NO; + [argument setString:[NSString stringWithFormat:@"'%@' AND '%@'", [firstBetweenField stringValue], [secondBetweenField stringValue]]]; + break; + case 9: compareOperator = @"IS NULL"; doQuote = NO; ignoreArgument = YES; break; - case 9: + case 10: compareOperator = @"IS NOT NULL"; doQuote = NO; ignoreArgument = YES; break; } - } else if ( [compareType isEqualToString:@"date"] ) { - //date comparision - switch ( tag ) { + } + else if ([compareType isEqualToString:@"date"]) { + // Date comparision + switch (tag) { case 0: compareOperator = @"="; break; @@ -616,37 +648,45 @@ compareOperator = @"<="; break; case 6: + compareOperator = @"BETWEEN"; + doQuote = NO; + [argument setString:[NSString stringWithFormat:@"'%@' AND '%@'", [firstBetweenField stringValue], [secondBetweenField stringValue]]]; + break; + case 7: compareOperator = @"IS NULL"; doQuote = NO; ignoreArgument = YES; break; - case 7: + case 8: compareOperator = @"IS NOT NULL"; doQuote = NO; ignoreArgument = YES; break; } - } else { + } + else { doQuote = NO; ignoreArgument = YES; - NSLog(@"ERROR: unknown compare type %@", compareType); + NSLog(@"ERROR: unknown comparison type %@", compareType); } if (doQuote) { - //escape special characters - for ( i = 0 ; i < [argument length] ; i++ ) { - if ( [argument characterAtIndex:i] == '\\' ) { + int i; + + // Escape special characters + for (i = 0 ; i < [argument length]; i++) { + if ([argument characterAtIndex:i] == '\\') { [argument insertString:@"\\" atIndex:i]; i++; } } + [argument setString:[mySQLConnection prepareString:argument]]; - filterString = [NSString stringWithFormat:@"%@ %@ \"%@\"", - [[fieldField titleOfSelectedItem] backtickQuotedString], compareOperator, argument]; - } else { - filterString = [NSString stringWithFormat:@"%@ %@ %@", - [[fieldField titleOfSelectedItem] backtickQuotedString], - compareOperator, (ignoreArgument) ? @"" : argument]; + + filterString = [NSString stringWithFormat:@"%@ %@ \"%@\"", [[fieldField titleOfSelectedItem] backtickQuotedString], compareOperator, argument]; + } + else { + filterString = [NSString stringWithFormat:@"%@ %@ %@", [[fieldField titleOfSelectedItem] backtickQuotedString], compareOperator, (ignoreArgument) ? @"" : argument]; } } @@ -726,22 +766,19 @@ */ - (IBAction)filterTable:(id)sender { - // Check whether a save of the current row is required. - if ( ![self saveRowOnDeselect] ) { - return; - } + if (![self saveRowOnDeselect]) return; // Update history [spHistoryControllerInstance updateHistoryEntries]; // Update negative limits - if ( [limitRowsField intValue] <= 0 ) { + if ([limitRowsField intValue] <= 0) { [limitRowsField setStringValue:@"1"]; } // If limitRowsField > number of total table rows show the last limitRowsValue rows - if ( [prefs boolForKey:@"LimitResults"] && [limitRowsField intValue] >= maxNumRows ) { + if ([prefs boolForKey:@"LimitResults"] && [limitRowsField intValue] >= maxNumRows) { int newLimit = maxNumRows - [prefs integerForKey:@"LimitResultsValue"]; [limitRowsField setStringValue:[[NSNumber numberWithInt:(newLimit<1)?1:newLimit] stringValue]]; } @@ -759,7 +796,24 @@ */ - (IBAction)toggleFilterField:(id)sender { - // If the user is filtering for NULLs then disabled the filter field, otherwise enable it. + NSString *filter = [[compareField selectedItem] title]; + + if ([filter isEqualToString:@"BETWEEN"]) { + [argumentField setHidden:YES]; + [betweenTextField setHidden:NO]; + [firstBetweenField setHidden:NO]; + [secondBetweenField setHidden:NO]; + [firstBetweenField setEnabled:YES]; + [secondBetweenField setEnabled:YES]; + } + else { + [argumentField setHidden:NO]; + [betweenTextField setHidden:YES]; + [firstBetweenField setHidden:YES]; + [secondBetweenField setHidden:YES]; + } + + // If the user is filtering for NULLs then disable the filter field, otherwise enable it. [argumentField setEnabled:(![[[compareField selectedItem] title] hasSuffix:@"NULL"])]; } @@ -808,10 +862,10 @@ [tableContentView editColumn:0 row:[tableContentView numberOfRows]-1 withEvent:nil select:YES]; } -- (IBAction)copyRow:(id)sender -/* - copies a row of the table-array and goes into edit mode +/** + * Copies a row of the table-array and goes into edit mode */ +- (IBAction)copyRow:(id)sender { NSMutableArray *tempRow; MCPResult *queryResult; @@ -1074,10 +1128,10 @@ */ - (IBAction)setCompareTypes:(id)sender { - 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 *numberTypes = [NSArray arrayWithObjects:@"=", @"≠", @">", @"<", @"≥", @"≤", @"IN", @"LIKE", nil]; - NSArray *dateTypes = [NSArray arrayWithObjects:NSLocalizedString(@"is", @"popup menuitem for field IS value"), NSLocalizedString(@"is not", @"popup menuitem for field IS NOT value"), NSLocalizedString(@"is after", @"popup menuitem for field AFTER DATE value"), NSLocalizedString(@"is before", @"popup menuitem for field BEFORE DATE value"), NSLocalizedString(@"is after or equal to", @"popup menuitem for field AFTER OR EQUAL TO value"), NSLocalizedString(@"is before or equal to", @"popup menuitem for field BEFORE OR EQUAL TO value"), nil]; - NSString *fieldTypeGrouping = [NSString stringWithString:[[tableDataInstance columnWithName:[[fieldField selectedItem] title]] objectForKey:@"typegrouping"]]; + 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", @"BETWEEN", nil]; + NSArray *numberTypes = [NSArray arrayWithObjects:@"=", @"≠", @">", @"<", @"≥", @"≤", @"IN", @"LIKE", @"BETWEEN", nil]; + NSArray *dateTypes = [NSArray arrayWithObjects:NSLocalizedString(@"IS", @"popup menuitem for field IS value"), NSLocalizedString(@"IS NOT", @"popup menuitem for field IS NOT value"), NSLocalizedString(@"is after", @"popup menuitem for field AFTER DATE value"), NSLocalizedString(@"is before", @"popup menuitem for field BEFORE DATE value"), NSLocalizedString(@"is after or equal to", @"popup menuitem for field AFTER OR EQUAL TO value"), NSLocalizedString(@"is before or equal to", @"popup menuitem for field BEFORE OR EQUAL TO value"), @"BETWEEN", nil]; + NSString *fieldTypeGrouping = [NSString stringWithString:[[tableDataInstance columnWithName:[[fieldField selectedItem] title]] objectForKey:@"typegrouping"]]; int i; @@ -2011,18 +2065,18 @@ - (void)tableViewSelectionDidChange:(NSNotification *)aNotification { // Check our notification object is our table content view - if ([aNotification object] != tableContentView) - return; + if ([aNotification object] != tableContentView) return; // If we are editing a row, attempt to save that row - if saving failed, reselect the edit row. - if ( isEditingRow && [tableContentView selectedRow] != currentlyEditingRow && ![self saveRowOnDeselect] ) return; + if (isEditingRow && [tableContentView selectedRow] != currentlyEditingRow && ![self saveRowOnDeselect]) return; // Update the row selection count // and update the status of the delete/duplicate buttons - if ( [tableContentView numberOfSelectedRows] > 0 ) { + if ([tableContentView numberOfSelectedRows] > 0) { [copyButton setEnabled:YES]; [removeButton setEnabled:YES]; - } else { + } + else { [copyButton setEnabled:NO]; [removeButton setEnabled:NO]; } @@ -2144,15 +2198,12 @@ return YES; } -- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows - toPasteboard:(NSPasteboard*)pboard -/* - enable drag from tableview +/** + * Enable drag from tableview */ +- (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard { - if ( tableView == tableContentView ) - { - + if (tableView == tableContentView) { NSString *tmp; // By holding ⌘, ⇧, or/and ⌥ copies selected rows as SQL INSERTS @@ -2173,6 +2224,7 @@ return YES; } } + return NO; } @@ -2186,7 +2238,7 @@ - (float)splitView:(NSSplitView *)sender constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(int)offset { - return (proposedMax - 150); + return (proposedMax - 180); } - (float)splitView:(NSSplitView *)sender constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset |