On 8/30/10 3:17 PM, Jim Byrnes wrote:
> How does Form.save() decide if it should do an INSERT or an UPDATE?
The underlying bizobj decides, based on whether the record is internally
flagged as a
new record or not.
> I have a form with a dropdown list of Categories. Selecting a Category
> fills a listbox of Accounts. Selecting an Account populates 6 texboxes
> with a row from the db. The PK is the Account field which is displayed
> in one of the textboxes.
It is usually a bad idea to have meaningful PK's. But, you may be stuck with an
inherited design. As long as you never allow the editing of that Account
textbox,
you'll probably be okay.
> I was poking around the wiki and saw that dabo has logging so I turned
> it on. The log of a failed save is below:
>
> Database Activity Log: Mon Aug 30 16:40:39 2010: SQL: BEGIN
> Database Activity Log: Mon Aug 30 16:40:39 2010: SQL: begin
> Database Activity Log: Mon Aug 30 16:40:39 2010: FAILED SQL: insert into
> "pwds" ("Category", "User_Id", "Notes", "Location", "Password") values
> (?,?,?,?,?) , PARAMS: WebSites, jim byrnes, None, , bearsXX
> Database Activity Log: Mon Aug 30 16:40:39 2010: DBQueryException
> encountered in execute(): pwds.Account may not be NULL
> insert into "pwds" ("Category", "User_Id", "Notes", "Location",
> "Password") values (?,?,?,?,?)
> Database Activity Log: Mon Aug 30 16:40:39 2010: DBQueryException
> encountered in save(): pwds.Account may not be NULL
> Dabo Error Log: Mon Aug 30 16:40:39 2010: Error in scanChangedRows:
> pwds.Account may not be NULL
> Database Activity Log: Mon Aug 30 16:40:39 2010: SQL: ROLLBACK
> Database Activity Log: Mon Aug 30 16:40:39 2010: SQL: rollback
> Dabo Error Log: Mon Aug 30 16:44:58 2010: Cancel failed with response:
> PK '-1-dabotmp' not found in table 'pwds' (RowCount: 82)
Upon new(), you need to fill the Account field with a unique value. You should
do
this in your bizobj using the DefaultValues property, like:
class MyBiz(dabo.biz.dBizobj):
def initProperties(self):
...
self.KeyField = "Account"
self.DefaultValues["Account"] = self.getNewAccountNumber
def getNewAccountNumber(self):
# however you determine the next unique account number, return it here
return newAccountNumber
Alternatively, you could (should?) configure the database to generate the new
account
number.
Paul
_______________________________________________
Post Messages to: [email protected]
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/[email protected]