aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPCustomQuery.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/SPCustomQuery.m')
-rw-r--r--Source/SPCustomQuery.m38
1 files changed, 26 insertions, 12 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index f69db3b7..f7f31088 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -25,10 +25,10 @@
#import "SPCustomQuery.h"
#import "SPSQLParser.h"
-#import "SPMySQL.h"
#ifndef SP_REFACTOR /* headers */
#import "SPGrowlController.h"
#endif
+#import <SPMySQL/SPMySQL.h>
#import "SPDataCellFormatter.h"
#import "SPDatabaseDocument.h"
#import "SPTablesList.h"
@@ -44,8 +44,10 @@
#import "SPAlertSheets.h"
#import "SPCopyTable.h"
#import "SPGeometryDataView.h"
+#ifndef SP_REFACTOR /* headers */
#import "SPAppController.h"
#import "SPBundleHTMLOutputController.h"
+#endif
#include <pthread.h>
#ifndef SP_REFACTOR /* headers */
@@ -55,7 +57,7 @@
@interface SPCustomQuery (PrivateAPI)
- (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column;
-- (id)_convertResultDataValueToDisplayableRepresentation:(id)value whilePreservingNULLs:(BOOL)preserveNULLs;
+- (id)_convertResultDataValueToDisplayableRepresentation:(id)value whilePreservingNULLs:(BOOL)preserveNULLs truncateDataFields:(BOOL)truncate;
@end
@@ -793,6 +795,7 @@
// if(!queriesSeparatedByDelimiter) // TODO: How to combine queries delimited by DELIMITER?
usedQuery = [[NSString stringWithString:[tempQueries componentsJoinedByString:@";\n"]] retain];
+ if (lastExecutedQuery) [lastExecutedQuery release];
lastExecutedQuery = [[tempQueries lastObject] retain];
// Perform empty query if no query is given
@@ -858,7 +861,9 @@
];
}
}
+#ifndef SP_REFACTOR
[[affectedRowsText onMainThread] setStringValue:statusString];
+#endif
// Restore automatic query retries
[mySQLConnection setRetryQueriesOnConnectionFailure:YES];
@@ -1289,9 +1294,11 @@
// If errors occur, display them
if ( [mySQLConnection lastQueryWasCancelled] || ([errorsString length] && !queryIsTableSorter)) {
+#ifndef SP_REFACTOR
// set the error text
[errorText setString:[errorsString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
[[errorTextScrollView verticalScroller] setFloatValue:1.0f];
+#endif
// try to select the line x of the first error if error message with ID 1064 contains "at line x"
// by capturing the last number of the error string
@@ -1365,6 +1372,9 @@
[queryInfoButton setState:NSOffState];
[self toggleQueryInfoPaneCollapse:queryInfoButton];
}
+#else
+ if ( [errorsString length] > 0 )
+ NSRunAlertPanel(LOCAL(@"Query Error"), @"%@", LOCAL(@"OK"), nil, nil, errorsString);
#endif
}
@@ -1452,7 +1462,7 @@
*/
- (NSArray *)currentResult
{
- return [self currentDataResultWithNULLs:NO];
+ return [self currentDataResultWithNULLs:NO truncateDataFields:YES];
}
/**
@@ -1461,8 +1471,9 @@
*
* @param includeNULLs Indicates whether to include NULLs as a native type
* or use the user's NULL string representation preference.
+ * @param truncate Indicates whether to truncate data fields for display purposes.
*/
-- (NSArray *)currentDataResultWithNULLs:(BOOL)includeNULLs
+- (NSArray *)currentDataResultWithNULLs:(BOOL)includeNULLs truncateDataFields:(BOOL)truncate
{
NSInteger i;
id tableColumn;
@@ -1485,7 +1496,7 @@
while ( (tableColumn = [enumerator nextObject]) ) {
id value = [self _resultDataItemAtRow:i columnIndex:[[tableColumn identifier] integerValue]];
- [tempRow addObject:[self _convertResultDataValueToDisplayableRepresentation:value whilePreservingNULLs:YES]];
+ [tempRow addObject:[self _convertResultDataValueToDisplayableRepresentation:value whilePreservingNULLs:includeNULLs truncateDataFields:truncate]];
}
[currentResult addObject:[NSArray arrayWithArray:tempRow]];
}
@@ -1520,11 +1531,11 @@
[autouppercaseKeywordsMenuItem setState:(YES?NSOnState:NSOffState)];
#endif
+#ifndef SP_REFACTOR
if ( [[SPQueryController sharedQueryController] historyForFileURL:[tableDocumentInstance fileURL]] )
[self performSelectorOnMainThread:@selector(historyItemsHaveBeenUpdated:) withObject:self waitUntilDone:YES];
// Populate query favorites
-#ifndef SP_REFACTOR
[self queryFavoritesHaveBeenUpdated:nil];
#endif
@@ -2044,7 +2055,7 @@
{
if (aTableView == customQueryView) {
- return [self _convertResultDataValueToDisplayableRepresentation:[self _resultDataItemAtRow:rowIndex columnIndex:[[tableColumn identifier] integerValue]] whilePreservingNULLs:NO];
+ return [self _convertResultDataValueToDisplayableRepresentation:[self _resultDataItemAtRow:rowIndex columnIndex:[[tableColumn identifier] integerValue]] whilePreservingNULLs:NO truncateDataFields:YES];
}
return @"";
@@ -2514,15 +2525,15 @@
// Retrieve the original index of the column from the identifier
NSInteger columnIndex = [[[[aNotification userInfo] objectForKey:@"NSTableColumn"] identifier] integerValue];
NSDictionary *columnDefinition = NSArrayObjectAtIndex(cqColumnDefinition, columnIndex);
+ NSString *table = [columnDefinition objectForKey:@"org_table"];
+ NSString *col = [columnDefinition objectForKey:@"org_name"];
// Don't save if the column doesn't map to an underlying SQL field
- if (![columnDefinition objectForKey:@"org_name"] || ![(NSString *)[columnDefinition objectForKey:@"org_name"] length])
+ if (!table || ![table length] || !col || ![col length])
return;
NSMutableDictionary *tableColumnWidths;
NSString *host_db = [NSString stringWithFormat:@"%@@%@", [columnDefinition objectForKey:@"db"], [tableDocumentInstance host]];
- NSString *table = [columnDefinition objectForKey:@"org_table"];
- NSString *col = [columnDefinition objectForKey:@"org_name"];
// Retrieve or instantiate the tableColumnWidths object
#ifndef SP_REFACTOR
@@ -3689,6 +3700,7 @@
if ((self = [super init])) {
usedQuery = [[NSString stringWithString:@""] retain];
+ lastExecutedQuery = nil;
fieldIDQueryString = nil;
sortField = nil;
isDesc = NO;
@@ -3988,13 +4000,14 @@
* @param value The value to convert
* @param preserveNULLs Whether or not NULLs should be preserved or converted to the
* user's NULL placeholder preference.
+ * @param truncate Whether or not data fields should be truncates for display purposes.
*
* @return The converted value
*/
-- (id)_convertResultDataValueToDisplayableRepresentation:(id)value whilePreservingNULLs:(BOOL)preserveNULLs
+- (id)_convertResultDataValueToDisplayableRepresentation:(id)value whilePreservingNULLs:(BOOL)preserveNULLs truncateDataFields:(BOOL)truncate
{
if ([value isKindOfClass:[NSData class]]) {
- value = [value shortStringRepresentationUsingEncoding:[mySQLConnection stringEncoding]];
+ value = truncate ? [value shortStringRepresentationUsingEncoding:[mySQLConnection stringEncoding]] : [value stringRepresentationUsingEncoding:[mySQLConnection stringEncoding]];
}
if ([value isNSNull] && !preserveNULLs) {
@@ -4023,6 +4036,7 @@
[self clearQueryLoadTimer];
[usedQuery release];
+ [lastExecutedQuery release];
[resultData release];
[favoritesManager release];