From: idfx Date: Sun, 9 Mar 2003 21:26:53 +0000 (+0000) Subject: dupetrigger now compatble to postgresql 7.2.*. thank you matthias X-Git-Tag: BEFORE_MERGE_1_1~229 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=0afe724376d470108d31e135f1fe5c7c47130eea;p=mir.git dupetrigger now compatble to postgresql 7.2.*. thank you matthias --- diff --git a/dbscripts/dupetrigger/Makefile-dist b/dbscripts/dupetrigger/Makefile-dist index 9a0df1b6..aa3cd0d5 100755 --- a/dbscripts/dupetrigger/Makefile-dist +++ b/dbscripts/dupetrigger/Makefile-dist @@ -4,7 +4,8 @@ PGINC=/usr/include/postgresql/server #PGVERSION=-DPG70 -PGVERSION=-DPG71 +#PGVERSION=-DPG71 +PGVERSION=-DPG72 # If changed, also change postgresql.script INSTALLDIR=/var/lib/postgres/data diff --git a/dbscripts/dupetrigger/dupetrigger.c b/dbscripts/dupetrigger/dupetrigger.c index 16831035..ef823fad 100755 --- a/dbscripts/dupetrigger/dupetrigger.c +++ b/dbscripts/dupetrigger/dupetrigger.c @@ -27,7 +27,7 @@ -#ifdef PG71 +#ifndef PG70 extern Datum dupecheck(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(dupecheck); #else @@ -117,7 +117,7 @@ static u_long crc32(u_char *buf, unsigned len) -#ifdef PG71 +#ifndef PG70 Datum dupecheck(PG_FUNCTION_ARGS) { TriggerData *trigdata = (TriggerData *) fcinfo->context; @@ -252,9 +252,20 @@ Datum dupecheck(void) } sprintf(query, "SELECT count(*) FROM %s WHERE checksum='%ld';", relation, crc); + if (debug_on) + { + elog(DEBUG, "dupecheck: %s", query); + } ret = SPI_exec(query, 2); - num = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull); - elog(DEBUG, "dupecheck: %s", query); + + if ((ret == SPI_OK_SELECT) && (SPI_processed > 0)) + { +#ifdef PG72 + num = (int) DatumGetInt64(SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull)); +#else + num = SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull); +#endif + } if ((ret == SPI_OK_SELECT) && (num > 0) && !(TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))) {