Changes

From Gramps

Addon:Generic DB Access lib

1,040 bytes added, 07:14, 13 May 2020
Example
=== Example ===
Consider the problem of finding out how many people were born in March. Basically, we need to go through the database, get the reference (if one) to the birth event, look up the birth event, if found, get the date from it, get the month and compare it. That might look like this:
 
<pre>
count = 0
for p in db.iter_people():
birth_ref = p.get_birth_ref()
if birth_ref:
event = db.get_event_from_handle(birth_ref.ref)
if event:
date = event.get_date_object()
if date.get_month() == 3:
count += 1
</pre>
 
This example is not unusual; you’d have to do something like this whatever it is that you are doing. And this is a simple example. It can get much more complicated. But even in this “simple” example, you have to know a lot about the gen.lib objects that make up Gramps (things like Person, Event, and Date) but you also need to know the interface to the database (things like iter_people, get_event_from_handle) and how things are linked together (handles and refs).
 
Here is how you would solve the above using this experimental Gramps addon:
15,091
edits

Navigation menu