From ed37df176cb24f284a0ae0628598c37882915b11 Mon Sep 17 00:00:00 2001 From: mj Date: Thu, 27 Sep 2001 19:29:17 +0000 Subject: [PATCH] Renamed the trigger.c to dupetrigger.c to enlarge the namespace for additional triggers. Cleaned up Makefile and the other files. --- dbscripts/dupetrigger/INSTALL | 2 -- dbscripts/dupetrigger/Makefile | 21 ++++++++++++++------- dbscripts/dupetrigger/README | 8 ++++---- dbscripts/dupetrigger/{trigger.c => dupetrigger.c} | 0 dbscripts/dupetrigger/postgresql.sript | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-) rename dbscripts/dupetrigger/{trigger.c => dupetrigger.c} (100%) diff --git a/dbscripts/dupetrigger/INSTALL b/dbscripts/dupetrigger/INSTALL index 8571231f..e7687f7d 100755 --- a/dbscripts/dupetrigger/INSTALL +++ b/dbscripts/dupetrigger/INSTALL @@ -5,5 +5,3 @@ To install the trigger do the following: # psql -U postgres Mir < postgresql.script (This installs the the trigger binary and creates a new trigger.) - -# rm /tmp/trigger.so diff --git a/dbscripts/dupetrigger/Makefile b/dbscripts/dupetrigger/Makefile index ad1c52c7..6185ec2d 100755 --- a/dbscripts/dupetrigger/Makefile +++ b/dbscripts/dupetrigger/Makefile @@ -2,18 +2,25 @@ CC=gcc PGINC=/usr/include/postgresql +CFLAGS=-I$(PGINC) -trigger.so: trigger.o - $(CC) -shared -dynamic -o trigger.so trigger.o - cp trigger.so /tmp - chmod 755 /tmp/trigger.so +# If changed, also change postgresql.script +INSTALLDIR=../../../Mir/src -trigger.o: trigger.c - $(CC) -I$(PGINC) -c trigger.c -o trigger.o +install: dupetrigger.so + cp dupetrigger.so $(INSTALLDIR) + chmod 755 $(INSTALLDIR)/dupetrigger.so + # + # Now, change the path to dupetrigger.so in postgresql.script to the + # absolute path where dupetrigger.so is installed (this + # is typically ../../../Mir/src) + +dupetrigger.so: dupetrigger.o + $(CC) -shared -dynamic -o dupetrigger.so dupetrigger.o clean: - rm -rf trigger.o trigger.so + rm -rf dupetrigger.o dupetrigger.so tidy: clean diff --git a/dbscripts/dupetrigger/README b/dbscripts/dupetrigger/README index 58561771..a506867e 100755 --- a/dbscripts/dupetrigger/README +++ b/dbscripts/dupetrigger/README @@ -8,9 +8,9 @@ this somehow. Because Indymedia databases will hopefully grow big very fast, we want to do this check as fast as possible. So Mir simply issues the INSERT. By this INSERT statement, a trigger gets, -well, triggered that calculate a CRC-32 checksum of the comment and searches -for rows with the same checksum. If it finds the checksum, the INSERT gets -aborted. If the checksum isn't found, it is appended to the row and the -INSERT is executed. +well, triggered that calculates a CRC-32 checksum of the comment and +searches for rows with the same checksum. If it finds the checksum, the +INSERT gets aborted. If the checksum isn't found, it is appended to the row +and the INSERT is executed. The trigger works for INSERTs and UPDATEs. diff --git a/dbscripts/dupetrigger/trigger.c b/dbscripts/dupetrigger/dupetrigger.c similarity index 100% rename from dbscripts/dupetrigger/trigger.c rename to dbscripts/dupetrigger/dupetrigger.c diff --git a/dbscripts/dupetrigger/postgresql.sript b/dbscripts/dupetrigger/postgresql.sript index d1f43c44..28e9027c 100755 --- a/dbscripts/dupetrigger/postgresql.sript +++ b/dbscripts/dupetrigger/postgresql.sript @@ -1,5 +1,6 @@ \connect - postgres DROP FUNCTION dupecheck(); DROP TRIGGER dupetrigger ON comment; -CREATE FUNCTION dupecheck() RETURNS OPAQUE AS '/tmp/trigger.so' LANGUAGE 'C'; +CREATE FUNCTION dupecheck() RETURNS OPAQUE AS '/path/to/dupetrigger.so' LANGUAGE 'C'; CREATE TRIGGER dupetrigger BEFORE INSERT OR UPDATE ON comment FOR EACH ROW EXECUTE PROCEDURE dupecheck(); +CREATE INDEX comment_checksum_index on comment (checksum); -- 2.11.0