dupetrigger now compatble to postgresql 7.2.*. thank you matthias
authoridfx <idfx>
Sun, 9 Mar 2003 21:26:53 +0000 (21:26 +0000)
committeridfx <idfx>
Sun, 9 Mar 2003 21:26:53 +0000 (21:26 +0000)
dbscripts/dupetrigger/Makefile-dist
dbscripts/dupetrigger/dupetrigger.c

index 9a0df1b..aa3cd0d 100755 (executable)
@@ -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
index 1683103..ef823fa 100755 (executable)
@@ -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)))
        {