MySQL Forums
Forum List  »  Replication

Non deterministic functions with replication
Posted by: Sam Post
Date: January 05, 2006 02:19PM

Hi,

I've been wading through the manual to figure out how to create a stored function that replicates from my master server to the slave, and is NOT deterministic.

It would look something like this:

****** FUNCTION:

CREATE FUNCTION addNewThing (name varchar(255), email varchar(255)) RETURNS INTEGER
BEGIN
DECLARE lastID INTEGER DEFAULT NULL;
INSERT INTO mytable (Name, Email) VALUES (name, email);
SELECT LAST_INSERT_ID() INTO lastID;
RETURN lastID;
END

****** USAGE:

SELECT addNewThing('My name', 'my email');
INSERT INTO other_table (owner_id, the_thing) VALUES (addNewThing('my name', 'my email'), 'the thing the person owns');

Is this possible? I don't want to have to call last_insert_id() in php every time, I want the ability to have the stored function take care of that and be able to have that function replicated to the slave.

Thanks,

Sam

Options: ReplyQuote


Subject
Views
Written By
Posted
Non deterministic functions with replication
5003
January 05, 2006 02:19PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.