On Monday, December 20, 2010 08:56:03 pm John Fabiani wrote:
> On Monday, December 20, 2010 01:59:42 pm Ed Leafe wrote:
> > On Dec 20, 2010, at 4:54 PM, marcelo nicolet wrote:
> > > Thank you again, John. But is exactly in the bizobj where it's
> > > convenient to have an "array flavor" of these data, because some of the
> > > biz rules involve a sum over the elements.
> >     
> >     If you requery the table, can you reference biz.Record.array_column
> 
> (where
> 
> > 'biz' is your bizobj, and 'array_column' is the Postgres array? Do you
> > get a Python list of values?
> > 
> > 
> > -- Ed Leafe
> 
> In testing I discovered the following:
> 
> CREATE TABLE sal_emp
> (
>   "name" text,
>   pay_by_quarter integer[],
>   schedule text[]
> )
> WITH (
>   OIDS=FALSE
> );
> 
> Using a standard bizobj class:
> class Publicsal_EmpBizobj(dabo.biz.dBizobj):
>     def afterInit(self):
>         self.DataSource = "public.sal_emp"
>         self.KeyField = ""
>         self.addFrom("public.sal_emp")
>         self.addField("schedule")
>         self.addField("name")
>         self.addField("pay_by_quarter")
> 
>     def validateRecord(self):
>         """Returning anything other than an empty string from
>         this method will prevent the data from being saved.
>         """
>         ret = ""
>         # Add your business rules here.
>         return ret
> 
> Using a standard cnxml connection.   I added the bizobj to a form.
> 
>       self.testbizobj= Publicsal_EmpBizobj(self.conn)
>         self.addBizobj(self.testbizobj)
> 
> I am able to access the field without issue.
> 
> self.testbizobj.Record.pay_by_quarter
> provides a python list

Forgot the PK:
class Publicsal_EmpBizobj(dabo.biz.dBizobj):
    def afterInit(self):
        self.DataSource = "public.sal_emp"
        self.KeyField = "pkid"
        self.addFrom("public.sal_emp")
        self.addField('pkid')
        self.addField("schedule")
        self.addField("name")
        self.addField("pay_by_quarter")



And of course all the list stuff just works

myDS = self.testbizobj.getDataSet()
myDS[0]['pay_by_quarter'][0]

As I suggested dbPostgres.py returns the data type as unknown ('?').  
Everything works as far as the read is concerned. 

Writing data to the array is not working.  

self.testbizobj.setFieldVal('pay_by_quarter[0]', 2000)

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/johnf/dabo/dabo/biz/dBizobj.py", line 1631, in setFieldVal
    ret = cursor.setFieldVal(fld, val, row)
  File "/home/johnf/dabo/dabo/db/dCursorMixin.py", line 962, in setFieldVal
    _("Field '%s' does not exist in the data set.") % (fld,))
FieldNotFoundException: Field 'pay_by_quarter[0]' does not exist in the data 
set.

I suspected this because Dabo is looking for real field and not list.

but this works
self.testbizobj.setFieldVal('pay_by_quarter',[2000,3000,4000,5000])
self.testbizobj.save()

Johnf




_______________________________________________
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