aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPSQLExporter.m89
1 files changed, 46 insertions, 43 deletions
diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m
index 81e7756e..286abc22 100644
--- a/Source/SPSQLExporter.m
+++ b/Source/SPSQLExporter.m
@@ -494,56 +494,59 @@
}
}
}
+
+ // Add triggers if the structure export was enabled
+ if (sqlOutputIncludeStructure) {
+ queryResult = [connection queryString:[NSString stringWithFormat:@"/*!50003 SHOW TRIGGERS WHERE `Table` = %@ */", [tableName tickQuotedString]]];
- queryResult = [connection queryString:[NSString stringWithFormat:@"/*!50003 SHOW TRIGGERS WHERE `Table` = %@ */", [tableName tickQuotedString]]];
-
- [queryResult setReturnDataAsStrings:YES];
-
- if ([queryResult numberOfRows]) {
-
- [metaString setString:@"\n"];
- [metaString appendString:@"DELIMITER ;;\n"];
+ [queryResult setReturnDataAsStrings:YES];
- for (s = 0; s < [queryResult numberOfRows]; s++)
- {
- // Check for cancellation flag
- if ([self isCancelled]) {
- [errors release];
- [sqlString release];
- [pool release];
- return;
+ if ([queryResult numberOfRows]) {
+
+ [metaString setString:@"\n"];
+ [metaString appendString:@"DELIMITER ;;\n"];
+
+ for (s = 0; s < [queryResult numberOfRows]; s++)
+ {
+ // Check for cancellation flag
+ if ([self isCancelled]) {
+ [errors release];
+ [sqlString release];
+ [pool release];
+ return;
+ }
+
+ NSDictionary *triggers = [[NSDictionary alloc] initWithDictionary:[queryResult getRowAsDictionary]];
+
+ // Definer is user@host but we need to escape it to `user`@`host`
+ NSArray *triggersDefiner = [[triggers objectForKey:@"Definer"] componentsSeparatedByString:@"@"];
+
+ [metaString appendFormat:@"/*!50003 SET SESSION SQL_MODE=\"%@\" */;;\n/*!50003 CREATE */ ", [triggers objectForKey:@"sql_mode"]];
+ [metaString appendFormat:@"/*!50017 DEFINER=%@@%@ */ /*!50003 TRIGGER %@ %@ %@ ON %@ FOR EACH ROW %@ */;;\n",
+ [NSArrayObjectAtIndex(triggersDefiner, 0) backtickQuotedString],
+ [NSArrayObjectAtIndex(triggersDefiner, 1) backtickQuotedString],
+ [[triggers objectForKey:@"Trigger"] backtickQuotedString],
+ [triggers objectForKey:@"Timing"],
+ [triggers objectForKey:@"Event"],
+ [[triggers objectForKey:@"Table"] backtickQuotedString],
+ [triggers objectForKey:@"Statement"]
+ ];
+
+ [triggers release];
}
- NSDictionary *triggers = [[NSDictionary alloc] initWithDictionary:[queryResult getRowAsDictionary]];
+ [metaString appendString:@"DELIMITER ;\n/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"];
- // Definer is user@host but we need to escape it to `user`@`host`
- NSArray *triggersDefiner = [[triggers objectForKey:@"Definer"] componentsSeparatedByString:@"@"];
-
- [metaString appendFormat:@"/*!50003 SET SESSION SQL_MODE=\"%@\" */;;\n/*!50003 CREATE */ ", [triggers objectForKey:@"sql_mode"]];
- [metaString appendFormat:@"/*!50017 DEFINER=%@@%@ */ /*!50003 TRIGGER %@ %@ %@ ON %@ FOR EACH ROW %@ */;;\n",
- [NSArrayObjectAtIndex(triggersDefiner, 0) backtickQuotedString],
- [NSArrayObjectAtIndex(triggersDefiner, 1) backtickQuotedString],
- [[triggers objectForKey:@"Trigger"] backtickQuotedString],
- [triggers objectForKey:@"Timing"],
- [triggers objectForKey:@"Event"],
- [[triggers objectForKey:@"Table"] backtickQuotedString],
- [triggers objectForKey:@"Statement"]
- ];
-
- [triggers release];
+ [[self exportOutputFile] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]];
}
- [metaString appendString:@"DELIMITER ;\n/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"];
-
- [[self exportOutputFile] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]];
- }
-
- if ([connection queryErrored]) {
- [errors appendFormat:@"%@\n", [connection lastErrorMessage]];
-
- if ([self sqlOutputIncludeErrors]) {
- [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection lastErrorMessage]]
- dataUsingEncoding:NSUTF8StringEncoding]];
+ if ([connection queryErrored]) {
+ [errors appendFormat:@"%@\n", [connection lastErrorMessage]];
+
+ if ([self sqlOutputIncludeErrors]) {
+ [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"# Error: %@\n", [connection lastErrorMessage]]
+ dataUsingEncoding:NSUTF8StringEncoding]];
+ }
}
}