diff options
author | rowanbeentje <rowan@beent.je> | 2010-05-01 01:36:52 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2010-05-01 01:36:52 +0000 |
commit | 8acde6bf2580ce1e2feac2b9ac74dfa34b1ddf7e (patch) | |
tree | 4c2411b8f04d038d03013cae244d54566761ec96 /Source/TableDump.m | |
parent | 9175848b8bbe6e4b9145a492d9b4da86adb8760d (diff) | |
download | sequelpro-8acde6bf2580ce1e2feac2b9ac74dfa34b1ddf7e.tar.gz sequelpro-8acde6bf2580ce1e2feac2b9ac74dfa34b1ddf7e.tar.bz2 sequelpro-8acde6bf2580ce1e2feac2b9ac74dfa34b1ddf7e.zip |
Review trigger fetching and storage:
- Trigger queries are no longer made for MySQL < 5.0.2
- Trigger loading has been deferred until the trigger tab is active, reducing queries when switching tables and thus increasing overall responsiveness
- Export triggers in MySQL dumps even if the Table Content switch is unchecked
Diffstat (limited to 'Source/TableDump.m')
-rw-r--r-- | Source/TableDump.m | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/Source/TableDump.m b/Source/TableDump.m index 9f40d90e..004a8e61 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -1921,52 +1921,52 @@ // Release the result set [streamingResult release]; + } + + // Export triggers, if any + queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"/*!50003 SHOW TRIGGERS WHERE `Table` = %@ */;", + [tableName tickQuotedString]]]; + [queryResult setReturnDataAsStrings:YES]; + if ( [queryResult numOfRows] ) { + [metaString setString:@"\n"]; + [metaString appendString:@"DELIMITER ;;\n"]; - queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"/*!50003 SHOW TRIGGERS WHERE `Table` = %@ */;", - [tableName tickQuotedString]]]; - [queryResult setReturnDataAsStrings:YES]; - if ( [queryResult numOfRows] ) { - [metaString setString:@"\n"]; - [metaString appendString:@"DELIMITER ;;\n"]; + for (int s=0; s<[queryResult numOfRows]; s++) { + NSDictionary *triggers = [[NSDictionary alloc] initWithDictionary:[queryResult fetchRowAsDictionary]]; - for (int s=0; s<[queryResult numOfRows]; s++) { - NSDictionary *triggers = [[NSDictionary alloc] initWithDictionary:[queryResult fetchRowAsDictionary]]; - - //Definer is user@host but we need to escape it to `user`@`host` - NSArray *triggersDefiner = [[triggers objectForKey:@"Definer"] componentsSeparatedByString:@"@"]; - NSString *escapedDefiner = [NSString stringWithFormat:@"%@@%@", - [[triggersDefiner objectAtIndex:0] backtickQuotedString], - [[triggersDefiner objectAtIndex:1] backtickQuotedString] - ]; - - [metaString appendString:[NSString stringWithFormat:@"/*!50003 SET SESSION SQL_MODE=\"%@\" */;;\n", - [triggers objectForKey:@"sql_mode"]]]; - [metaString appendString:@"/*!50003 CREATE */ "]; - [metaString appendString:[NSString stringWithFormat:@"/*!50017 DEFINER=%@ */ ", - escapedDefiner]]; - [metaString appendString:[NSString stringWithFormat:@"/*!50003 TRIGGER %@ %@ %@ ON %@ FOR EACH ROW %@ */;;\n", - [[triggers objectForKey:@"Trigger"] backtickQuotedString], - [triggers objectForKey:@"Timing"], - [triggers objectForKey:@"Event"], - [[triggers objectForKey:@"Table"] backtickQuotedString], - [triggers objectForKey:@"Statement"] - ]]; - [triggers release]; - } + //Definer is user@host but we need to escape it to `user`@`host` + NSArray *triggersDefiner = [[triggers objectForKey:@"Definer"] componentsSeparatedByString:@"@"]; + NSString *escapedDefiner = [NSString stringWithFormat:@"%@@%@", + [[triggersDefiner objectAtIndex:0] backtickQuotedString], + [[triggersDefiner objectAtIndex:1] backtickQuotedString] + ]; - [metaString appendString:@"DELIMITER ;\n"]; - [metaString appendString:@"/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"]; - [fileHandle writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; + [metaString appendString:[NSString stringWithFormat:@"/*!50003 SET SESSION SQL_MODE=\"%@\" */;;\n", + [triggers objectForKey:@"sql_mode"]]]; + [metaString appendString:@"/*!50003 CREATE */ "]; + [metaString appendString:[NSString stringWithFormat:@"/*!50017 DEFINER=%@ */ ", + escapedDefiner]]; + [metaString appendString:[NSString stringWithFormat:@"/*!50003 TRIGGER %@ %@ %@ ON %@ FOR EACH ROW %@ */;;\n", + [[triggers objectForKey:@"Trigger"] backtickQuotedString], + [triggers objectForKey:@"Timing"], + [triggers objectForKey:@"Event"], + [[triggers objectForKey:@"Table"] backtickQuotedString], + [triggers objectForKey:@"Statement"] + ]]; + [triggers release]; } - if ([mySQLConnection queryErrored]) { - [errors appendString:[NSString stringWithFormat:@"%@\n", [mySQLConnection getLastErrorMessage]]]; - if ( [addErrorsSwitch state] == NSOnState ) { - [fileHandle writeData:[[NSString stringWithFormat:@"# Error: %@\n", [mySQLConnection getLastErrorMessage]] - dataUsingEncoding:NSUTF8StringEncoding]]; - } + [metaString appendString:@"DELIMITER ;\n"]; + [metaString appendString:@"/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"]; + [fileHandle writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; + } + + if ([mySQLConnection queryErrored]) { + [errors appendString:[NSString stringWithFormat:@"%@\n", [mySQLConnection getLastErrorMessage]]]; + if ( [addErrorsSwitch state] == NSOnState ) { + [fileHandle writeData:[[NSString stringWithFormat:@"# Error: %@\n", [mySQLConnection getLastErrorMessage]] + dataUsingEncoding:NSUTF8StringEncoding]]; } - } // Add an additional separator between tables |