Sibylle Koczian wrote:
> as I'm slowly working through this guide, I get the next error: when I try to 
> save a new record for the "hours" table, the error messages are:
> 
> 1. "Notice" message box:
> Save Failed:
> 
> table hours has no column named clientname
> SQL: insert into "hours" 
> ("clientfk", "notes", "hours", "servicedate", "billed", "clientname") values 
> (1, 'Test', 2.00, '2008-08-16', '', NULL) 
> 
> 2. In the terminal:
> 
> Dabo Error Log: Sat Aug 16 16:02:14 2008: !!! Data Type Mismatch: 
> field=servicedate. Expecting: <type 'unicode'>; got: <type 'datetime.date'>
> Dabo Info Log: Sat Aug 16 16:02:14 2008: Key '0' not found
> 
> Why this? In the database the field has type "date", and only using the 
> Python 
> sqlite3 module I can use a datetime.date object as parameter to an insert 
> statement.

Does the save happen okay, even though you get the message? It is 
probably an erroneous error message.


> Message 1 is quite right, but why has such an insert statement been 
> generated? 
> And where can I change it?

NonUpdateFields should be getting automatically set to not include the 
foreign/calculated fields. Obviously it didn't happen in this case.

> 
> The BizObject:
> 
> #!/usr/bin/env python
> # -*- coding: utf8 -*-
> # BizHours.py
> # Step-By-Step Guide to Dabo Programming
> 
> import datetime
> import dabo
> 
> class BizHours(dabo.biz.dBizobj):
>     def afterInit(self):
>         self.DataSource = "hours"
>         self.KeyField = "pkid"
>         self.addField("hours.pkid")
>         self.addField("hours.clientfk")
>         self.addField("clients.clientname")
>         self.addField("hours.servicedate")
>         self.addField("hours.hours")
>         self.addField("hours.notes")
>         self.addField("hours.billed")
>         self.addFrom("hours")
>         self.addJoin("clients", "hours.clientfk = clients.pkid")
>         self.DefaultValues = {"servicedate": datetime.date.today()}
>         
>     def getClients(self):
>         """Return a 2-tuple of lists of the client names and their keys."""
>         crs = self.getTempCursor()
>         crs.execute("select pkid, clientname from clients order by 
> clientname")
>         ds = crs.getDataSet()
>         # Create the lists
>         names = [rec["clientname"] for rec in ds]
>         keys = [rec["pkid"] for rec in ds]
>         return (names, keys)
> 
> And the table structure for the "hours" table (ported to SQLite):
> 
> CREATE TABLE hours (
>     pkid integer PRIMARY KEY,
>     clientfk integer NOT NULL,
>     servicedate date NOT NULL default CURRENT_DATE,
>     hours real(4,2) NOT NULL,
>     notes text(240) NOT NULL,
>     billed tinyint(1) NOT NULL default 0 check(billed in (0, 1))
>   );
> 
> What is wrong here?

First off, get into the habit of putting your property settings in 
initProperties() instead of afterInit(). Second of all, try explicitly 
setting NonUpdateFields, like:

class BizHours(..):
   ..
   def initProperties(self):
     ..
     self.NonUpdateFields = ["clientname"]
   ..

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]

Reply via email to