[dabo-users] Importing data to linked tables

Author: Charles Brunet

Posted: 2012-05-02 at 20:24:18

Hi,

I'm working from the AppWizard generated project. I want to import a csv

file to two linked tables.

1. Contact table, which has an INTEGER PRIMARY KEY (so it autoincrements)

2. Attribute table, which has a composite PK, including a reference to the

Contact table

Here is what I did so far:

- In biz/Attribute.py , I added 'self.AutoPopulatePK = False'

- My import script looks like this:

> self.bizContact = app.biz.Contact(app.dbConnection)

> self.bizAttribute = app.biz.Attribute(app.dbConnection)

> self.bizContact.addChild(self.bizAttribute)

> for contact in rows:

> self.bizContact.new()

> self.bizContact.setFieldVals(contact)

> self.bizContact.save() # How can I avoid this line?

> contactid = self.bizContact.getPK()

> for attr in attributes:

> self.bizAttribute.new()

> self.bizAttribute.setFieldVals(attr)

> self.bizContact.saveAll()

My problem is that it performs commits at each row, instead of one big

commit at the end of the importation. I tried to remove the save() in the

loop, but then it set Attribute.Contact to a negative ID, which is wrong.

My questions are:

- Am I using the bizObject in the right way?

- How can I insert data in child without commiting the parent first to get

its PK?

Thank you,

*Charles Brunet, B. Ing.*

Webmestre.

Étudiant à la maîtrise, génie informatique, Université Laval.

--- StripMime Report -- processed MIME parts ---

multipart/alternative

text/plain (text body -- kept)

text/html

---

_______________________________________________

Post Messages to: Dabo-users@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Searchable Archives: http://leafe.com/archives/search/dabo-users

This message: http://leafe.com/archives/byMID/CAJPgzxmKFw30z+zmP3EdnAD1cJLrrHmtS-9f0Oa7ef-5JKnbvQ@mail.gmail.com

©2012 Charles Brunet