Paul McNett wrote:
> 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.

Based on the log it seems to think this is a new record, but it is not. 
  In this case I displayed a record in textboxes, I edited one of the 
fields (not Account) and tried to save it.

>> 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.
>

In a way, yes.  This data was in a program I was running under OS/2. 
When I moved to Ubuntu I saved it as a csv file and have been using it 
in Open Office.  I put it in an Sqlite db as a means to continue 
learning Python and Dabo.


>> 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

This app just holds web logon info, software registration numbers, etc. 
The Account field is text.  Right now I'm just working on displaying, 
editing and saving existing records.  Once that works I will add the 
ability to add new records.

I can't figure out why the log says Account is null.  I put it in a 
readonly textbox thinking that would allow the form to see it and then 
save it.

Thanks,  Jim
_______________________________________________
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]

Reply via email to