summaryrefslogtreecommitdiff
path: root/contrib/spi/autoinc.c
diff options
context:
space:
mode:
authorPavan Deolasee2017-06-14 05:42:18 +0000
committerPavan Deolasee2017-06-14 05:42:18 +0000
commit15dd5274c323fb93e4e3ea9ad2185aaaec10f79c (patch)
tree9dafb4c7f735d9429ea461dc792933af87493c33 /contrib/spi/autoinc.c
parentdfbb88e3bbb526dcb204b456b9e5cfd9d10d0d0a (diff)
parentd5cb3bab564e0927ffac7c8729eacf181a12dd40 (diff)
Merge from PG master upto d5cb3bab564e0927ffac7c8729eacf181a12dd40
This is the result of the "git merge remotes/PGSQL/master" upto the said commit point. We have done some basic analysis, fixed compilation problems etc, but bulk of the logical problems in conflict resolution etc will be handled by subsequent commits.
Diffstat (limited to 'contrib/spi/autoinc.c')
-rw-r--r--contrib/spi/autoinc.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/contrib/spi/autoinc.c b/contrib/spi/autoinc.c
index 41eae4fdc4..8bf742230e 100644
--- a/contrib/spi/autoinc.c
+++ b/contrib/spi/autoinc.c
@@ -3,6 +3,7 @@
*/
#include "postgres.h"
+#include "access/htup_details.h"
#include "catalog/pg_type.h"
#include "commands/sequence.h"
#include "commands/trigger.h"
@@ -23,6 +24,7 @@ autoinc(PG_FUNCTION_ARGS)
int *chattrs; /* attnums of attributes to change */
int chnattrs = 0; /* # of above */
Datum *newvals; /* vals of above */
+ bool *newnulls; /* null flags for above */
char **args; /* arguments */
char *relname; /* triggered relation name */
Relation rel; /* triggered relation */
@@ -64,6 +66,7 @@ autoinc(PG_FUNCTION_ARGS)
chattrs = (int *) palloc(nargs / 2 * sizeof(int));
newvals = (Datum *) palloc(nargs / 2 * sizeof(Datum));
+ newnulls = (bool *) palloc(nargs / 2 * sizeof(bool));
for (i = 0; i < nargs;)
{
@@ -71,7 +74,7 @@ autoinc(PG_FUNCTION_ARGS)
int32 val;
Datum seqname;
- if (attnum < 0)
+ if (attnum <= 0)
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_ACTION_EXCEPTION),
errmsg("\"%s\" has no attribute \"%s\"",
@@ -102,23 +105,23 @@ autoinc(PG_FUNCTION_ARGS)
newvals[chnattrs] = DirectFunctionCall1(nextval, seqname);
newvals[chnattrs] = Int32GetDatum((int32) DatumGetInt64(newvals[chnattrs]));
}
- pfree(DatumGetTextP(seqname));
+ newnulls[chnattrs] = false;
+ pfree(DatumGetTextPP(seqname));
chnattrs++;
i++;
}
if (chnattrs > 0)
{
- rettuple = SPI_modifytuple(rel, rettuple, chnattrs, chattrs, newvals, NULL);
- if (rettuple == NULL)
- /* internal error */
- elog(ERROR, "autoinc (%s): %d returned by SPI_modifytuple",
- relname, SPI_result);
+ rettuple = heap_modify_tuple_by_cols(rettuple, tupdesc,
+ chnattrs, chattrs,
+ newvals, newnulls);
}
pfree(relname);
pfree(chattrs);
pfree(newvals);
+ pfree(newnulls);
return PointerGetDatum(rettuple);
}