|
6 | 6 | *
|
7 | 7 | *
|
8 | 8 | * IDENTIFICATION
|
9 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.27 1997/08/22 14:22:09 vadim Exp $ |
| 9 | + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.28 1997/09/01 07:59:04 vadim Exp $ |
10 | 10 | *
|
11 | 11 | *-------------------------------------------------------------------------
|
12 | 12 | */
|
|
34 | 34 | #include <catalog/catname.h>
|
35 | 35 | #include <catalog/pg_user.h>
|
36 | 36 | #include <commands/copy.h>
|
| 37 | +#include "commands/trigger.h" |
37 | 38 | #include <storage/fd.h>
|
38 | 39 |
|
39 | 40 | #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
|
@@ -334,6 +335,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
334 | 335 | InsertIndexResult indexRes;
|
335 | 336 | TupleDesc tupDesc;
|
336 | 337 | Oid loaded_oid;
|
| 338 | + bool skip_tuple = false; |
337 | 339 |
|
338 | 340 | tupDesc = RelationGetTupleDescriptor(rel);
|
339 | 341 | attr = tupDesc->attrs;
|
@@ -602,54 +604,83 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
602 | 604 | tuple = heap_formtuple(tupDesc, values, nulls);
|
603 | 605 | if (oids)
|
604 | 606 | tuple->t_oid = loaded_oid;
|
605 |
| - |
606 |
| - /* ---------------- |
607 |
| - * Check the constraints of a tuple |
608 |
| - * ---------------- |
609 |
| - */ |
610 |
| - |
611 |
| - if ( rel->rd_att->constr ) |
| 607 | + |
| 608 | + skip_tuple = false; |
| 609 | + /* BEFORE ROW INSERT Triggers */ |
| 610 | + if ( rel->trigdesc && |
| 611 | + rel->trigdesc->n_before_row[TRIGGER_ACTION_INSERT] > 0 ) |
612 | 612 | {
|
613 | 613 | HeapTuple newtuple;
|
614 | 614 |
|
615 |
| - newtuple = ExecConstraints ("CopyFrom", rel, tuple); |
616 |
| - |
617 |
| - if ( newtuple != tuple ) |
| 615 | + newtuple = ExecBRInsertTriggers (rel, tuple); |
| 616 | + |
| 617 | + if ( newtuple == NULL ) /* "do nothing" */ |
| 618 | + skip_tuple = true; |
| 619 | + else if ( newtuple != tuple ) /* modified by Trigger(s) */ |
618 | 620 | {
|
619 | 621 | pfree (tuple);
|
620 | 622 | tuple = newtuple;
|
621 | 623 | }
|
622 | 624 | }
|
| 625 | + |
| 626 | + if ( !skip_tuple ) |
| 627 | + { |
| 628 | + /* ---------------- |
| 629 | + * Check the constraints of a tuple |
| 630 | + * ---------------- |
| 631 | + */ |
623 | 632 |
|
624 |
| - heap_insert(rel, tuple); |
| 633 | + if ( rel->rd_att->constr ) |
| 634 | + { |
| 635 | + HeapTuple newtuple; |
| 636 | + |
| 637 | + newtuple = ExecConstraints ("CopyFrom", rel, tuple); |
| 638 | + |
| 639 | + if ( newtuple != tuple ) |
| 640 | + { |
| 641 | + pfree (tuple); |
| 642 | + tuple = newtuple; |
| 643 | + } |
| 644 | + } |
| 645 | + |
| 646 | + heap_insert(rel, tuple); |
625 | 647 |
|
626 |
| - if (has_index) { |
627 |
| - for (i = 0; i < n_indices; i++) { |
628 |
| - if (indexPred[i] != NULL) { |
| 648 | + if (has_index) |
| 649 | + { |
| 650 | + for (i = 0; i < n_indices; i++) |
| 651 | + { |
| 652 | + if (indexPred[i] != NULL) |
| 653 | + { |
629 | 654 | #ifndef OMIT_PARTIAL_INDEX
|
630 |
| - /* if tuple doesn't satisfy predicate, |
631 |
| - * don't update index |
632 |
| - */ |
633 |
| - slot->val = tuple; |
634 |
| - /*SetSlotContents(slot, tuple); */ |
635 |
| - if (ExecQual((List*)indexPred[i], econtext) == false) |
636 |
| - continue; |
| 655 | + /* |
| 656 | + * if tuple doesn't satisfy predicate, |
| 657 | + * don't update index |
| 658 | + */ |
| 659 | + slot->val = tuple; |
| 660 | + /*SetSlotContents(slot, tuple); */ |
| 661 | + if (ExecQual((List*)indexPred[i], econtext) == false) |
| 662 | + continue; |
637 | 663 | #endif /* OMIT_PARTIAL_INDEX */
|
638 |
| - } |
639 |
| - FormIndexDatum(indexNatts[i], |
| 664 | + } |
| 665 | + FormIndexDatum(indexNatts[i], |
640 | 666 | (AttrNumber *)&(pgIndexP[i]->indkey[0]),
|
641 | 667 | tuple,
|
642 | 668 | tupDesc,
|
643 | 669 | InvalidBuffer,
|
644 | 670 | idatum,
|
645 | 671 | index_nulls,
|
646 | 672 | finfoP[i]);
|
647 |
| - indexRes = index_insert(index_rels[i], idatum, index_nulls, |
| 673 | + indexRes = index_insert(index_rels[i], idatum, index_nulls, |
648 | 674 | &(tuple->t_ctid), rel);
|
649 |
| - if (indexRes) pfree(indexRes); |
| 675 | + if (indexRes) pfree(indexRes); |
| 676 | + } |
650 | 677 | }
|
| 678 | + /* AFTER ROW INSERT Triggers */ |
| 679 | + if ( rel->trigdesc && |
| 680 | + rel->trigdesc->n_after_row[TRIGGER_ACTION_INSERT] > 0 ) |
| 681 | + ExecARInsertTriggers (rel, tuple); |
651 | 682 | }
|
652 |
| - |
| 683 | + |
653 | 684 | if (binary) pfree(string);
|
654 | 685 |
|
655 | 686 | for (i = 0; i < attr_count; i++) {
|
|
0 commit comments