Hi,
I wrote the following code to create two tables, add a couple of triggers, the problem I am having is with the add_props_date trigger... when an existing record is already present in the table email i still want a record creating in the email props table, which works however the compid field is showing as -1 I need compid to have the value of hashid (the record which already exists). If i get 10 duplicate entries into the database, there will be only one record in the email table and 10 references to that in emailprops table
Hope this makes sense, here is my code:
Here are some screen shots showing what I get:
And this is what i want (with a little creative editing):
Thanks!
I wrote the following code to create two tables, add a couple of triggers, the problem I am having is with the add_props_date trigger... when an existing record is already present in the table email i still want a record creating in the email props table, which works however the compid field is showing as -1 I need compid to have the value of hashid (the record which already exists). If i get 10 duplicate entries into the database, there will be only one record in the email table and 10 references to that in emailprops table
Hope this makes sense, here is my code:
Code:
CREATE TABLE email (
hashid INTEGER PRIMARY KEY,
emailhash TEXT NOT NULL UNIQUE,
hash_date_added DATETIME
);
CREATE TABLE emailprops (
propsid INTEGER PRIMARY KEY,
compid INTEGER,
props_date_added DATETIME,
FOREIGN KEY (compid) REFERENCES email(hashid)
);
CREATE TRIGGER add_hash_date AFTER INSERT ON email
BEGIN
UPDATE email SET hash_date_added = DATETIME('NOW') WHERE hashid = new.hashid;
END;
CREATE TRIGGER add_props_date BEFORE INSERT ON email
BEGIN
INSERT INTO emailprops(compid, props_date_added) VALUES (new.hashid, datetime('now'));
END;
INSERT INTO email ( emailhash ) VALUES ( 'hello' );
INSERT OR IGNORE INTO email ( emailhash ) VALUES ( 'hello' );
Here are some screen shots showing what I get:
And this is what i want (with a little creative editing):
Thanks!