3737 * Modifications - 27-Jan-2001 - pjw@rhyme.com.au
3838 * - When dropping the schema, reconnect as owner of each object.
3939 *
40+ * Modifications - 6-Mar-2001 - pjw@rhyme.com.au
41+ * - Only disable triggers in DataOnly (or implied data-only) restores.
42+ *
4043 *-------------------------------------------------------------------------
4144 */
4245
@@ -65,8 +68,8 @@ static void_reconnectAsOwner(ArchiveHandle* AH, const char *dbname, TocEntry*
6568static void _reconnectAsUser (ArchiveHandle * AH ,const char * dbname ,char * user );
6669
6770static int _tocEntryRequired (TocEntry * te ,RestoreOptions * ropt );
68- static void _disableTriggers (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt );
69- static void _enableTriggers (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt );
71+ static void _disableTriggersIfNecessary (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt );
72+ static void _enableTriggersIfNecessary (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt );
7073static TocEntry * _getTocEntry (ArchiveHandle * AH ,int id );
7174static void _moveAfter (ArchiveHandle * AH ,TocEntry * pos ,TocEntry * te );
7275static void _moveBefore (ArchiveHandle * AH ,TocEntry * pos ,TocEntry * te );
@@ -128,8 +131,9 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
128131{
129132ArchiveHandle * AH = (ArchiveHandle * )AHX ;
130133TocEntry * te = AH -> toc -> next ;
131- int reqs ;
134+ int reqs ;
132135OutputContext sav ;
136+ int impliedDataOnly ;
133137
134138AH -> ropt = ropt ;
135139
@@ -159,6 +163,33 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
159163
160164}
161165
166+ /*
167+ * Work out if we have an implied data-only retore. This can happen if
168+ * the dump was data only or if the user has used a toc list to exclude
169+ * all of the schema data. All we do is look for schema entries - if none
170+ * are found then we set the dataOnly flag.
171+ *
172+ * We could scan for wanted TABLE entries, but that is not the same as
173+ * dataOnly. At this stage, it seems unnecessary (6-Mar-2001).
174+ */
175+ if (!ropt -> dataOnly ) {
176+ te = AH -> toc -> next ;
177+ impliedDataOnly = 1 ;
178+ while (te != AH -> toc ) {
179+ reqs = _tocEntryRequired (te ,ropt );
180+ if ( (reqs & 1 )!= 0 ) {/* It's schema, and it's wanted */
181+ impliedDataOnly = 0 ;
182+ break ;
183+ }
184+ te = te -> next ;
185+ }
186+ if (impliedDataOnly )
187+ {
188+ ropt -> dataOnly = impliedDataOnly ;
189+ ahlog (AH ,1 ,"Implied data-only restore\n" ,te -> desc ,te -> name );
190+ }
191+ }
192+
162193if (!ropt -> superuser )
163194fprintf (stderr ,"\n%s: ******** WARNING ******** \n"
164195" Data restoration may fail since any defined triggers\n"
@@ -244,7 +275,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
244275
245276}else {
246277
247- _disableTriggers (AH ,te ,ropt );
278+ _disableTriggersIfNecessary (AH ,te ,ropt );
248279
249280/* Reconnect if necessary (_disableTriggers may have reconnected) */
250281_reconnectAsOwner (AH ,"-" ,te );
@@ -263,7 +294,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
263294
264295(* AH -> PrintTocDataPtr )(AH ,te ,ropt );
265296
266- _enableTriggers (AH ,te ,ropt );
297+ _enableTriggersIfNecessary (AH ,te ,ropt );
267298}
268299}
269300te = te -> next ;
@@ -275,7 +306,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
275306if (_canRestoreBlobs (AH )&& AH -> createdBlobXref )
276307{
277308/* NULL parameter means disable ALL user triggers */
278- _disableTriggers (AH ,NULL ,ropt );
309+ _disableTriggersIfNecessary (AH ,NULL ,ropt );
279310
280311te = AH -> toc -> next ;
281312while (te != AH -> toc ) {
@@ -302,7 +333,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
302333}
303334
304335/* NULL parameter means enable ALL user triggers */
305- _enableTriggers (AH ,NULL ,ropt );
336+ _enableTriggersIfNecessary (AH ,NULL ,ropt );
306337}
307338
308339/*
@@ -349,12 +380,13 @@ static int _canRestoreBlobs(ArchiveHandle *AH)
349380return _restoringToDB (AH );
350381}
351382
352- static void _disableTriggers (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt )
383+ static void _disableTriggersIfNecessary (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt )
353384{
354385char * oldUser = NULL ;
355386
356387/* Can't do much if we're connected & don't have a superuser */
357- if (_restoringToDB (AH )&& !ropt -> superuser )
388+ /* Also, don't bother with triggers unless a data-only retore. */
389+ if ( !ropt -> dataOnly || (_restoringToDB (AH )&& !ropt -> superuser ) )
358390return ;
359391
360392/*
@@ -404,12 +436,13 @@ static void _disableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ro
404436}
405437}
406438
407- static void _enableTriggers (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt )
439+ static void _enableTriggersIfNecessary (ArchiveHandle * AH ,TocEntry * te ,RestoreOptions * ropt )
408440{
409441char * oldUser = NULL ;
410442
411443/* Can't do much if we're connected & don't have a superuser */
412- if (_restoringToDB (AH )&& !ropt -> superuser )
444+ /* Also, don't bother with triggers unless a data-only retore. */
445+ if ( !ropt -> dataOnly || (_restoringToDB (AH )&& !ropt -> superuser ) )
413446return ;
414447
415448/*