Query is taking a very, very long time

I have been using this query for a quite a while now:
— Alternate Name Typos
Select f.FamilyID,
— 1 — Column B Gets the surname, given name and fathered for the fatherid from the famillytable for the fathers primary record. This is the husband.
(select n1.surname || “, ” || n1.given || ” ” || f.FatherID
from nametable n1
where f.fatherid = n1.ownerid — Get the father info from the primary record
and n1.isprimary = 1) as Husband,
— 2 — Column C Gets the surname, given name and mothered from the familytable for the motherid from the mothers primary record. This is the Wife.
(select n2.surname || “, ” || n2.given || ” ” || f.MotherID
from nametable n2
where f.motherid = n2.ownerid — Get the mother info from the primary record
and n2.isprimary = 1) as Wife,
— 3 — Column D — Gets the wife’s given name, maiden name, married name, husband’s given name and MothersID from the wife’s alternate name record. This is the Alternate Name.
(select n3.given || ” ” || n5.surname || ” ” || n5.suffix || ” ” || f.MotherID
from nametable as n3
inner join — get the father’s record from nametable file for the primary record
nametable as n4
on f.fatherid = n4.ownerid
and n4.isprimary = 1
inner join — get the surname and suffix from the nametable for the father’s primary record
nametable as n5
on “(” || n4.given || “)” = n5.suffix
where f.motherid = n3.ownerid — get the mother’s information from the alternate record
and n3.isprimary = 0) as Alternate,
— 4 — Column E — Gets the wife’ given name from the wife’s alternate record. This is the Alternate Maiden Name.
(select n6.given
from nametable n6
inner join — get the father’s record from nametable file for the primary record
nametable as n7
on f.fatherid = n7.ownerid
and n7.isprimary = 1
where f.motherid = n6.ownerid — get the mother’s information for the alternate record and the husbands Surname
and n6.isprimary = 0
and n7.surname = n6.surname) as Alt_Maiden_Name,
— 8 — Column I — Gets the wife’s surname from the alternate record. This is the Alternate Surname.
(select n18.surname
from nametable as n16
inner join — gets the father’s record from nametable file
nametable as n17
on (f.fatherid = n17.ownerid)
inner join — gets the father’s record from the nametable with the the suffix
nametable as n18
on “(” || n17.given || “)” = n18.suffix
and f.MotherID = n18.ownerid
and n17.surname = n18.surname
where f.motherid = n16.ownerid
and n16.isprimary = 0) as Alt_Surname,
— 6 — Column G — Gets the suffix for the wife from the alternate name record. This is the Alternate Suffix.
(select n12.suffix
from nametable as n10
inner join — get the father’s record from nametable file for the primary record
nametable as n11
on f.fatherid = n11.ownerid
and n11.isprimary = 1
inner join — get the suffix from the nametable for the father’s primary record
nametable as n12
on n10.given || ” ” || n11.surname = n12.given || ” ” || n12.surname
and “(” || n11.given || “)” = n12.suffix
where f.motherid = n10.ownerid
and n10.isprimary = 0) as Alt_Suffix,
— 5 — Column F — Gets the wife’s given name and surname from the wife’s primary record. This is the Primary Maiden Name.
(Select n9.given || ” ” || n9.surname
from nametable as n9
where f.motherid = n9.ownerid
and n9.isprimary = 1) as Pri_Maiden_Name,
— 9 — Column J — Gets the husband’s surname form the husband’s primary record. This is the husband’s surname.
(select n19.surname
from nametable as n19
where f.fatherid = n19.ownerid
and n19.isprimary = 1) as Primary_Surname,
— 7 — Column H — Puts parenthesis around the husbands given name from the primary records. This is the Primary Siffix.
(select “(” || n13.given || “)”
from nametable as n13
where f.fatherid = n13.ownerid
and n13.isprimary = 1) as Pri_Suffix
from familytable f
where f.FatherID is not 0 — fatherid is not 0
and f.MotherID is not 0 — motherid is not 0
–and substr(wife, 1, 1) <> “,” — the first position of the wife was not a comma
–and $Enterfamilyid = f.familyid — Inputs the familyid
–and familyid in(66, 1617)
order by wife, husband;

Up until a couple days ago, it took about 3 seconds to run. All of a sudden it is taking minutes like at least 5 minutes. I am using sqlite Expert 3.4.76.2306. I have tried Sqlite 5 also and i am getting the same thing. I created a GED and imported it back into rootsmagic. I have rebooted my machine. I have run ccleaner and malwarebytes. Nothing seems to work. Any ideas on what is happening or what I need to do?

I am adding a new SQL Tab and it is taking minutes.

Discussions & comments from Wikispaces site


ve3meo

Comments

ve3meo
23 November 2017 14:08:31

Something changed. Think back. Your last sentence suggests that it’s not the database or the query; rather the OS or the program. Maybe RAM has been overflowed into the swapdisk file. That would explain sluggish database but not the slow new tab. Run the Windows Task Manager and see what part of the system is saturating.


ve3meo

ve3meo
24 November 2017 04:54:07

I had a quick look at your script and ran it on both SQLite Expert Personal 4-32b and on SQLiteSpy and got similar results on a smallish database (729 records in NameTable of which only 170 are Alternate) ~200 milliseconds.

Explain Query Plan suggests that it could bog down because there are so many correlated sub-queries (9) involving a total of 16 SEARCHes. Fortunately, the optimiser applies an INDEX to all the SEARCHes else these would have become SCANs. A redesign to eliminate or reduce the CORRELATED SUBQUERIES could make a huge improvement on a large database.

A minor point perhaps is this. IsPrimary is already a logic value. There is no need to test that it =1 or =0. WHERE NOT IsPrimary produces the same result as WHERE IsPrimary=0; WHERE IsPrimary is one less operation than WHERE IsPrimary = 1.

And this may no longer be true. In early RM4+, I found that WHERE +IsPrimary was actually faster than WHERE IsPrimary. But that was due to an Indexing error on the part of the developer which, I believe, was corrected.

SQLite Expert Personal Edition Version 5.2.2.240 (x64) problem

I installed SQLite Expert Personal Edition Version 5.2.2.240 (x64).

external image user_none_lg.jpgve3meo Nov 12, 2017

What is your OS? Is it 32 or 64 bit. You can install 32 or 64 bit programs on a 64 bit OS but you cannot install a 64 bit program on a 32 bit system. 32 bit programs on a 64 bit system must be installed in “Program Files (x86)”; 64 bit programs go into “Program Files”.

I started SQLite Expert Personal Edition
I opened my database
I got a popup saying SQLite Library not loaded.
I click OK
When I checked the SQLite Library in the options it contained sqlite3.dll 3.21.0 [FTS3 FTS4 FTS5 RTREE]

ve3meo Nov 12, 2017

That looks right. But maybe the 32b/64b issue caused this error.

I entered the following in the SQL window:

select surname
from nametable;

ve3meo Nov 12, 2017

Don’t select a field that requires RMNOCASE until you resolve the basic issues. This just complicates the matter.

I got Database not connected

ve3meo Nov 12, 2017

because the SQLite Library didn’t load. Has nothing to do with unifuzz.

I did a right click on my database
I selected Load Extension
I selected the the File Name (C:Program DataMicrosoftWindowsStart MenuProgramsSQLite ExpertPersonal 5 – 64bitunifuzz.dll

ve3meo Nov 12, 2017

This is a path to a hyperlink, not to the file unifuzz.dll unless that’s where you put it. I think the best place for extensions is with the program. On my 64b Win 10 system, I have the 32b version 4 program and unifuzz in “C:Program Files (x86)SQLite ExpertPersonal 4”

I entered sqlite_extension_init for the Entry Point
I checked Auto
I clicked OK
I got the following: Could not load library: C:Program DataMicrosoftWindowsStart MenuProgramsSQLite ExpertPersonal 5 – 64bitunifuzz.dll%1 is not a valid Win32 application.
I tried doing the above but left Auto unchecked
I got an Access violation error

I have put the unifuzz.dll file in C:program FileSQLite Expert Personal 5 folder and did the above steps and got the same results.

I put the unifuzz.dll file in the folder where the rmgc file is and still got the same thing.

What am I doing wrong?

Should the library be unifuzz.dll instead of sqlite.dll? If so how do I change it?

ve3meo Nov 12, 2017

No.

Discussions & comments from Wikispaces site


ve3meo

unifuzz.dll is compatible only with the 32 bit version

ve3meo
12 November 2017 16:19:01

Using unifuzz.dll with SQLite Expert

So uninstall the 64b SQLite Expert. Install the 32b version and place unifuzz.dll in the same folder as the program.


momakid

momakid
12 November 2017 18:17:11

Is it possible to use the 64b SQLite Expert version with Rootsmagic 7.5? If so what do I need to do to make it work? I have a 64b machine so I would like to use the 64b version. But if it is not possible, I have no problem using the 32b version. Thank you so very much. You are a miracle worker.

Inline comments


ve3meo

Comment: What is your OS? Is it 32 or 64 bit. …

ve3meo
12 November 2017 16:15:20

What is your OS? Is it 32 or 64 bit. You can install 32 or 64 bit programs on a 64 bit OS but you cannot install a 64 bit program on a 32 bit system. 32 bit programs on a 64 bit system must be installed in “Program Files (x86)”; 64 bit programs go into “Program Files”.


ve3meo

Comment: That looks right. But maybe the 32b/6…

ve3meo
12 November 2017 16:15:21

That looks right. But maybe the 32b/64b issue caused this error.


ve3meo

Comment: Don’t select a field that requires RM…

ve3meo
12 November 2017 16:15:22

Don’t select a field that requires RMNOCASE until you resolve the basic issues. This just complicates the matter.


ve3meo

Comment: because the SQLite Library didn’t loa…

ve3meo
12 November 2017 16:15:23

because the SQLite Library didn’t load. Has nothing to do with unifuzz.


ve3meo

Comment: This is a path to a hyperlink, not to…

ve3meo
12 November 2017 16:15:23

This is a path to a hyperlink, not to the file unifuzz.dll unless that’s where you put it. I think the best place for extensions is with the program. On my 64b Win 10 system, I have the 32b version 4 program and unifuzz in “C:Program Files (x86)SQLite ExpertPersonal 4”


ve3meo

Comment: No.

ve3meo
12 November 2017 16:15:24

No.

Where is this data?

I am trying to put query together that will get the information for the Date, Place, Place Details, Description, Citation, and media fields on the following screen:

Pic 1.jpg
Pic 1

The put the following query together to get the above information:
select et.ownerid,
nt.surname,
nt.given,
et.eventid,
et.eventtype,
nt.birthyear,
ft.Name,
et.placeid,
et.siteid,
substr(et.date,4,4) as Ev_Date,
–(select pt.name
— from placetable pt
— where et.siteid = pt.placeid) as Place,
pt.name as Place,
site.name as Place_Details,
trim(et.details) as Description,
ml.mediaid,
ml.linkid,
–mm.mediatype,
(select m1.mediapath
from multimediatable m1
where ml.MediaID = m1.mediaid) as Path,
(select m2.mediafile
from multimediatable m2
where ml.MediaID = m2.mediaid) as File,
(select m3.caption
from multimediatable m3
where ml.MediaID = m3.mediaid) as Caption,
(Select s1.name
from sourcetable s1
where ct.sourceid = s1.sourceid) as Source,
(Select s2.actualtext
from sourcetable s2
where ct.sourceid = s2.sourceid) as Actual_Text,
(Select s3.comments
from sourcetable s3
where ct.sourceid = s3.sourceid) as Comments

from eventtable et,
placetable pt,
facttypetable ft,
nametable nt,
sourcetable st

left join medialinktable as ml
on et.ownerid = ml.ownerid

left join citationtable as ct
on et.ownerid = ct.ownerid

left join placetable as site
on et.siteid = site.placeid

where et.ownerid = nt.ownerid
and et.eventtype = ft.facttypeid
and et.placeid = pt.placeid
and ct.sourceid = st.sourceid
and et.EventType = 29
and et.ownerid = 1490

order by nt.surname, nt.given, ev_date
;

I am getting the Event Date, Place, Place Details and Description.

I am not getting the following information:

Pic 2.jpg
Pic 2

Nor this information:

Pic 3.jpg
Pic 3

I am getting the source but it is not correct. I am not getting anything for Actual_Text or Comments.
I am getting the filepath which appears to be correct. I am getting a filename and caption but they are not correct.

I am getting too many rows

I want a row for every eventtype of 29 from the eventtable. If there is a place, place detail, description, mediapath, mediafile, caption, source, actual_text or comments, that it appear in the query results. If there isn’t data, the field be blank but the row to be displayed.

I want to be able to sort it my surname, given and eventdate.

I am missing something somewhere. Can you point me in the right direction or tell me what I am doing wrong?

Discussions & comments from Wikispaces site


ve3meo

Will produce big results set

ve3meo
25 October 2017 22:10:39

Because for each event for a person, there can be multiple citations AND multiple media. If an event has 2 of each, there will be 4 rows; 3 of each, 9 rows… And if you are also after the Master Source media and/or the Source Details media for which there can be more than one in each case, then it can exponentiate even faster. Are you sure that is what you really want? It’s one reason why RM has all these sub-windows.


momakid

momakid
26 October 2017 02:26:13

I have residence events for attaching the census image. They do have the month and year of the census. There should be only one citation and on a few occasions 2 images. If there is more than one citation, then I need research it and delete the extras. But on a whole there should be only one. There should be multiple years on a lot of them. I am trying to determine which records are missing census images, which ones are missing citations and sources. Which ones are missing a census year.
A family member had a shoe box full of funeral cards. I scanned them and started attaching them to the death event. But I soon discovered most of those women names were married names. I didn’t know their maiden names. So I created alternate names consisting of given name and maiden name for the given name of the alternate record. The surname was the married name and the suffix was the husbands given name. I was now able to find a big majority of the women.
BUT i think that could affect my results. I am not going to restrict it to the primary record first but I have a feeling I am going to have to. I did do a query to see how many residence records there were and there were 3,414. I am trying to think of why I should not get at least that many records in my results. I want to get every residence event. I may need to restrict it to A thru G, H thru K, etc. I will dump the results into an excel spreadsheet and work from it.
I did discover that I needed to look at the eventid and ownertype of 2 for the citation and medialinktable .I am getting the path, file, caption and source but not the source details.
This is what I have now:
select et.ownerid,
nt.IsPrimary,
nt.surname,
nt.given,
et.eventid,
et.eventtype,
nt.birthyear,
ft.Name,
et.placeid,
et.siteid,
substr(et.date,4,4) as Ev_Date,
pt.name as Place,
site.name as Place_Details,
trim(et.details) as Description,
ml.mediaid,
ml.linkid,
–mm.mediatype,
(select m1.mediapath
from multimediatable m1
where ml.MediaID = m1.mediaid) as Path,
(select m2.mediafile
from multimediatable m2
where ml.MediaID = m2.mediaid) as File,
(select m3.caption
from multimediatable m3
where ml.MediaID = m3.mediaid) as Caption,
(Select s1.name
from sourcetable s1
where ct.sourceid = s1.sourceid) as Source,
(Select s2.actualtext
from sourcetable s2
where ct.sourceid = s2.sourceid) as Actual_Text,
(Select s3.comments
from sourcetable s3
where ct.sourceid = s3.sourceid) as Comments

from eventtable et,
placetable pt,
facttypetable ft,
nametable nt,
sourcetable st

left join medialinktable as ml
on et.eventid = ml.ownerid and ml.ownertype = 2

left join citationtable as ct
on et.eventid = ct.ownerid and ct.ownertype = 2

left join placetable as site
on et.siteid = site.placeid

where et.ownerid = nt.ownerid
and et.eventtype = ft.facttypeid
and et.placeid = pt.placeid
and ct.sourceid = st.sourceid
–and nt.isprimary = 0
and et.EventType = 29
–and et.ownerid = 1490

order by nt.surname, nt.given, ev_date;

Removing media from one person

I attached the 1920 Census to the people displayed in the window below:
Pic 1.jpg
I want to remove the media from Sophia only.and leave the media attached to the remaining people.

Actual Results:
I have Sophia’s record open, selected the media column for the fact, highlighted Sophia and pressed the Remove media button. It removes the media from everyone in the list. I have to re-add the media to everyone again. That is not good. That is a lot of wasted time.

Expected Results:
I expected to highlight the person I wanted to remove the media from. Select Remove media and the media only would be removed from only the person selected. I would expect the event to still be there. If I wanted to have the media removed from everyone, I would highlight/select everyone and then press remove media.

If the actual results is the way it is supposed to work, may I suggest an enhancement for the expected results?

Discussions & comments from Wikispaces site


ve3meo

Removing a media item from a specific person/event…

ve3meo
19 October 2017 04:12:54

Use Delete tag for what you wanted to have happen. The controls across the top are for the Media file or Album – Remove Media removes the media item from the Media Gallery and eliminates all its tags, as you discovered.

For RM user issues or questions having nothing to do with SQLite, please post to the RM Forum or FB Page.

Tom

Where is the data stashed

Pic 1.jpg
Pic 1
The explanation for the Details field in the EventTable of the Data Definitions states Content of Description field in Edit Person fact/event pane.
Pic 2.jpg
Pic 2
I take that to mean it should contain Marital Status: MarriedRelation to Head of House: Head in the above print screen.

I created the following query to get those details:

select et.eventid, et.eventtype, ft.Name, et.placeid, pt.name, substr(et.date,4,4), pt.name, et.Details, et.note

from eventtable et,
facttypetable ft,
placetable pt

where et.eventtype = ft.facttypeid
and et.placeid = pt.placeid
and ownerid = 70
;
I got the following results:
Pic 3.jpg
Pic 3

What file(s) do I find the Place details (address, Hospital, cemetery, etc.) field and the Descriptions: field on the Edit Person window above? I am trying to find where testing and Marital Status: MarriedRelation to Head of House: Head is stashed.

Discussions & comments from Wikispaces site


thejerrybryan

Place Details Location

thejerrybryan
18 October 2017 00:43:43

The Place Details are in the PlaceTable. The format is the same as for the Place info itself except that the PlaceType is 2 for PlaceDetails. The corresponding PlaceID is in the MasterID field. The basic idea is that you have to do a JOIN of the PlaceTable to itself so that you are joining the PlaceDetails values to the Place values on MasterID for the PlaceDetails and PlaceID for the Place.


ve3meo

ve3meo
18 October 2017 02:31:01

The text you are looking for is in the Blob type field Details. You need to convert the binary data to Text. See the different results between:
SELECT Details FROM EventTable;
and
SELECT TRIM(Details) FROM EventTable;

Tom


thejerrybryan

Descriptions field location

thejerrybryan
18 October 2017 00:46:59

This field has many names in RM, like all the multiple names for one person in a Russian novel. It is Description in the Edit Person screen, Details in the EventTable if you are using SQLite, and Value if you are in the Find/Search dialog in the RM user interface.


thejerrybryan

Individual Facts and Family Facts

thejerrybryan
18 October 2017 00:55:18

Your query for info about person 70 looks like it’s fine for individual events such as birth and death, but it will not work correctly for “family” event such as marriage. RM’s “family” events are really just for the couple, not for the children.

When you are first starting out with SQLite and RM, it’s probably easier to make two separate queries, one for individual events and one for couple events. The trick in the EventTable is to test the OwnerType field with a WHERE clause such that OwnerType = 0 for individual events and OwnerType = 1 for couple events. Individual events are easy. For couple events, OwnerID points to the FamilyTable rather than to the PersonTable. So depending on what you are trying to accomplish with couple events, you will probably have to JOIN the EventTable to the FamilyTable and the FamilyTable to the PersonTable or the NameTable (or to both).

Alternate Names List

I created alternate names for wives so I can find the wife with her married name.
I put the given and maiden name in the given for the alternate name. I put her husband’s surname in surname. I use Married as Name Type, Mrs. As Prefix and the husbands given name with parenthesis around it as the suffix.

I am using the following query to get the alternate names: (See Pic 1)
Pic 1.jpg
It works great if there is only one alternate name. It is a problem if there is more than one alternate name for each husband as displayed in Pic 1.

Pic 2.jpg
This is the print screen of Rootsmagic. (See Pic 2)

Pic 3.jpg
If I do a data view of the nametable and do a custom on ownerid of 590, I get the following: (See Pic 3)

Pic 4.jpg
If I do a data view of the familytable and do a custom on ownerid of 590, I get the following: (See Pic 4)

Pic 5.jpg
How do I get the original query to display the correct husband with the wife like displayed below? (See Pic 5)

Pic 6.jpg
I copy all of the results of the query into a spreadsheet to verify there aren’t any typos in the alternate name. (See Pic 6)

Is it possible to create the query to get the results contained in the spreadsheet? (Column O and Column P)

How could I put a where statement in thee query to select only certain ownerid’s? I need to be able to hard code it and to be able to input the ownerid.

Discussions & comments from Wikispaces site


ve3meo

Add Married Name as Alternate

ve3meo
15 September 2017 16:15:15

Are you acquainted with this script? Names+-+Add+Married


ve3meo

ve3meo
15 September 2017 16:22:41

Okay, I understand that you have already manually created these Alternate Names and are looking for a way to detect errors. Is that your objective?

If we are to tinker wit your script, it would be helpful if you would post the script file or copy the script onto the page.

Submit Your Problem #requestforhelp

Problem Queries
Create a New Page for your problem by editing this page, inserting a link from the Editor menu which will permit you to insert the text for the hyperlink and name your new page. After saving this revised page, click on your new link to create and edit your new problem page. On your new page, describe the problem and insert a link (Use the ‘Insert Images or Files’ button of the Editor bar) to the .rmgc or .ged file holding the sample data you are querying; this will allow you to upload the file. Discussion can then proceed around your page which can be revised as progress is made. Once solved, then your working query may be added to the RM4 Queries page.

Discussions & comments from Wikispaces site


thejerrybryan

Page Number Field in Citations using Freeform Source Template

thejerrybryan
05 June 2011 17:56:23

Using the Freeform source template, citations include a field called Page Number. To see it, edit an individual, go to the Citation Manager sub-window, choose a citation, and edit the citation. The page number field is towards the bottom of the sub-window in the green area, and is just under where it says “source details”.

I have been trying to figure out where this field is stored so that I may run an SQLite query against it, but I can’t it. It almost has to be in the CitationTable, but the only possibility in the Citation Table is a column entitled “Fields”. It display in hex in SQLiteSpy. I have a test database with only 5 citations. The page number is different in the 5 citations, and the hex data for Fields as displayed by SQLiteSpy is the same for all 5 citations. So the data must be somewhere else, or else SQLiteSpy is not displaying the entire contents of the Fields column in the CitationTable.

Jerry Bryan


ve3meo

ve3meo
05 June 2011 19:51:22

Use CAST to convert the BLOB to TEXT:
SELECT CAST(Fields AS Text) FROM CitationTable;

You will see a result like this for a Free Form template:
<?xml version=”1.0″ encoding=”UTF-8″?>
<Root><Fields><Field><Name>Page</Name><Value>Email 2 June 2008</Value></Field></Fields></Root>

Tom


craigg43

Add fact for color coding

craigg43
24 January 2013 03:12:45

I have a system of color coding all persons in my data base. I also have defined a fact call _color which I would like to add to each person to reflect their current color coding. Once that is done, I can use color coding for other purposes and still would be able to revert to my color coding system.
So I would like to be able to take all people and add a _color fact reflecting their current color coding.


ve3meo

ve3meo
24 January 2013 03:32:48

Adding a _color fact to store a current color code is one approach and lends itself to RM’s Search Persons tool. Is there any reason to use this fact to restore the color-coding? That would require a complementary query.

A second approach that is actually easier to implement is to snapshot the color settings to a new table in the database. Not searchable within RM. Easy to restore the setting from the table with a complementary query.

Tom


JoyceAE

Listing of Ref No’s for Spouses & Parents

JoyceAE
21 January 2014 22:51:51

What I want is a list (report) of everyone in my database with the following information:

Person’s RefNo, Person’s Name, Spouse’s RefNo, Spouse’s Name, Father’s RefNo, Father’s Name, Mother’s RefNo & Mother’s Name

For example:

Person’s Spouse’s Father’s Mother’s
RefNo Name RefNo Name RefNo Name RefNo Name
H456 George Harris H717 Ed Harris L954 Edith Lister No spouse
J001 Joyce Smith M124 Fred Brown J002 Bill Smith G056 Mary Good Spouse, father & mother
M546 Harry Mead M856 Roy Mead Only a father
R563 Edith Royce W067 Angela Woodman Only a mother

If the person does not have a spouse then that information should be blank. The same thing goes for either of the person’s father or mother.

Can someone point me to an SQL query that might provide this kind of information? Right now, I am trying to maintain this information in an Excel spreadsheet but it is very labour-intensive and prone to errors and discrepancies. Any help on this would be greatly appreciated.


wegm

wegm
07 May 2015 20:25:34

This should do what you want:

— Listing of Ref No’s for Individuals and Spouses & Parents

SELECT
PersonTable.PersonID AS [PersonsRefNo],
CASE
WHEN ifnull(NameTable.Prefix, ”) = ”
THEN ”
ELSE NameTable.Prefix || ‘ ‘
END || CASE
WHEN ifnull(NameTable.Given, ”) = ”
THEN ”
ELSE NameTable.Given || ‘ ‘
END || CASE
WHEN ifnull(NameTable.Nickname, ”) = ”
THEN ”
ELSE ‘(‘ || NameTable.Nickname || ‘) ‘
END || ifnull(NameTable.Surname, ”) || CASE
WHEN ifnull(NameTable.Suffix, ”) = ”
THEN ”
ELSE ‘, ‘ || NameTable.Suffix
END AS [PersonsName],
CASE
WHEN PersonTable.Sex = 0
THEN famSpouse.MotherID
ELSE famSpouse.FatherID
END SpouseRefsNo,
CASE
WHEN ifnull(spouseName.Prefix, ”) = ”
THEN ”
ELSE spouseName.Prefix || ‘ ‘
END || CASE
WHEN ifnull(spouseName.Given, ”) = ”
THEN ”
ELSE spouseName.Given || ‘ ‘
END || CASE
WHEN ifnull(spouseName.Nickname, ”) = ”
THEN ”
ELSE ‘(‘ || spouseName.Nickname || ‘) ‘
END || ifnull(spouseName.Surname, ”) || CASE
WHEN ifnull(spouseName.Suffix, ”) = ”
THEN ”
ELSE ‘, ‘ || spouseName.Suffix
END AS [SpousesName],
famParents.FatherID AS [FathersRefNo],
CASE
WHEN ifnull(FatherName.Prefix, ”) = ”
THEN ”
ELSE FatherName.Prefix || ‘ ‘
END || CASE
WHEN ifnull(FatherName.Given, ”) = ”
THEN ”
ELSE FatherName.Given || ‘ ‘
END || CASE
WHEN ifnull(FatherName.Nickname, ”) = ”
THEN ”
ELSE ‘(‘ || FatherName.Nickname || ‘) ‘
END || ifnull(FatherName.Surname, ”) || CASE
WHEN ifnull(FatherName.Suffix, ”) = ”
THEN ”
ELSE ‘, ‘ || FatherName.Suffix
END AS [FathersName],
famParents.MotherID AS [MothersRefNo],
CASE
WHEN ifnull(MotherName.Prefix, ”) = ”
THEN ”
ELSE MotherName.Prefix || ‘ ‘
END || CASE
WHEN ifnull(MotherName.Given, ”) = ”
THEN ”
ELSE MotherName.Given || ‘ ‘
END || CASE
WHEN ifnull(MotherName.Nickname, ”) = ”
THEN ”
ELSE ‘(‘ || MotherName.Nickname || ‘) ‘
END || ifnull(MotherName.Surname, ”) || CASE
WHEN ifnull(MotherName.Suffix, ”) = ”
THEN ”
ELSE ‘, ‘ || MotherName.Suffix
END AS [MothersName]
FROM
PersonTable
INNER JOIN NameTable ON PersonTable.PersonID = NameTable.OwnerID AND NameTable.IsPrimary = 1
LEFT JOIN FamilyTable famSpouse ON (
(
PersonTable.Sex = 0
AND famSpouse.FatherID = PersonTable.PersonID
)
OR (
PersonTable.Sex = 1
AND famSpouse.MotherID = PersonTable.PersonID
)
)
LEFT JOIN NameTable spouseName ON spouseName.IsPrimary = 1
AND (
(
PersonTable.Sex = 0
AND famSpouse.MotherID = spouseName.OwnerID
)
OR (
PersonTable.Sex = 1
AND famSpouse.FatherID = spouseName.OwnerID
)
)
LEFT JOIN ChildTable ON ChildTable.ChildID = PersonTable.PersonID
LEFT JOIN FamilyTable famParents ON famParents.FamilyID = ChildTable.FamilyID
LEFT JOIN NameTable FatherName ON famParents.FatherID = FatherName.OwnerID AND FatherName.IsPrimary = 1
LEFT JOIN NameTable MotherName ON famParents.MotherID = MotherName.OwnerID AND MotherName.IsPrimary = 1
ORDER BY
PersonTable.PersonID,
CASE
WHEN PersonTable.Sex = 0
THEN famSpouse.WifeOrder
ELSE famSpouse.HusbOrder
END
–LIMIT 100
;


niall15

Home Person

niall15
26 May 2015 17:01:15

How do I find the Home Person who is not necessarily PersonId 1?
Cheers
Niall


ve3meo

ve3meo
26 May 2015 17:53:21

It is stored in record 1 of the ConfigTable in the XML “file” stored as a Blob in the DataRec field, e.g.,
<Root><Version>6000</Version><RootPerson>1</RootPerson><Las…

This query will let you inspect the XML data
SELECT *, CAST(DataRec AS TEXT) FROM `ConfigTable` WHERE 1 LIMIT 100;

Tom


boltongenes

SQLite query required that lists Citation Details in separate columns

boltongenes
29 November 2015 02:42:23

I have looked at the Source queries but find all the ones with Citation Fields in them list all the fields together in one cell. I would like a query that lists the citation fields in separate columns. As the list of citation fields can be different between any two sources the query would have to be limited to the user specifying one of the following:

1. which Source Template to run the query for eg Basic Ancestry Database Template ( where I have multiple Master Sources based on a single Source Template it would include all of those sources), or
2. which specific Master Source for eg My English Birth Certificates (from the Master Source List).
Fields required:

RecNo, Source Name, Surname, Given Name, OwnerID, Event Type, Cit Field 1, Cit Field 2, Cit Field 3,….etc, Citation Quality

Any help would be appreciated.

thanks
Anne-Marie


ve3meo

ve3meo
29 November 2015 05:17:41

That is likely beyond the capabilities of the SQLite language and would require a higher level language and processing. At least, it is beyond me. The problem is that the column names and values you want are in XML in one column and defined by a cell in another table. SQLite does not have any native XML support.


spR6sMtno

Database Schema

spR6sMtno
06 March 2016 11:14:06

Hi folks!

I work with DBs for a few years now, but the desing of the RM6 DB is not clear for me. And I’m not in genealogy – I do this for my wife.

Currently I work on a program that imports a RM DB and generates a graphical view of the relationships for direct ancestors. But I have trouble always detecting the correct parents, and this is where I need your assistance.

I have a name, and using nametable.ownerid, I go to the person. Then the problem begins. There are at least three different tables where I could look up the parents:
childtable ( … where childtable.childid = persontable.personid) (I dont belive this table really helps me)
familytable ( select fatherid, motherid from persontable where familytable.childid = persontable.personid)
parenttable (select parentid from persontable where persontable.personid = nametable.ownerid).

Ok, enough confusion.

What’s the correct way to look up a person’s parents?

Thank you four your help!


ve3meo

ve3meo
09 March 2016 20:36:30

Just received notification of your message. Also am not able to access SQLite at moment so this is from memory and may not be accurate. Yes, PersonTable.PersonID = ChildTable.ChildID to find FamilyID WHERE RelFather =0 AND RelMother =0 to get birth parental couple. Then ChildTable.FamilyID = FamilyTable.FamilyID to get RINs of birth parents. Then FamilyTable.FatherID = NameTable.OwnerID WHERE NameTable.IsPrimary to get name of Father and likewise for mother.


Ksquared333

Merge unknown spouses

Ksquared333
05 February 2017 23:24:06

I have a good number of people where one of the spouses is unknown (usually the wife). When I imported to RM (from The Master Genealogist) a separate unknown spouse was assigned to each of the children. For instance, in TMG I had John Smith with 1 unknown wife and 5 children. In RM I have John Smith with 5 unknown wives, each with 1 child. I need a SQLite that will merge the children under the known spouse and combine all the unknown spouses.

Thanks!


Ksquared333

Ksquared333
19 February 2017 23:52:54

So I did that. I backed up my original and then restored the one you sent. I put the guy I was having trouble with in the Family View and it worked fine. Then I started checking other RINs from my list. It was all going fine until I tried 10019 and the same thing happened. When in the Family View I got a blank Family View. I closed the database and reopened it. Navigated to him through his grandparents and parents this time instead of using the Explorer, but I still got a blank Family View when I made him (10019) the primary. This isn’t happening on databases that I haven’t run the script on, so I don’t think it’s my system or my copy of RM. Would you mind having a further look around the database to see if it happens to you after you’ve looked at several. I think it happened on the 5th one I looked at. I looked at
14284, 13770, 13784, 10012, then 10019 and the blank Family View happened.


momakid

Alternate name problem

momakid
24 July 2017 13:00:10

In entering names in the suffix field for Alternate Name with name type Married, I entered some names like ( Doe Sally). With a space between the parenthesis and the D. I did the following query and got the people I wanted:
Select suffix
from nametable
where suffix like ‘( %’;

A space between the parenthesis and the percent.

So I created the following update query:
update nametable
set suffix = ‘(%’
where suffix like ‘( %’;

the problem is it wiped the names out and put (% in the suffix field.

What should the update query have been?
What query can I run to make it (Doe Sally) again?

When I run the following query:
Select suffix
from nametable
where suffix like ‘(%’;

I get the following results:
(Doe Sally)
(%
(White Snow)

I want the entries with (% fixed. Of course it would be OK to update all suffix entries because I am sure there may be some typos.

If I wanted to change the suffix name to (Sally Doe) what would the update query be? I do have husbands who have no wives and wives that have no husbands. I do not want a suffix entry in those.


ve3meo

ve3meo
24 July 2017 19:52:54

Always make a copy or backup before you modify the database. That’s the easiest way to get back to where you were so you can try again.

Use a SELECT to evaluate the expression you draft as an UPDATE before applying the UPDATE. For example, you would have seen that your UPDATE would produce the results you got from:
SELECT ‘(%’ AS Suffix where suffix like ‘( %’;

The % wild card is only a wild card, not a memory variable. You need to use the REPLACE() function:
SELECT REPLACE(Suffix, ‘( ‘, ‘(‘) AS Suffix where suffix like ‘( %’;
If satisfied, then:
UPDATE NameTable SET Suffix = REPLACE(Suffix, ‘( ‘, ‘(‘) AS Suffix where suffix like ‘( %’;

I’m unclear whether you are asking for a way to swap the first and last names already entered in Suffix or a way to populate the Suffix with the Given and Married Surname from the database records. The former would count on there being an existing Suffix entry having only two names with a space separating them. The latter would require that there be an Alternate Name fact with its type set to Married; alternatively, it would have to invent the Married Surname from the husband’s Surname. Then there is the question of handling multiple spouses – multiple Surnames.

Tom


faliondg

Fix for marriages imported thru Ancestry TreeShare _ invalid IDs cause _[Couple] were married_ sentences

faliondg
18 January 2018 21:12:03

I have 34 marriage records in my RM file with a sentence that begins with “[couple] married on…” instead of the spouse’s names. All affected marriages were from records added in Ancestry and pulled into RM. I’ve narrowed down the problem in the data: there are marriage events for each of the spouses, but the OwnerType is 0, not 1, and the FamilyID is 0 instead of the FamilyID for the couple.

Below are the changes I developed. I’ve verified the data afterwards, by data dumps and printing the narrative reports. I had to do this as a multi-step process; there may be a more way to code the SQL but I’m sure this worked.

— test table development below
— create temporary table to hold problem records

DROP TABLE IF EXISTS TesttableEventTable ;

CREATE TEMP TABLE TesttableEventTable AS
Select *
FROM EventTable
where EventType = 300
and OwnerType <> 1
Order by Date;

— this SQL Identifies the two rows where individuals also have a valid marriage record (these records to be deleted)
— and stores the data into a temporary testing table:
DROP TABLE IF EXISTS TestEventsToDELETE
;
CREATE TEMP TABLE TestEventsToDELETE AS

select * from TestTableEventTable T
Where T.OwnerID in
(Select F.FatherID from FamilyTable F
INNER JOIN EventTable E on F.FamilyID = E.OwnerID
AND E.OwnerType = 1
And E.EventType = 300
)
UNION
select * from TestTableEventTable T
Where T.OwnerID in
(Select F.MotherID from FamilyTable F
INNER JOIN EventTable E on F.FamilyID = E.OwnerID
AND E.OwnerType = 1
And E.EventType = 300
)

;
— END this SQL stores the above data into a temporary testing table

— this SQL stores the IDs to be updated into a temporary testing table:
DROP TABLE IF EXISTS TestEventsToUPDATE
;
CREATE TEMP TABLE TestEventsToUPDATE AS

Select EventID
FROM TesttableEventTable
where (EventType = 300
and OwnerType <> 1)
AND EventID not in (Select EventID from TestEventsToDELETE)
GROUP BY Date
HAVING ( COUNT (Date) > 1)
ORDER BY Date;
— END this SQL stores the IDs to be updated into a temporary testing table

— this SQL creates a second test table to run tests against and compare to first:
DROP TABLE IF EXISTS TesttableEventTable2
;
CREATE TEMP TABLE TesttableEventTable2 AS
Select *
FROM EventTable
where EventType = 300
and OwnerType <> 1
Order by Date;
— END this SQL creates a second test table to run tests against and compare to first

DROP table if exists TestEventsChangeData;

CREATE TEMP TABLE TestEventsChangeData
AS
select TETU.EventID,
TTET.OwnerID,
F.FamilyID
from TestEventsToUPDATE TETU, TestTableEventTable TTET, FamilyTable F
where TETU.EventID = TTET.EventID
And ((F.FatherID = TTET.OwnerID) OR (F.MotherID = TTET.OwnerID))
;

— These three steps, run in order, solve the problem:

BEGIN TRANSACTION;

— set OwnerID in EventTable to Family ID from FamilyTable
UPDATE EventTable

SET
OwnerID = (SELECT TestEventsChangeData.FamilyID
FROM TestEventsChangeData
WHERE TestEventsChangeData.EventID = EventTable.EventID)
WHERE
EXISTS (
SELECT *
FROM TestEventsChangeData
WHERE TestEventsChangeData.EventID = EventTable.EventID
)
;

— set OwnerType in EventTable to 1 instead of 0
UPDATE EventTable
SET
OwnerType = (SELECT 1
FROM TestEventsChangeData
WHERE TestEventsChangeData.EventID = EventTable.EventID)
WHERE
EXISTS (
SELECT *
FROM TestEventsChangeData
WHERE TestEventsChangeData.EventID = EventTable.EventID
)
;

— Delete remaining invalid records
Delete from EventTable
where EventType = 300
and OwnerType <> 1
;

COMMIT;


Trob2

Sources merged in error

Trob2
04 July 2018 19:55:27

I have accidentally merged two similar sources and now regret it!

This relates to a parish baptism, marriage and burial data for my local area. I set up separate free-form Sources for each of the three elements. Unfortunately I now have only two sources as I somehow managed to merge the baptism and burial templates.

For obvious reasons I only used the baptism Source for Birth or Baptism events and the burial Source for Death or Burial events.

It is a very simple job to recreate the two original source templates and as stated above it’s quite simple to identify which source should be used for each event.

Would it be possible to create a query which would find instances of the merged source and rewrite them (using the relevant event as key) using the correct Source template – without losing any of the individual detail data?

Thanks in advance for any help you can offer.I’m using RM version 7.5.7.0 BTW.


ve3meo

ve3meo
05 July 2018 02:58:12

The regret stems from not having a backup just prior to the merge or you’ve done a lot of changes since then before realising the error of your ways… Familiar story!

You’ll start by looking up the merged source Name in the SourceTable and noting the value of its SourceID. We’ll call this variable “SourceIDold” in the SQL statements that follow; you will substitute the value where the name is written.

Likewise for the Name of the new Birth-Baptism source to sub for “SourceIDnew”. (You don’t need a new source for the Death-Burial source – just edit the merged source.

From the FactTypeTable, the Birth and Baptism types have FactTypeID of 1 and 7 respectively.

The CitationTable points each citation to a Master Source via SourceID and to a record in the EventTable via OwnerID when OwnerType=2.

The EventTable points to a record in the FactTypeTable via its EventType value.

So a list of all Citation records of the merged source for Birth-Baptism events can be found by this query:

DROP VIEW IF EXISTS BirthCitations
;
CREATE TEMP VIEW BirthCitations AS
SELECT CitationID FROM CitationTable C
JOIN EventTable E ON C.OwnerID = E.EventID AND C.OwnerType = 2
WHERE C.SourceID=SourceIDold –plug in your value for the merged source
AND E.EventType IN (1,7)
;

–Look under Views to see the resulting list.
–Then transfer the SourceID for this list to that of your new Birth-Bapt source with this statement.

UPDATE CitationTable
SET SourceID = SourceIDnew –plug in your value
WHERE CitationID IN (SELECT CitationID FROM BirthCitations)
;

That should have repointed the Birth-Bapt citations to the new Birth-Bapt source. Now you can edit the merged source in RM to be the Death-Burial source. You’ll be editing only the Master Source (yellow) fields.

CAUTION – you will make a backup or a copy of your database first. I have tested these statements for syntax errors but not for actual results.

Good luck!

Tom

Query to Add Parents Events to RM Database #facttypes #events #sharedevent

I have recently added a Parents “fact” to everyone in my RM database who has parents. These Parents events really are new rows added to the EventTable, even though parentage is already denoted in RM by entries in the ChildTable joined with entries in the FamilyTable. The reasons for the new events are two-fold. First, it provides a good place in the RM user interface to attach evidence of parentage. Second, it improves RM narrative reports. A person’s parents are listed explicitly as a fact in a narrative report. The evidence of parentage appears with its respective Parents fact in a narrative report. And a “birth of child” event appears in a narrative report in the parents’ timelines.

The parents fact looks something like the following in my narrative reports.

1. Elza Cordelia (Elzie) Peters12.
Birth: 21 Dec 1898, Anderson County, Tennessee.12
Parents: Alva Edward Peters and Sallie Jane Cole.

The birth of child role looks something like the following in my narrative reports.

1. Alva Edward Peters13.
Birth: 14 Oct 1870, Scarbrough, Anderson County, Tennessee.1,46
Marriage: 28 Nov 1893, Anderson County, Tennessee, age 23, to Sallie Jane Cole.1,3
Birth of Child: 21 Dec 1898, Elza Cordelia (Elzie) Peters.

In order to make this work, a Parents fact has to be added to RM’s FactTypeTable from the RM user interface via Lists->Fact Type List. A sentence template must be added for the Principle role for the Parents fact. In addition, a Parent role must be added to the Parents fact.

Because I use point form sentences, my two sentence templates for the Principle and Parent role for the Parents fact are as follows.

{cr}
<b>Parents:</b>< [Parent].>
 
{cr}
<b>Birth of Child: </b> <[Date:plain]><, [Person:Full]>.

where {cr} is an actual carriage return and line feed sequence entered into the template simply be depressing the Enter key on the PC’s keyboard. The [Parent] variable works in an amazing way in RM because it lists both persons with the Parent role (the father and mother) and separates their names with “and”. The parents names are stored in the Description field of the Parents fact, so the [Parent] variable could be replaced by the [Desc] variable, but the use of the [Parent] variable causes the parents names to included in the Index of Names in a narrative report.

I used the following query to create the Parents fact for everybody in the database who has parents, with the following exceptions. The query is designed not to add the Parents fact if it’s already there. The query is designed not to add the Parents fact for dummy people in my database. The query is designed not to add the Parents fact for people without Birth facts because it uses the Birth fact to create a date and sortdate for the Parents fact.

Jerry

-- Create a view of the EventTable
-- containing only Parents events.
-- This view will be used to prevent
-- creating a Parents event for
-- any individuals who already have
-- a Parents event. The main data needed
-- is the PersonID of the individuals
-- who already have a Parents event.
-- The PersonID manifests itself in
-- the EventTable as OwnerId.
 
 
DROP VIEW IF EXISTS ParentEventView;
CREATE TEMP VIEW ParentEventView AS
SELECT E.*
FROM EventTable AS E
       JOIN
     FactTypeTable AS FT  ON FT.FactTypeID = E.EventType
     WHERE FT.Name LIKE('Parents');
 
 
 
-- Create a view of the EventTable
-- containing only Birth events.
-- These events provides an initial list
-- of candidates of people to receive
-- a Parents event. Also, many of the
-- fields for newly created Parents
-- events will be replicated from the
-- corresponding Birth event.
 
DROP VIEW IF EXISTS BirthEventView;
CREATE TEMP VIEW BirthEventView AS
SELECT Birth.*
FROM EventTable AS Birth
       JOIN
     FactTypeTable AS FT  ON FT.FactTypeID = Birth.EventType
     WHERE FT.Name LIKE('Birth');
 
 
-- Create a view of Birth events for people
-- that don't have a Parent event. This is the
-- first filtering on the list of candidates
-- of people to receive a Parents event.
 
 
DROP VIEW IF EXISTS BirthWithoutParentsEventView;
CREATE TEMP VIEW BirthWithoutParentsEventView AS
SELECT Birth.*
FROM BirthEventView AS Birth
          LEFT JOIN
     ParentEventView AS Parent ON Parent.Ownerid = Birth.OwneriD
WHERE Parent.OwnerID IS NULL;
 
-- Create a view of the NameTable
-- containing only primary names.
-- This view will be a source of
-- the names needed for the newly
-- created Parents events and will
-- prevent any names other than the
-- primary ames from being loaded
-- into -- Parents events. This
-- view also prevents Parents events
-- from being created for any dummy
-- people, designated with an asterisk
-- in the name.
 
DROP VIEW IF EXISTS NameView;
CREATE TEMP VIEW NameView AS
SELECT N.*
FROM NameTable AS N
WHERE N.IsPrimary = 1
  AND N.Surname NOT LIKE('%*%')
  AND N.Given   NOT LIKE('%*%');
 
-- This view performs most of the
-- main processing for this project.
-- It determines which people actually
-- do have parents. Actually having
-- parents is based on being in the
-- ChildTable and has nothing to do
-- with whether a Parents event exists
-- or not. This list of people with parents
-- is then matched against people who are not
-- dummy people, who do have birth
-- events, and who don't already have
-- Parents events. This view also
-- develops the data that will need to
-- be stored in the newly created
-- Parents events.
 
 
DROP VIEW IF EXISTS ChildParentsView;
CREATE TEMP VIEW ChildParentsView AS
SELECT Child.ChildID,  Child.Given  || ' ' || Child.Surname  AS ChildName,
       Father.FatherID, Father.Given || ' ' || Father.Surname AS FatherName,
       Mother.MotherID, Mother.Given || ' ' || Mother.Surname AS MotherName,
       CASE
       WHEN Father.FatherID = 0 THEN Mother.Given || ' ' || Mother.Surname
       WHEN Mother.MotherID = 0 THEN Father.Given || ' ' || Father.Surname
       ELSE Father.Given || ' ' || Father.Surname || ' and ' || Mother.Given || ' ' || Mother.Surname
       END CombinedNames,
       B.DATE,
       B.SortDate,
       B.EditDate
 
FROM  (  SELECT C.RecID,
                C.ChildID,
                N.Given,
                N.Surname
         FROM   ChildTable AS C
                  JOIN
                NameView AS N ON N.Ownerid = C.ChildID
      ) AS Child
 
           JOIN
 
      (  SELECT C.RecID,
                FM.FatherID,
                N.Given,
                N.Surname
         FROM ChildTable AS C
                JOIN
              FamilyTable AS FM ON C.FamilyID =  FM.FamilyID
                LEFT JOIN
              NameView AS N ON N.OwnerID = FM.FatherID
      ) AS Father ON Father.RecID = Child.RecID
 
           JOIN
 
      (  SELECT C.RecID,
                FM.MotherID,
                N.Given,
                N.Surname
         FROM   ChildTable AS C
                  JOIN
                FamilyTable AS FM ON C.FamilyID =  FM.FamilyID
                  LEFT JOIN
             NameView AS N ON N.OwnerID = FM.MotherID
       ) AS Mother ON Mother.RecID = Father.RecID
 
            JOIN
 
       BirthWithoutParentsEventView AS B ON B.OwnerID = Child.ChildID;
 
-- The data from the ChildParentsView needs to be used
-- twice, once to load Parents events into the EventTable
-- and again to load roles into the WitnessTable. The
-- Parents events have to be loaded into the EventsTable
-- first, and one Insert statment in SQLite cannot load
-- data into two tables. However, loading Parents Events
-- into the EventTable will cause the ChildParentsView
-- not to produce the correct results the second time it
-- is used. Therefore, the results from applying the
-- ChildParentsView will be saved into a temporary table
-- called ChildParentsTable. As a table instead of a view,
-- the data in ChildParentsTable can be used two different
-- times and remain the same data both times it is used.
 
DROP TABLE IF EXISTS ChildParentsTable;
CREATE TEMP TABLE ChildParentsTable
(ChildID,ChildName,FatherID,FatherName,MotherID,Mothername,CombinedNames,DATE,SortDate,EditDate);
INSERT INTO ChildParentsTable
(ChildID,ChildName,FatherID,FatherName,MotherID,Mothername,CombinedNames,DATE,SortDate,EditDate)
SELECT CP.*
FROM ChildParentsView AS CP;
 
 
 
-- Load new Parents facts into the EventTable.
 
INSERT OR ROLLBACK INTO EventTable
SELECT NULL AS EventID
    ,(SELECT FT.FactTypeID FROM FactTypeTable AS FT WHERE FT.Name LIKE('Parents') ) AS EventType
    ,0 AS OwnerType
    ,ChildID AS OwnerID
    ,0 AS FamilyID
    ,0 AS PlaceID
    ,0 AS SiteID
    ,DATE AS DATE
    ,SortDate AS SortDate
    ,0 AS IsPrimary
    ,0 AS IsPrivate
    ,0 AS Proof
    ,0 AS STATUS
    ,EditDate AS EditDate
    ,CAST('' AS TEXT) AS Sentence
    ,CAST(CombinedNames AS TEXT) AS Details
    ,CAST('' AS TEXT) AS Note
 FROM ChildParentsTable;
 
 
 
 --   ===========================================================================================================
 --     The following is adapted from Tom Holden to rank same date sort dates.
 --
 --     There are a number of changes by Jerry Bryan that are specific to his
 --     use case.
 --
 --        * The list of fact types which are supported is greatly increased.
 --        * Sort dates including ranked sort dates (date-n) are ranked and even re-ranked
 --          whether or not they match the date from from the fact itself, provided only
 --          that the sort dates in question match each other.
 --             . This allows same "ABT" dates to be ranked.
 --             . This allows same "year only" dates to be ranked if the sort date is
 --               1 July of the year.
 --             . This allows same "year and month only" dates to be ranked if the
 --             . sort date is the 15th of the month.
 --
 --   ===========================================================================================================
 
/* SortDateSameDayOrderCustom.sql
   2011-12-20 ve3meo
   Alters SortDates of any set of Fact types
   to a natural order when any pair or more occur on the same date.
   Could be extended to order other facts also. SortDates are effectively assigned
   (by arithmetical offsets) an absolute suffix -1, -2, ... related to the rank of the FactType.
   Affects only those events whose SortDates correspond to the Fact Date, as computed
   by a Date encoding algorithm. The algorithm does not handle Date modifiers so not all
   Event dates are handled, e.g. "Bef 1960".
*/
DROP TABLE IF EXISTS TmpFactOrder
;
CREATE TEMP TABLE IF NOT EXISTS TmpFactOrder
(Rank INTEGER PRIMARY KEY, FactName TEXT)
;
 
/* list of Fact Names, standard and custom, to be sorted, in rank order.
   Revise the list to suit your needs */
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Birth');
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Parents');             -- added by JB
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Birth Certificate');   -- added by JB
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Christen');
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Baptism');
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Death');
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Obituary');            -- moved up by JB
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Death Certificate');   -- added by JB
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Funeral');
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Cremation');
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Burial');
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Burial Inscription');  -- Added by JB
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Burial GPS');          -- Added by JB
INSERT INTO TmpFactOrder (Rank, FactName) VALUES (NULL, 'Memorial');
/* revise SortDates */
UPDATE EventTable
SET SortDate = SortDate
  -6692012023  -- this offset goes to Date-1 if the event is a ranked event
  *( (
      SELECT Rank
      FROM TmpFactOrder,
           FactTypeTable
      WHERE FactName LIKE Name
      AND FactTypeID = EventType
      )>0
    )
  +1048576  -- this offset adds steps of 1 to Date-1 multiplied by (rank-1)
  *( (
      SELECT Rank
      FROM TmpFactOrder,
           FactTypeTable
      WHERE FactName LIKE Name
      AND FactTypeID = EventType
      )-1
    ) -- maps the FactType to its order
WHERE EventID
IN (SELECT EventID FROM EventTable
    INNER JOIN
    (SELECT -- matching dates
     SortDate, OwnerID, COUNT()-1 AS Matches
     FROM EventTable
     INNER JOIN FactTypeTable
     ON EventType = FactTypeID
     WHERE EventTable.OwnerType = 0
     AND Name IN (SELECT FactName FROM TmpFactOrder)
/*     AND    -- commented out by JB to handle sort dates not matching fact date when sort dates are equal to each other.
     SortDate =   -- equals encoded event Date (if not a match, suggests that user has modified SortDate so don't touch it)
       (CASE
        WHEN DATE LIKE '.%'
        THEN 1
        ELSE Substr(DATE,3,5) END
        +10000
        )*562949953421312
        + Substr(DATE,8,2)*35184372088832
        + Substr(DATE,10,2)*549755813888
        + 17178820620 */
      GROUP BY SortDate, OwnerID, EventTable.OwnerType
     )
     USING (OwnerID, SortDate)
     INNER JOIN FactTypeTable
     ON EventType = FactTypeID
     WHERE Matches
     AND EventTable.OwnerType = 0
     AND Name IN (SELECT FactName FROM TmpFactOrder)
    )
;
 
 
-- We now add Parent roles to each Parents event.
-- It is most convenient to add the Parent role
-- for the father in one INSERT and to add the
-- Parent role for the mother as a separate insert.
-- So we first create a view that joins the
-- Parent events with the ChildTable and FamilyTable
-- to get a list of Parent events and their
-- respective fathers and mothers.
 
DROP VIEW IF EXISTS ParentRoleView;
CREATE TEMP VIEW ParentRoleView AS
SELECT PEV.*,
       FM.FatherID, FM.MotherID
FROM ParentEventView AS PEV
        JOIN
     ChildTable AS CT ON CT.ChildID = PEV.OwnerID
        JOIN
     FamilyTable AS FM ON CT.FamilyID =  FM.FamilyID;
 
 
-- Load Parents roles for fathers into the WitnessTable
 
INSERT OR ROLLBACK INTO WitnessTable
SELECT NULL AS WitnessID
    ,PE.EventID AS EventID
    ,Parents.FatherID AS PersonID
    ,0       AS WitnessOrder
    ,(SELECT R.RoleID FROM RoleTable AS R WHERE R.RoleName LIKE ('Parent') ) AS ROLE
    ,CAST('' AS TEXT) AS Sentence
    ,CAST('' AS TEXT) AS Note
    ,CAST('' AS TEXT) AS Given
    ,CAST('' AS TEXT) AS Surname
    ,CAST('' AS TEXT) AS Prefix
    ,CAST('' AS TEXT) AS Suffix
 FROM ChildParentsTable AS Parents
         JOIN
      ParentEventView AS PE ON PE.OwnerID =  Parents.ChildID AND PE.Details = Parents.CombinedNames;
 
-- Load Parents roles for mothers into the WitnessTable
 
INSERT OR ROLLBACK INTO WitnessTable
SELECT NULL AS WitnessID
    ,PE.EventID AS EventID
    ,Parents.MotherID AS PersonID
    ,0       AS WitnessOrder
    ,(SELECT R.RoleID FROM RoleTable AS R WHERE R.RoleName LIKE ('Parent') ) AS ROLE
    ,CAST('' AS TEXT) AS Sentence
    ,CAST('' AS TEXT) AS Note
    ,CAST('' AS TEXT) AS Given
    ,CAST('' AS TEXT) AS Surname
    ,CAST('' AS TEXT) AS Prefix
    ,CAST('' AS TEXT) AS Suffix
 FROM ChildParentsTable AS Parents
         JOIN
      ParentEventView AS PE ON PE.OwnerID =  Parents.ChildID AND PE.Details = Parents.CombinedNames;
;
 

Identifying Events with Individual Sentence Template Customization

I recently went through an exercise of removing all sentence customization for specific events in my RM database. The purpose of this change was to allow my Point Form sentence templates from the Fact Type Table to be used in all cases.

It is not possible in the RM user interface to search for specific events that have their own customized sentence templates. To that end, I developed the following query. This is pretty specific to my own research, but it did occur to me that there might be other reasons that someone might wish to find all events with individualized sentence customization.

I removed each sentence customization in RM by hand and I used this query only to find the customizations that needed to be removed. I could have done the removals with a query, but as I was removing the sentence customizations I was also updating the Fact note and in some cases the Fact description. So it was essentially impossible to do a complete automation of the the project.

Jerry

-- Finds events with individually customized sentence templates.
-- Sentence templates that are customized in the Fact Type table are not
-- identifed, only those that are customized for a particular event for a
-- particular person in the Edit Person sceen.
--
-- This query is for standard facts only, not for shared facts.
--
-- For a query such as this, most typically I would create
-- three queries and form their UNION. The reason for the
-- three queries is to find the PersonID for individual facts,
-- the FatherID for family facts, and the MotherID for family
-- facts. But for this query, I changed the logic a bit and
-- created a single query with three result columns. Some of
-- the column values will therefore be null, but each row
-- of the query includes at least one person of interest.
--
-- There is a subtle but important point in this query. The
-- query contains a sub-query within a couple of CASE statements.
-- These sub-queries must test the OwnerID from the EventTable
-- that's outside the sub-query rather than the OwnerID from the
-- EventTable that's inside the sub-query. I'm not quite sure why
-- this is so, but the query does not work correctly otherwise.
 
SELECT CASE E.OwnerType
       WHEN 0 THEN E.OwnerID      -- individual fact, get the PersonID
       END PersonID,
 
       CASE E.OwnerType   -- family fact, get the FatherID
       WHEN 1 THEN (SELECT F.FatherID
                    FROM FamilyTable AS F
                           JOIN
                         EventTable ON E.OwnerID = F.FamilyID)
       END FatherID,
 
       CASE E.OwnerType
       WHEN 1 THEN (SELECT F.MotherID   -- family fact, get the MotherID
                    FROM FamilyTable AS F
                           JOIN
                         EventTable ON E.OwnerID = F.FamilyID)
       END MotherID,
 
       FT.Name AS Fact,
       E.Sentence AS Sentence
FROM EventTable AS E
        JOIN
      FactTypeTable AS FT ON E.EventType = FT.FactTypeID
WHERE LENGTH(E.Sentence) > 0                                   -- test to see if sentence template exists
ORDER BY FatherID, MotherID, PersonID, E.DATE;