tupdesc = trigdata->tg_relation->rd_att;
/* Connect to SPI manager */
- if ((ret = SPI_connect()) < 0)
- ret = SPI_connect();
- elog(NOTICE, "dupecheck: SPI_connect returned %d", ret);
+ if ((ret = SPI_connect()) != SPI_OK_CONNECT)
+ {
+ elog(NOTICE, "dupecheck: SPI_connect returned error %d", ret);
+ }
// Now we are connected to the database's SPI manager
// We will now construct a string of some important row values.
{
rowstrlen += strlen(items[i]);
}
- rowstrlen++; // add space for 0-terminator
- rowstring = malloc(rowstrlen);
+ rowstring = malloc(rowstrlen+1); // add space for 0-terminator
if (rowstring == NULL)
{
// Big problem.
// items of the table record. Now we calculate the CRC-32 checksum
// of the rowstring
- crc = crc32(rowstring, rowstrlen - 1);
+ crc = crc32(rowstring, rowstrlen);
// Now we allocate some space and construct the SQL query
query = malloc(47 + 11 + 2 + 1); // SELECT part + crc32 + "';" + 0-term
if ((ret == SPI_OK_SELECT) && (num > 0))
{
- elog(NOTICE, "dupecheck: UBD prevented (dupe dropped)");
+ elog(NOTICE, "dupecheck: UBD detected, dupe dropped");
return PointerGetDatum(NULL);
}
else
Datum value;
char nulls = 0;
- elog(NOTICE, "dupecheck: Adding checksum to INSERT");
+// elog(NOTICE, "dupecheck: Adding checksum to INSERT");
attnum = SPI_fnumber(tupdesc, "checksum");
value = (Datum) crc;
rettuple = SPI_modifytuple(trigdata->tg_relation, rettuple, 1, &attnum, &value, &nulls);