Problem Query Example #requestforhelp

This is an example problem

blahblahblah
TGC55C.ged

Discussions & comments from Wikispaces site


mdriscol

Exporting SQL results to Excel

mdriscol
24 January 2016 23:20:39

I’ve searched the postings here and researched on the internet. I am using SQLite Expert Personal 3 with my RootsMagic 7 database and don’t find anywhere that I can use this version of SQLite to export results to a .csv or some file version that can be imported into Excel. Does anyone know if that is possible?

Thanks!

Mark


ve3meo
ve3meo
25 January 2016 04:14:14

You can copy from the results of a query to the clipboard and paste into Excel. To export to a file, I think you need the Pro version. Look up Export in Help – I don’t see this feature in the free version.

Tom

Tom


momakid

Can I get Alternate Name back into NameTable?

momakid
18 July 2017 03:40:56

I’ve searched the postings here and researched on the internet. I am using SQLite Spy with my RootsMagic 7 database and didn’t find anywhere how to accomplish what I need.

I am fairly new to RootsMagic.

Some action I did in the application causes a record to be added to the NameTable file with the IsPrimary filed is equal to 0. The IsPrimary equal to 0 causes the Alternate Name to be displayed on the Edit Person screen in the application. Alternate Name is displayed both in the left column with a plus and on the Edit Person screen.

I saw several Alternate Name lines on the Edit Person screen. I did not want all of the alternate names so I deleted all of the events with a fact type of Alternate Name in the application.

I still found Alternate names displayed in the left column and in the Edit Person screen. I found documentation that said Alternate names are in the NameTable with the IsPrimary = 0. I deleted them also.

Now I realize those were the married name and did not realize that when I deleted them.

I found a file that had the Alternate Names still in it and ran a query over it to get a list of the people in the NameTable file that have the IsPrimary = 0. I have put those records in a spreadsheet. I want to get those people back in the NameTable file.

Is there a query I can run to repopulate the NameTable file? Or is there a query that I can run that I can put the ownerid in to get the alternate names back into the NameTable?


ve3meo

ve3meo
19 July 2017 03:03:08

Did you see my response to your earlier posting on the home page?

Is it necessary to repopulate the NameTable from the spreadsheet or can the desired Alternate Names be filtered from the old database?

Tom

Named Group – Mark or Unmark List refresh #namedgroup

Intro

We might want to modify a group that we created using one of the parameterised scripts by adding or deleting persons that our programmed rules just can’t catch. For example, a Census Needed group might have someone in it who immigrated to the census jurisdiction after the census year or emigrated from it beforehand. Its rules are not complex enough to filter out these persons. So as we work through a group, we will find that there are persons we would like to remove from the group without getting all fancy about the rules. This page shows how we can go about building a script that we can run in tandem to ‘unmark’ or ‘mark’ selected persons for a group.

WARNING: you may use this type of refresh only on groups fully refreshed by an outboard SQLite query or on empty groups BUT NOT on groups last built or modified by using RM4’s Mark Group/Unmark Group functions as it is possible that the deletion of a person from the latter group may actually remove a range of persons with consecutive Record Numbers.

Group Unmark List

This script could be one of several similar ones with different lists of people. If we have a Census needed #1871 Canada group and a Census needed #1900 Pennsylvania group, the two sets of people to unmark will be very different. So we cannot use a single list with runtime parameters. We will need an Unmark script for each one. Each script will have a corresponding name and hardcoded parameters by which it will select and operate on the correct group. Let’s make an Unmark script for the group “*Census needed #1871 Canada” which we have previously built using the script at Census Needed – Named Group.

This first block of code clears out the temporary table GroupParmTable and re-creates it for the Unmark operation:
NB- LabelID instead of LabelValue error corrected 2011-11-27 21:45 EST

DROP TABLE IF EXISTS GroupParmTable
;
CREATE TEMP TABLE IF NOT EXISTS GroupParmTable
AS
SELECT LabelValue AS GroupID, LabelName COLLATE NOCASE FROM LabelTable
WHERE LabelName LIKE '%Census needed%#1871%Canada%'
;

This table stores the GroupID corresponding to the Group Name that matches the search string ‘%Census needed%#1871%Canada%’ for use by later statements in the script.

The next statement contains the list of RINs that are to be deleted from the group and deletes them.

-- Unmark (list of manual unmarks)
 
DELETE FROM GroupTable
WHERE GroupID LIKE
(
SELECT GroupID FROM GroupParmTable
)
AND StartID IN (78,829) -- list of RINs to unmark, separated by commas
;
 
-- END OF SCRIPT

And that’s all there is to it. As you find more persons you want to delete from the group, you just edit the list of RINs between the parentheses … (78,829,97,12345,2,678) No need to keep them sorted. Putting it altogether, here is my working script: Census needed #1871 Canada – group Unmark list.sql


Group Mark List

A similar procedure for refreshing the ‘manual’ marking of a group follows…

It starts with the same first block of code as Group Unmark above to ensure GroupParmTable registers the group to which we want to add people.

If the list is to replace all that is currently in the group, then we need to clean out the current members of the group with this block of code:

-- delete all persons from the named group whose id is stored in the temp table set up at the start
DELETE FROM GroupTable WHERE GroupID =
(
SELECT GroupID FROM GroupParmTable
)
;

If, instead, the list is to be added to a non-empty group, skip the foregoing block. BUT, be warned that the following code does not prevent the duplication of existing persons in the group. That requires some extra measures TBA.

Now, we add the members in the list to the group:

-- Mark (list of manual marks)
INSERT INTO GroupTable (GroupID, StartID, EndID)
SELECT GroupID, MarkList.*, MarkList.*  FROM GroupParmTable
LEFT JOIN
(
SELECT 78       -- RIN to be marked
UNION           -- required for each successive RIN to be marked
SELECT 829      -- RIN to be marked
--UNION         -- uncomment for next RIN to be added
)
AS MarkList
;

That’s the end of the script. RINs 78 and 829 get added to the target group when the script is run against your database.

If the list got very large, it would be cumbersome to maintain and you can consider a couple of alternatives. One is to keep the list of RINs in a spreadsheet table and use formulas to produce the SELECT RINUNION statements, copy and paste into the script. You can also do it with a regular expression text editor such as PSPad ( Find: (d+) Replace: SELECT $1 UNION ). Another is to create a table of RINs either within your database or in a separate database and revise the procedure to SELECT DISTINCT RIN FROM databasename.tablename, replacing all the SELECT RIN UNION statements with this one.

Name Find query #search

Producing a list of names from your database similar to what is found by RootsMagic 4’s Search > Person List > NameFind, this query does it faster. Moreover, you can sort and filter the results, not supported in RootsMagic Explorer’s NameFind. As a list, it may prove handy to use in conjunction with RM Explorer’s “Record number to find” function (Alt-R).

This query requires the use of SQLite Expert Personal or another SQLite manager that fully supports SQLite runtime parameters of the form $AA::AA(anytext). Neither SQLiteSpy nor SQLite Developer do.

Download

NameFind.sql

Screenshots

NameFindMissingParamDialog.PNG
Sample input dialog

On running the query, you will encounter a series of dialog windows prompting for inputs for:

  • UseSoundex(Y/N) – Y will use the Soundex function to look for soundalikes
  • Surname – the search string for surnames
  • Given – the search string for given names; left blank returns all surname matches

When Soundex is not invoked, you can also use wildcards in the name strings: _ for 1 character, % for any number of characters.

NameFindResult.PNG
Sample result sorted on death year.

The query adds a suffix after the found surname if it is not the person’s primary name: (m) for married name (i.e., the name of the male spouse although that might not be accurate for all cases), (alt) for alternate name.

SQLite Expert Personal allows you to sort these results on any column (it re-runs the query adding an ORDER BY columnname clause). It also lets you filter simply entering a value in the cell of a column above the results or a more complex filter can be built using its Customise button. You can copy and paste selected results directly into Excel and Microsoft Word (use Convert text to table accepting its default settings).

Future

This is about the simplest result set that is useful. Of course, more RM4 tables could be tied in to extend the type of information that could be brought out.

Geo-Lifelines Query #places #placedetails #geocoding #events

2021-11-22 Compatible with #RM8

Have you ever wished to be able to look at all the facts in your family tree database that happened within a day’s horseride of a certain location? Until RootsMagic contains such a report, this adaptation of the LifeLines query helps you view your events for any geographic area in addition to looking at the lifeline of any person in your database.

Edit the SQL file to set the coordinates of your target location and the distance from it you want included. Set the values to (0,0,12450) to include all facts for everywhere. As coded near the end of the query, the results will be sorted by RIN and SortDate so that each person’s events are all together sorted by timeline. With SQLiteSpy et al, you can override that sort by clicking on a column header. Click on SortDate to mix people’s events in a pure timeline sort that may reveal some interesting connections.

Download: Geo-Lifelines.sql

Geo-Lifelines.png
SQLiteSpy screenshot showing results from a database filtered for a range of 10 miles from Oshawa, Ont., Canada.

A Proposal for a Named Group and Color Manager

I’m going to write this up as a free standing utility program that performs only one function. But of course I would prefer that it be included in a bundled and comprehensive utility program. The proposal is for a Named Group and Color Coding Manager for RM5. This intent is to supplement the Named Group and Color Coding capabilities that are already in RM5. For example,

  1. It is possible to create a Named Group from a collection of individuals that are color coded. But it is not possible to create a color coding scheme from Named Groups.
  2. The criteria used to create a Named Group or to color code a collection of individuals does not apply to any persons or facts or changes made to the database after the criteria are applied.
  3. It is not possible to save the criteria that were used to establish a color coding or to save the criteria used to create a Named Group and later to reapply those criteria.
  4. It is not possible to document the purpose of a Named Group or of a color coding with a comment that is associated with the Named Group or color coding.
  5. It is not possible to establish a default color coding scheme for a database, to temporarily change some of the color coding in the database, and then automatically to reset the color coding back to the default.
  6. There are not timestamps maintained about a Named Group or a color coding to indicate when they were established or when they were last reapplied.
  7. It is not possible for the criteria used to define a Named Group or a color coding to include complete Boolean logic (AND, OR, NOT, and parentheses).
  8. It is not possible for the criteria used to define a Named Group or a color coding to apply two or more tests to the same fact. For example, the test “census date equal 1850” and the test “census place contains Tennessee” are not guaranteed to be applied to the same census fact.
  9. There are a number of criteria that would be useful to include in the definition of a Named Group or in the creation of a color coding that are not supported by RM5. Examples are that it is not possible from within RM5 to search for number of parents or number of children, and there are a number of source and citation fields that cannot be searched.

The intent will be to address all these issues.

Here follows a mockup of a proposed “main screen” for the utility program. The mockup assumes that an RM5 database has been opened and that the database already includes a number of named groups.

group_manager.jpg

Note that one of the groups was created from within RM5 itself. Such groups will not include additional metadata needed by the proposed Group Manager.

The proposed Group Manager will need two additional tables in the RM5 database. A table called the GroupDefTable would contain the following data elements.

  1. GroupDefID – a numeric primary key that has no other purpose than to be a unique primary key.
  2. OwnerID – a unique foreign key that can be joined to RM5’s own GroupTable and LabelTable.
  3. CreationDate – the date the Named Group was created.
  4. EditedDate – the date the Named Group was lasted edited.
  5. Comment – Descriptive text for the group (the area in yellow).
  6. Color – the color code to be applied to all the members of the group (if any). This data element is on the Edit Group screen below.
  7. ColorDefaultFlag – a flag to indicate whether this group and its color is a part of the default color scheme for this database. This data element is on the Edit Group screen below.

In order to edit the group criteria for an existing group, the user would double click one of the groups in the list, or would single click or scroll to one of the groups in the list and click the Edit Group button at the top of the screen.

In order to delete the group criteria for an existing group and to delete the group, the user would single click or scroll to one of the groups in the list and click the Delete Group button at the top of the screen.

In order to create a new group, the user would click the New Group button at the top of the screen, and the screen would look something like the following.

group_manager2.jpg

After entering the data for the new group, click Edit Group to bring up the Edit Group screen where the group criteria are entered.

group_manager3.jpg

This screen and the underlying GroupCriteriaTable are not fully formed in my mind just yet. Because this note is becoming so long, I’ll return to it later and fill in more details of how this screen would work for entering the group criteria and how the underlying table will work. I’ll also follow up with some more details of how the group definition process would interact with color coding.

Jerry

Discussions & comments from Wikispaces site


ve3meo

Great!

ve3meo
22 January 2012 13:47:42

What a great surprise this morning, Jerry! Your proposal and detailed outline sound very thorough and useful. I think Named Groups is long overdue for enhancement and your tool will be most welcome by many. I look forward to your further description and progress and would be happy to assist in any way I can.

Are you developing in Visual C++?

Tom


snowathlete

snowathlete
24 October 2012 12:42:33

i also think this looks like an excellent idea. i would definately use this. does it have an ETA?


ve3meo

Manual Mark/Unmark

ve3meo
23 January 2012 23:02:21

I wonder if you have given thought to building and maintaining a list of individual Mark/Unmark settings in addition to the algebraic rules. Your Group Editor might be an adequate user interface with one row taken for each person. Alternatively, I could envision a Mark > Persons or Unmark > Persons opening up another dialog window with the list of persons in the database (as in RM Explorer) with checkboxes – maybe a common list with two mutually exclusive checkboxes each, one for Mark, one for Unmark (or maybe the proper term is Exclude). At its simplest, the dialog interface could just be a list of RINs that the user copies from RM.

I showed a very crude Mark/Unmark of individuals in

This may warrant another table with three fields, GroupID, PersonID and Mark or perhaps a 4th, Unmark. Three would be adequate but the 4th might be easier to work with.


thejerrybryan

thejerrybryan
24 January 2012 05:22:16

Yes, I envisioned a mark/unmark capability on an person by person basis. I don’t think an additional table would be required. But whether an additional table would be required or not, the trickier part would be the user interface. As you suggest, the two basic options for the user interface would be to have row after row of “mark/unmark individual nnnnn” (i.e., by RIN number), or to have a RM Explorer style of marking capability

I’m trying to stay away from what I think is RM’s excessive clickiness. So for example, to enter comments about a group, a note window would not open up. Rather, the user would type directly into what I’m describing as the “yellow area”. I would like to do the same for mark/unmark on a person by person basis, but it may be necessary to do it RM Explorer style.

Jerry

Update Media Paths #media #paths #multimediatable

I have recently added a new drive to my pc and wanted a quick way to update the media path file. Whilst there is standard tool within RM5 to fix broken media links, it searches through my entire pc which now has 5TB of data – it picks up files from backup directories and generally takes a long time. I also have the option to update the path directly in the MultimediaTable. Some examples below:

  • I want to review the records with a particular path
SELECT * FROM MultimediaTable 
  WHERE Mediapath like ('J:\FAMILY_HISTORY\PAXTON\CERT%');
  • I want to update this path to the new path
UPDATE multimediatable 
  SET Mediapath = 'S:\New_Family_History\PAXTON\CERT') 
WHERE mediapath LIKE ('J:\FAMILY_HISTORY\PAXTON\CERT%');
  • If i want to replace only some of the path and not the entire string i use the REPLACE function
UPDATE multimediatable
 SET Mediapath = REPLACE (Mediapath, 'J:\FAMILY_HISTORY', 'S:\New_Family_History') 
WHERE mediapath LIKE ('J:\FAMILY_HISTORY\PAXTON\CERT%');

Cheers,

Sean

Discussions & comments from Wikispaces site


ve3meo

Inline comment: “a quick way to update the media path file”

ve3meo
04 September 2018 03:34:47

ve3meo Jan 12, 2012

Good examples of Search, Update and Replace. Also see the page Search & Replace for more examples. Of course, RootsMagic own Search & Replace function on “Multimedia filenames” in the “Field to search” selection does much the same, with the ability to confirm each replace.

Reporting Missing Census Information

One report that would be a great boon to RM users is one that would look at the recored information for each individual and work out where Census entries were missing. Of course this would vary by country of user but I am approaching this from the point of view of a UK User where 95% or more of his people records are for UK family.

For example we can assume at the moment that potential Census records exist for viewing for every tenth year between 1841 and 1911. The logic require is, therefore, to look at the birth/baptism/christening and death/burial dates of the individual as well as the existing Census entries on the Rootsmagic database and determine which Census entires are likley to be missing. We would also need some logic to cope as well as it could with individuals for whom no birth or death dates are known. The following “selections” would pull together what I want:

a) Individual has Birth Date earlier than 2nd April 1911 and Death Date no earlier than Sunday 6th June 1841:

Look through the Census entries on RM and if any are missing over the period the person was living between 1841 and 1911 then highlight this fact.

b) Individual has Birth Date earlier than 2nd Paril 1911 but no recorded Death Date:

In the absence of any other data – proceed as for a) above from date of Birth to 1911.

c) Individual has no Brith Date and a Death Date recorded after 1841:

In the absence of any other data proceed as a) above from 1841 to date of death.

d) Individual has no birth date and no death date:

Clearly we do not want to report on the many people who were “obviously” born after 1911 or “obviously” dead before 1841. One solution might be to look at Parents or Children of these individuals and try and determin whether they should be included in the report. Or perhaps just an option to include everyone in this category or exclude everyone in this category. Or to see if there are any Events of any type recorded for the individual between the period 1841 and 1911.

Or perhaps others have a better idea?

In a) b) c) and d) above I think the code should determine a birth date from the presence of either a Birth entry or in its absence a Baptism entry or a Christening entry. Similarly the Death entry should be used or in its absence a Burial entry.

I would envisage the report looking something like:

Name of Individual Birth/Chr/Bapt Death/Burial Potential Missing Census References
xx xxxxxxxxxxx xx/xx/1837 xx/xx/1902 1851, 1861, 1881
xx xxxxxxxxxxx xx/xx/1794 xx/xx/1852 1841, 1851
xx xxxxxxxxxxx xx/xx/1878 N/K 1901, 1911

Clearly for RM Users in other countries, where a different ranges of Census data isavailable, the start and end year parameters would have to be different.

MVS.

Discussions & comments from Wikispaces site


ve3meo

Inline comment: “where Census entries were missing‍”

ve3meo
04 September 2018 01:48:57

ve3meo Jan 16, 2012

In some respects,
Census Needed – Named Group does what you want. The qualifying rules are simpler but may be enhanced. Once the group is created, you could generate reports restricted to it, or, just select the group and work through it. Periodically, re-run the query to refresh the group membership and take satisfaction from seeing it shrink!

Inline comments


ve3meo

Comment: In some respects,
Census Needed – Na…

ve3meo
16 January 2012 18:21:38

In some respects,
Census Needed – Named Group does what you want. The qualifying rules are simpler but may be enhanced. Once the group is created, you could generate reports restricted to it, or, just select the group and work through it. Periodically, re-run the query to refresh the group membership and take satisfaction from seeing it shrink!

Missing Media #media

OK, this is a little misleading as it will only work for images (i.e. not applicable for text files or pdf files) ~ if anyone can show me how to check for valid paths from sqlite, i would be stoked!

SELECT *
FROM Multimediatable
WHERE Thumbnail is null
AND Mediafile like '%.jpg';

Discussions & comments from Wikispaces site


ve3meo

Comment: “how to check for valid paths from sqlite”

ve3meo
03 September 2018 21:49:34

ve3meo Jan 15, 2012

I have done this indirectly, by exporting the full path of each file to a text file to be processed by a command file (.bat or .cmd): see
Backup Media with Database – 7Zip
Backup Media with Database – RAR
Also, I have copied the results of a query to Excel and created hyperlinks (either in the query itself or by formula in Excel): see
Media List Query.

It requires more than SQLite itself to test that the stored path leads to the target file.

At the very least, your query lists those image files that have not been opened by RM, hence nothing in the thumbnail field.

Ahnentafel 64 generations #ahnentafel #ancestors #reports

RootsMagic 5 and below support for Ahnentafel numbering is limited to 32 bits, or 32 generations, even though the report allows the user to select a larger number. If the report does run over 32 generations, the Ahnentafel number starts over and is therefore incorrect. This query demonstrates that SQLite itself can support a 64 generation Ahnentafel report.

The results of this query look very similar to those from the Ancestors Query, with the addition of both a binary and decimal Ahnentafel number for the last person in a direct ancestral line from the starting person, expanded to 64 generations. It is a very large and slow query that cries out for help from a high level language because SQLite itself does not support loops nor binary-decimal conversion. If your database is large, I strongly recommend using a SQLite manager that supports run-time parameters so that the results are limited to the ancestry of just one person (SQLite Expert Personal or SQLite Developer), not that it is faster but rather the processing or results may exceed the software’s capacity to manage memory.

To build and revise it many times, I used Excel to generate the 64 lines from each of around 8 formulas, sorting and unsorting a large block of interleaved phrases for each revision. As such, the query is not very readable, having many very long lines and lacking indentation.

There must be a more efficient way of coming up with the lineage than the two similar methods I have used in this and its parental query (despite the similarity in the appearance of the results, Ahnentafel-64 uses a significantly different relationship in building the lineage). It is simply too slow to be attractive to run on databases larger than a few thousand persons. So there’s a challenge! Come up with a better one!

Ahnentafel-64.sql
Ahnentafel-64_tidy.sql– a formatted version that might be easier to follow.

— the Excel spreadsheet on which the query was developed using formulae.

Having torn my hair out trying to reconcile differences between RootsMagic 5’s Ahnentafel list and the results I was getting with my query, I discovered that RM5’s follows the parental line selected in the Pedigree View. I had one person shown with her adoptive parents and compounded with other issues I was having with incorrect Ahnentafel calculations, missing the last parent, etc., it took me quite a while to understand that some longer lines I was getting that were not showing up in the RM5 report were not because of an error in my query but because of this undocumented behaviour in RM5! My query follows the Birth parental line only; RM5 appears to follow whichever set of parents you choose.