aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-22 09:24:25 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-22 09:24:25 +0000
commitd061b5ad82b2dac3981f60f39bf397a13a912d12 (patch)
treec0edde0a32e75cb35f966f58130bf8218eb05f8b
parentfab8a7ddf951ed3697760093b43a612fa51a78c6 (diff)
downloadsequelpro-d061b5ad82b2dac3981f60f39bf397a13a912d12.tar.gz
sequelpro-d061b5ad82b2dac3981f60f39bf397a13a912d12.tar.bz2
sequelpro-d061b5ad82b2dac3981f60f39bf397a13a912d12.zip
• improved: "Copy as SQL INSERT" in Custom Query passes the original table name (not that one defined via "AS") if the result columns' table source is the same, otherwise <table>.
-rw-r--r--Source/CustomQuery.m29
1 files changed, 23 insertions, 6 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index d3739ef3..ba895a97 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -637,11 +637,28 @@
}
+ // get column definitions for the result array
columnDefinition = [theResult fetchResultFieldsStructure];
+
+ // set datasource
[fullResult removeAllObjects];
[fullResult setArray:[self fetchResultAsArray:theResult]];
- // Otherwise add columns corresponding to the query result
+ // Find result table name for copying as SQL INSERT.
+ // If more than one table name is found set resultTableName to nil.
+ // resultTableName will be set to the original table name (not defined via AS) provided by mysql return
+ // and the resultTableName can differ due to case-sensitive/insensitive settings!.
+ BOOL resultShowsColumnsFromOneTable = YES;
+ NSString *resultTableName = [[columnDefinition objectAtIndex:0] objectForKey:@"org_table"];
+ for(id field in columnDefinition) {
+ if(![[field objectForKey:@"org_table"] isEqualToString:resultTableName]) {
+ resultShowsColumnsFromOneTable = NO;
+ resultTableName = nil;
+ break;
+ }
+ }
+
+ // Add columns corresponding to the query result
theColumns = [theResult fetchFieldNames];
for ( i = 0 ; i < [theResult numOfFields] ; i++) {
theCol = [[NSTableColumn alloc] initWithIdentifier:[NSNumber numberWithInt:i]];
@@ -655,7 +672,7 @@
}
[dataCell setLineBreakMode:NSLineBreakByTruncatingTail];
[theCol setDataCell:dataCell];
- [[theCol headerCell] setStringValue:[theColumns objectAtIndex:i]];
+ [[theCol headerCell] setStringValue:NSArrayObjectAtIndex(theColumns, i)];
[customQueryView addTableColumn:theCol];
[theCol release];
@@ -671,7 +688,7 @@
[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];
+ [customQueryView setTableInstance:self withTableData:fullResult withColumns:columnDefinition withTableName:resultTableName withConnection:mySQLConnection];
//query finished
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
@@ -695,13 +712,13 @@
NSMutableDictionary *modifiedRow = [NSMutableDictionary dictionary];
NSEnumerator *enumerator;
id key;
- int i, j;
+ int i;
Class nullClass = [NSNull class];
id prefsNullValue = [prefs objectForKey:@"NullValue"];
- BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:@"LoadBlobsAsNeeded"];
+ // BOOL prefsLoadBlobsAsNeeded = [prefs boolForKey:@"LoadBlobsAsNeeded"];
// columns = [customQueryView columns];
- long columnsCount = [columnDefinition count];
+ // long columnsCount = [columnDefinition count];
if (numOfRows) [theResult dataSeek:0];
for ( i = 0 ; i < numOfRows ; i++ ) {