I assume that you have two tables in your database, one called
Persons
and another called
Relations
, PersonID is a Foreign Key in the Relations table.
One approach is to create two stored procedures, one to store the person and one that stores the relations one by one.
From the first SP must return the primary key of the Persons table, and that variable is then used as a parameter together with the relation data into the second SP.
This way will require several transactions, but from an implementation point of view it is pretty clean.
Example
CREATE FUNCTION AddPerson(IN personID INT, IN personName VARCHAR(45)) RETURNS INT
BEGIN
RETURN lastInsertedPersonID;
END
CREATE PROCDURE AddRelation(IN personID INT, IN relationID INT, IN relationType INT)
BEGIN
END
You could also serialize the object Person as XML,
Examples of XML Serialization[
^], and send into the SP as a string and then use
XMLPARSE[
^] inside the SP to extract the data.
This will require a loop for extracting the data, see
LOOP Statements[
^]
The advantage of the second method is that you will only have one transaction, but on the other hand the code will be more complex.