@@ -428,60 +428,75 @@ RestoreArchive(Archive *AHX)
428
428
}
429
429
else
430
430
{
431
- char buffer [40 ];
432
- char * mark ;
433
- char * dropStmt = pg_strdup (te -> dropStmt );
434
- char * dropStmtPtr = dropStmt ;
435
- PQExpBuffer ftStmt = createPQExpBuffer ();
436
-
437
431
/*
438
- * Need to inject IF EXISTS clause after ALTER TABLE
439
- * part in ALTER TABLE .. DROP statement
432
+ * Inject an appropriate spelling of "if exists". For
433
+ * large objects, we have a separate routine that
434
+ * knows how to do it, without depending on
435
+ * te->dropStmt; use that. For other objects we need
436
+ * to parse the command.
437
+ *
440
438
*/
441
- if (strncmp (dropStmt , "ALTER TABLE " , 11 ) == 0 )
439
+ if (strncmp (te -> desc , "BLOB " , 4 ) == 0 )
442
440
{
443
- appendPQExpBuffer (ftStmt ,
444
- "ALTER TABLE IF EXISTS" );
445
- dropStmt = dropStmt + 11 ;
441
+ DropBlobIfExists (AH , te -> catalogId .oid );
446
442
}
447
-
448
- /*
449
- * ALTER TABLE..ALTER COLUMN..DROP DEFAULT does not
450
- * support the IF EXISTS clause, and therefore we
451
- * simply emit the original command for such objects.
452
- * For other objects, we need to extract the first
453
- * part of the DROP which includes the object type.
454
- * Most of the time this matches te->desc, so search
455
- * for that; however for the different kinds of
456
- * CONSTRAINTs, we know to search for hardcoded "DROP
457
- * CONSTRAINT" instead.
458
- */
459
- if (strcmp (te -> desc , "DEFAULT" ) == 0 )
460
- appendPQExpBuffer (ftStmt , "%s" , dropStmt );
461
443
else
462
444
{
463
- if (strcmp (te -> desc , "CONSTRAINT" ) == 0 ||
464
- strcmp (te -> desc , "CHECK CONSTRAINT" ) == 0 ||
465
- strcmp (te -> desc , "FK CONSTRAINT" ) == 0 )
466
- strcpy (buffer , "DROP CONSTRAINT" );
445
+ char buffer [40 ];
446
+ char * mark ;
447
+ char * dropStmt = pg_strdup (te -> dropStmt );
448
+ char * dropStmtPtr = dropStmt ;
449
+ PQExpBuffer ftStmt = createPQExpBuffer ();
450
+
451
+ /*
452
+ * Need to inject IF EXISTS clause after ALTER
453
+ * TABLE part in ALTER TABLE .. DROP statement
454
+ */
455
+ if (strncmp (dropStmt , "ALTER TABLE" , 11 ) == 0 )
456
+ {
457
+ appendPQExpBuffer (ftStmt ,
458
+ "ALTER TABLE IF EXISTS" );
459
+ dropStmt = dropStmt + 11 ;
460
+ }
461
+
462
+ /*
463
+ * ALTER TABLE..ALTER COLUMN..DROP DEFAULT does
464
+ * not support the IF EXISTS clause, and therefore
465
+ * we simply emit the original command for such
466
+ * objects. For other objects, we need to extract
467
+ * the first part of the DROP which includes the
468
+ * object type. Most of the time this matches
469
+ * te->desc, so search for that; however for the
470
+ * different kinds of CONSTRAINTs, we know to
471
+ * search for hardcoded "DROP CONSTRAINT" instead.
472
+ */
473
+ if (strcmp (te -> desc , "DEFAULT" ) == 0 )
474
+ appendPQExpBuffer (ftStmt , "%s" , dropStmt );
467
475
else
468
- snprintf (buffer , sizeof (buffer ), "DROP %s" ,
469
- te -> desc );
476
+ {
477
+ if (strcmp (te -> desc , "CONSTRAINT" ) == 0 ||
478
+ strcmp (te -> desc , "CHECK CONSTRAINT" ) == 0 ||
479
+ strcmp (te -> desc , "FK CONSTRAINT" ) == 0 )
480
+ strcpy (buffer , "DROP CONSTRAINT" );
481
+ else
482
+ snprintf (buffer , sizeof (buffer ), "DROP %s" ,
483
+ te -> desc );
470
484
471
- mark = strstr (dropStmt , buffer );
472
- Assert (mark != NULL );
485
+ mark = strstr (dropStmt , buffer );
486
+ Assert (mark != NULL );
473
487
474
- * mark = '\0' ;
475
- appendPQExpBuffer (ftStmt , "%s%s IF EXISTS%s" ,
476
- dropStmt , buffer ,
477
- mark + strlen (buffer ));
478
- }
488
+ * mark = '\0' ;
489
+ appendPQExpBuffer (ftStmt , "%s%s IF EXISTS%s" ,
490
+ dropStmt , buffer ,
491
+ mark + strlen (buffer ));
492
+ }
479
493
480
- ahprintf (AH , "%s" , ftStmt -> data );
494
+ ahprintf (AH , "%s" , ftStmt -> data );
481
495
482
- destroyPQExpBuffer (ftStmt );
496
+ destroyPQExpBuffer (ftStmt );
483
497
484
- pg_free (dropStmtPtr );
498
+ pg_free (dropStmtPtr );
499
+ }
485
500
}
486
501
}
487
502
}
0 commit comments