writing changes to the database

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

writing changes to the database

Stéphane Charette-2
So far I've only ever read from the Gramps database.  Now I would like
to write, but I have a question.

I start with the information available from this page:

http://www.gramps-project.org/wiki/index.php?title=Using_database_API#Transactions_and_Commits

If I have a set of people -- say 20 people -- and I want to edit
something in each of them, can I do this:

    transaction = database.transaction_begin()

    for handle in some_set_of_handles:
        person=database.get_person_from_handle(handle)
        person.set_foo_bar()
        database.commit_person(person, transaction)

    database.transaction_commit(transaction, "Foo Bar")


Gmail will probably strip the whitespace in front of the lines, but I
hope this makes sense -- the 3 lines following the for loop are
indented.

The part I'm worried about is that I'm re-using the "person" and
calling commit_person() repeatedly for all of the similar changes.  Is
this allowed, or will this blow up?  Do I need to wrap each "person"
change into a new transaction?

Thanks,

Stéphane

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel
Reply | Threaded
Open this post in threaded view
|

Re: writing changes to the database

Don Allingham
This is perfectly valid.  database.get_person_from_handle() returns a
new, unique Person object each time through the loop.

Don

On Wed, 2007-08-22 at 04:12 -0700, Stéphane Charette wrote:

> So far I've only ever read from the Gramps database.  Now I would like
> to write, but I have a question.
>
> I start with the information available from this page:
>
> http://www.gramps-project.org/wiki/index.php?title=Using_database_API#Transactions_and_Commits
>
> If I have a set of people -- say 20 people -- and I want to edit
> something in each of them, can I do this:
>
>     transaction = database.transaction_begin()
>
>     for handle in some_set_of_handles:
>         person=database.get_person_from_handle(handle)
>         person.set_foo_bar()
>         database.commit_person(person, transaction)
>
>     database.transaction_commit(transaction, "Foo Bar")
>
>
> Gmail will probably strip the whitespace in front of the lines, but I
> hope this makes sense -- the 3 lines following the for loop are
> indented.
>
> The part I'm worried about is that I'm re-using the "person" and
> calling commit_person() repeatedly for all of the similar changes.  Is
> this allowed, or will this blow up?  Do I need to wrap each "person"
> change into a new transaction?
>
> Thanks,
>
> Stéphane
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Gramps-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gramps-devel


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel