You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[metaString appendString:@"/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n"];
199
-
[metaString appendString:@"/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n"];
195
+
200
196
/* A note on SQL_MODE:
201
197
*
202
198
* BEFORE 3.23.6
@@ -228,6 +224,40 @@ - (void)exportOperation
228
224
* (trivia: internally it has become MODE_NOT_USED: 16 = "?")
229
225
*
230
226
*/
227
+
228
+
BOOL sqlModeIsValid = NO;
229
+
//fetch old sql mode to restore it later
230
+
{
231
+
SPMySQLResult *result = [connection queryString:@"SHOW VARIABLES LIKE 'sql_mode'"];
232
+
if(![connection queryErrored]) {
233
+
[result setReturnDataAsStrings:YES];
234
+
NSArray *row = [result getRowAsArray];
235
+
oldSqlMode = [[row objectAtIndex:1] unboxNull];
236
+
}
237
+
}
238
+
//set sql mode for export
239
+
if([@""isEqualToString:oldSqlMode]) {
240
+
// the current sql_mode is already the one we want (empty string), no need to change+revert it
241
+
oldSqlMode = nil;
242
+
sqlModeIsValid = YES;
243
+
}
244
+
else {
245
+
[connection queryString:@"SET SQL_MODE=''"]; //mysqldump uses a conditional comment for 40100 here, but we want to see the error, since it can't simply be ignored (also ANSI mode is supported before 4.1)
246
+
if (![connection queryErrored]) {
247
+
sqlModeIsValid = YES;
248
+
}
249
+
else {
250
+
[errors appendFormat:@"%@ (%@)\n", NSLocalizedString(@"The server's SQL_MODE could not be changed to one suitable for export. The export may be missing important details or may not be importable at all!", @"sql export : 'set @@sql_mode' query failed message"), [connection lastErrorMessage]];
251
+
[selfwriteUTF8String:[NSStringstringWithFormat:@"# SET SQL_MODE Error: %@\n\n\n", [connection lastErrorMessage]]];
252
+
//if we couldn't change it, we don't need to restore it either
253
+
oldSqlMode = nil;
254
+
}
255
+
}
256
+
// there is no point in writing out that the file should use a specific SQL mode when we don't even know which one was active during export
257
+
if(sqlModeIsValid) {
258
+
[metaString appendString:@"/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n"];
259
+
}
260
+
231
261
[metaString appendString:@"/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n\n\n"];
0 commit comments