On Wednesday 24 November 2010 2:41:06 pm John Fabiani wrote:

>
> I should have said -  are you sure postgres is return the string
> "timedelta"? I would have expected "interval"
>
> Johnf
>

A quick and dirty way to get around this is shown below:

def interval_str(val,cur):
        if val is None:
                return None
        else:
                return val

def main():
    import psycopg2.extensions
    INTERVAL=psycopg2.extensions.new_type((1186,),"INTERVAL",interval_str)
    psycopg2.extensions.register_type(INTERVAL)
    app = dabo.dApp()
    app.MainFormClass = MainForm
    app.BasePrefKey = "intervalFrm"
    app.start()

This makes psycopg2 return a string instead of a timedelta when pulling data 
from an interval field. 

Then if you declare the interval field as "C" in the bizobj DataStructure the 
string representation shows up. 

class IntervalTest(dabo.biz.dBizobj):
            
            def afterInit(self):
                self.DataSource = "public.interval_test"
                self.KeyField = "id"
                self.DataStructure = [
                    ("id","I",True,"public.interval_test","id"),
                    ("interval_fld","C",False,"public.interval_test",\
                        "interval_fld")
                    ]
                self.SaveNewUnchanged=True
        publicIntervalTest = IntervalTest(self.Connection)
        self.addBizobj(publicIntervalTest)


-- 
Adrian Klaver
[email protected]
_______________________________________________
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