aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-11-20 05:42:12 +0100
committerMax <post@wickenrode.com>2015-11-20 05:42:12 +0100
commit7d4ec977bfdc0fea0af962d3859ba6d39c3c3a2d (patch)
tree45ed1ef1e4d6cb94dce0daea3f36ecedcba2c3c1
parent8b2376dc47110530eeab8f61334ff46e28256045 (diff)
downloadsequelpro-7d4ec977bfdc0fea0af962d3859ba6d39c3c3a2d.tar.gz
sequelpro-7d4ec977bfdc0fea0af962d3859ba6d39c3c3a2d.tar.bz2
sequelpro-7d4ec977bfdc0fea0af962d3859ba6d39c3c3a2d.zip
Export SQL in utf8mb4 if available (part of #2321)
-rw-r--r--Source/SPSQLExporter.m12
1 files changed, 12 insertions, 0 deletions
diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m
index 2fc581b0..1fde9ea0 100644
--- a/Source/SPSQLExporter.m
+++ b/Source/SPSQLExporter.m
@@ -170,6 +170,8 @@
// we require utf8
[connection setEncoding:@"utf8"];
+ // …but utf8mb4 (aka "really" utf8) would be even better.
+ BOOL utf8mb4 = [connection setEncoding:@"utf8mb4"];
// Add the dump header to the dump file
[metaString appendString:@"# ************************************************************\n"];
@@ -186,6 +188,15 @@
[metaString appendString:@"/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n"];
[metaString appendString:@"/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n"];
[metaString appendString:@"/*!40101 SET NAMES utf8 */;\n"];
+ if(utf8mb4) {
+ // !! This being outside of a conditional comment is FULLY INTENTIONAL !!
+ // We *absolutely* want that to fail if the export includes utf8mb4 data, but the server can't handle it.
+ // MySQL would _normally_ just drop-replace such characters with "?" (a literal questionmark) without any (visible) complaint.
+ // Since that means irreversible (and often hard to notice) data corruption,
+ // the user should CONSCIOUSLY make a decision for that to happen!
+ //TODO we should link to a website explaining the risk here
+ [metaString appendString:@"SET NAMES utf8mb4;\n"];
+ }
[metaString appendString:@"/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n"];
[metaString appendString:@"/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n"];
@@ -464,6 +475,7 @@
NSString *data = [[NSString alloc] initWithData:object encoding:[self exportOutputEncoding]];
if (data == nil) {
+#warning This can corrupt data! Check if this case ever happens and if so, export as hex-string
data = [[NSString alloc] initWithData:object encoding:NSASCIIStringEncoding];
}