/* Event-Add_Marriage.sql
2013-01-16 Tom Holden ve3meo

Adds a Marriage event to all couples lacking one.
No date, place or description. A private note is added.

*/
BEGIN TRANSACTION;

INSERT INTO EventTable
SELECT NULL AS EventID
	,300 AS EventType
	,1 AS OwnerType
	,FamilyID AS OwnerID
	,0 AS FamilyID
	,0 AS PlaceID
	,0 AS SiteID
	,'.' AS DATE
	,9223372036854775807 AS SortDate
	,0 AS IsPrimary
	,0 AS IsPrivate
	,0 AS Proof
	,0 AS STATUS
	,0 AS EditDate
	,CAST('' AS BLOB) AS Sentence
	,CAST('' AS BLOB) AS Details
	,CAST('{generated by SQLite query}' AS BLOB) AS Note
FROM FamilyTable
WHERE FamilyID NOT IN (
		-- Couples with Marriage Fact
		SELECT F.FamilyID
		FROM FamilyTable F
		INNER JOIN EventTable E ON F.FamilyID = E.OwnerID
			AND E.OwnerType = 1
			AND E.EventType = 300
		);

COMMIT TRANSACTION;