aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/CMCopyTable.m5
-rw-r--r--Source/CMMCPResult.m12
-rw-r--r--Source/CustomQuery.h4
-rw-r--r--Source/CustomQuery.m77
4 files changed, 90 insertions, 8 deletions
diff --git a/Source/CMCopyTable.m b/Source/CMCopyTable.m
index 85f8a20e..1ed22248 100644
--- a/Source/CMCopyTable.m
+++ b/Source/CMCopyTable.m
@@ -26,6 +26,7 @@
#import "SPArrayAdditions.h"
#import "CMMCPConnection.h"
#import "TableContent.h"
+#import "CustomQuery.h"
int MENU_EDIT_COPY_WITH_COLUMN = 2001;
int MENU_EDIT_COPY_AS_SQL = 2002;
@@ -240,7 +241,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002;
[mySQLConnection prepareString:[rowData description]]]];
break;
case 2: // blob
- if ([prefs boolForKey:@"LoadBlobsAsNeeded"]) {
+ if (![[self delegate] isKindOfClass:[CustomQuery class]] && [prefs boolForKey:@"LoadBlobsAsNeeded"]) {
// Abort if there are no indices on this table or if there's no table name given.
if (![[tableInstance argumentForRow:row] length] || selectedTable == nil)
@@ -260,7 +261,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002;
}
break;
case 3: // long text data
- if ([prefs boolForKey:@"LoadBlobsAsNeeded"]) {
+ if (![[self delegate] isKindOfClass:[CustomQuery class]] && [prefs boolForKey:@"LoadBlobsAsNeeded"]) {
// Abort if there are no indices on this table or if there's no table name given.
if (![[tableInstance argumentForRow:row] length] || selectedTable == nil)
diff --git a/Source/CMMCPResult.m b/Source/CMMCPResult.m
index ebc5c6ab..afc7c2ed 100644
--- a/Source/CMMCPResult.m
+++ b/Source/CMMCPResult.m
@@ -370,7 +370,7 @@ modified version for use with sequel-pro
/* Div flags */
[fieldStructure setObject:[NSNumber numberWithUnsignedInt:theField[i].flags] forKey:@"flags"];
- [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & NOT_NULL_FLAG) ? YES : NO] forKey:@"NOT_NULL_FLAG"];
+ [fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & NOT_NULL_FLAG) ? YES : NO] forKey:@"null"];
[fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & PRI_KEY_FLAG) ? YES : NO] forKey:@"PRI_KEY_FLAG"];
[fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & UNIQUE_KEY_FLAG) ? YES : NO] forKey:@"UNIQUE_KEY_FLAG"];
[fieldStructure setObject:[NSNumber numberWithBool:(theField[i].flags & MULTIPLE_KEY_FLAG) ? YES : NO] forKey:@"MULTIPLE_KEY_FLAG"];
@@ -423,6 +423,7 @@ modified version for use with sequel-pro
{
// BOOL isUnsigned = (flags & UNSIGNED_FLAG) != 0;
// BOOL isZerofill = (flags & ZEROFILL_FLAG) != 0;
+
switch (type) {
case FIELD_TYPE_BIT:
return @"BIT";
@@ -473,7 +474,14 @@ modified version for use with sequel-pro
case 16777215: return isBlob? @"MEDIUMBLOB":@"MEDIUMTEXT";
case 4294967295: return isBlob? @"LONGBLOB":@"LONGTEXT";
default:
- return @"UNKNOWN";
+ switch (length) {
+ case 255: return isBlob? @"TINYBLOB":@"TINYTEXT";
+ case 65535: return isBlob? @"BLOB":@"TEXT";
+ case 16777215: return isBlob? @"MEDIUMBLOB":@"MEDIUMTEXT";
+ case 4294967295: return isBlob? @"LONGBLOB":@"LONGTEXT";
+ default:
+ return @"UNKNOWN";
+ }
}
}
case MYSQL_TYPE_VAR_STRING:
diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h
index 0be5dc0d..6c33a375 100644
--- a/Source/CustomQuery.h
+++ b/Source/CustomQuery.h
@@ -88,6 +88,9 @@
int helpTarget;
WebHistory *helpHistory;
NSString *helpHTMLTemplate;
+
+ NSMutableArray *fullResult;
+ NSArray *columnDefinition;
}
@@ -123,6 +126,7 @@
// Accessors
- (NSArray *)currentResult;
+- (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult;
// MySQL Help
- (NSString *)getHTMLformattedMySQLHelpFor:(NSString *)aString;
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index c07f4d24..d3739ef3 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -637,6 +637,10 @@
}
+ columnDefinition = [theResult fetchResultFieldsStructure];
+ [fullResult removeAllObjects];
+ [fullResult setArray:[self fetchResultAsArray:theResult]];
+
// Otherwise add columns corresponding to the query result
theColumns = [theResult fetchFieldNames];
for ( i = 0 ; i < [theResult numOfFields] ; i++) {
@@ -656,7 +660,7 @@
[customQueryView addTableColumn:theCol];
[theCol release];
}
-
+
[customQueryView sizeLastColumnToFit];
//tries to fix problem with last row (otherwise to small)
//sets last column to width of the first if smaller than 30
@@ -666,6 +670,9 @@
setWidth:[[customQueryView tableColumnWithIdentifier:[NSNumber numberWithInt:0]] width]];
[customQueryView reloadData];
+ // Init copyTable with necessary information for copying selected rows as SQL INSERT
+ [customQueryView setTableInstance:self withTableData:fullResult withColumns:columnDefinition withTableName:nil withConnection:mySQLConnection];
+
//query finished
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
@@ -676,6 +683,57 @@
}
/*
+ * Fetches the result as an array with a dictionary for each row in it
+ */
+- (NSArray *)fetchResultAsArray:(CMMCPResult *)theResult
+{
+ // NSArray *columns;
+ unsigned long numOfRows = [theResult numOfRows];
+ NSMutableArray *tempResult = [NSMutableArray arrayWithCapacity:numOfRows];
+
+ NSDictionary *tempRow;
+ NSMutableDictionary *modifiedRow = [NSMutableDictionary dictionary];
+ NSEnumerator *enumerator;
+ id key;
+ int i, j;
+ Class nullClass = [NSNull class];
+ id prefsNullValue = [prefs objectForKey:@"NullValue"];
+ BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:@"LoadBlobsAsNeeded"];
+
+ // columns = [customQueryView columns];
+ long columnsCount = [columnDefinition count];
+
+ if (numOfRows) [theResult dataSeek:0];
+ for ( i = 0 ; i < numOfRows ; i++ ) {
+ tempRow = [theResult fetchRowAsDictionary];
+ enumerator = [tempRow keyEnumerator];
+
+ while ( key = [enumerator nextObject] ) {
+ if ( [[tempRow objectForKey:key] isMemberOfClass:nullClass] ) {
+ [modifiedRow setObject:prefsNullValue forKey:key];
+ } else {
+ [modifiedRow setObject:[tempRow objectForKey:key] forKey:key];
+ }
+ }
+
+ // Add values for hidden blob and text fields if appropriate
+ // if ( prefsLoadBlobsAsNeeded ) {
+ // for ( j = 0 ; j < columnsCount ; j++ ) {
+ // if ( [[NSArrayObjectAtIndex(columnDefinition, j) objectForKey:@"typegrouping"] isEqualToString:@"blobdata"] ||
+ // [[NSArrayObjectAtIndex(columnDefinition, j) objectForKey:@"typegrouping"] isEqualToString:@"textdata"]) {
+ // [modifiedRow setObject:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields") forKey:[NSArrayObjectAtIndex(columnDefinition, j) objectForKey:@"name"]];
+ // }
+ // }
+ // }
+
+ [tempResult addObject:[NSMutableDictionary dictionaryWithDictionary:modifiedRow]];
+ }
+
+ return tempResult;
+}
+
+
+/*
* Retrieve the range of the query at a position specified
* within the custom query text view.
*/
@@ -1030,15 +1088,23 @@
tmp = [[NSString alloc] initWithData:[theRow objectAtIndex:[theIdentifier intValue]]
encoding:NSASCIIStringEncoding];
}
- return [tmp autorelease];
+ // If field contains binary data show only the first 255 bytes for speed
+ if([tmp length] > 255) {
+ return [[tmp autorelease] substringToIndex:255];
+ } else
+ return [tmp autorelease];
}
if ( [[theRow objectAtIndex:[theIdentifier intValue]] isMemberOfClass:[NSNull class]] )
return [prefs objectForKey:@"NullValue"];
return [theRow objectAtIndex:[theIdentifier intValue]];
- } else if ( aTableView == queryFavoritesView ) {
+ }
+
+ else if ( aTableView == queryFavoritesView ) {
return [queryFavorites objectAtIndex:rowIndex];
- } else {
+ }
+
+ else {
return @"";
}
}
@@ -1914,6 +1980,8 @@
// init search history
[helpWebView setMaintainsBackForwardList:YES];
[[helpWebView backForwardList] setCapacity:20];
+
+ fullResult = [[NSMutableArray alloc] init];
}
return self;
@@ -1930,6 +1998,7 @@
[queryResult release];
[queryFavorites release];
[usedQuery release];
+ [fullResult release];
[super dealloc];
}