I think that the problem is with the start_date column.
c.start_date=time.asctime() is not a valid DateTime, you have to use
datetime.today() or something like that. SQLAlchemy (psycopg in fact) maps
timestamps with DateTime objects.
Enrico Morelli wrote:
> Dear all,
>
> I've a strange problem with session.flush() that I'm not able to
> understand why. I've the following tables
>
> users=Table('users', metadata,
> Column('user_id', Integer, primary_key=True),
> Column('firstname', String),
> Column('lastname', String),
> Column('login', String),
> Column('uid', Integer),
> Column('gid', Integer),
> Column('password', String),
> Column('email', String),
> Column('institute', String),
> Column('nationality', String),
> Column('home_directory', String),
> Column('category', String(1)))
>
>
> calculation=Table('calculations', metadata,
> Column('calculation_id', Integer, primary_key=True),
> Column('user_id', Integer, ForeignKey('users.user_id'),
> primary_key=True),
> Column('program', String),
> Column('job', String),
> Column('workdir', String),
> Column('start_date', DateTime),
> Column('protein', String),
> Column('status', String(1)))
>
>
> So, I create the engine and so on.
>
> engine=create_engine('postgres://[EMAIL PROTECTED]/db')
> metadata=BoundMetaData(engine)
> session=create_session()
>
> users=Table('users', metadata, autoload=True)
> calculations=Table('calculation', metadata, autoload=True)
>
> class Users(object): pass
> class Calculations(object): pass
>
> mapper(Users, users)
> mapper(Calculations, calculations, properties={'user':
> relation(Users)})
>
> u=session.query(Users).get_by(login='rossi')
> c=Calculations()
> c.job='1234'
> c.user_id=u
> c.start_date=time.asctime()
> c.program='cara'
> c.workdir='/home/morelli'
> c.protein='test'
> c.status='R'
> session.save(c)
> session.flush()
>
> SQLError: (ProgrammingError) can't adapt 'INSERT INTO calculations
> (calculation_id, user_id, job, workdir, start_date, protein, status,
> program) VALUES (%(calculation_id)s, %(user_id)s, %(job)s, %(workdir)s,
> %(start_date)s, %(protein)s, %(status)s, %(program)s)' {'status': 'R',
> 'workdir': '/home/morelli', 'user_id': <__main__.Users object at
> 0xb75d55cc>, 'calculation_id': 11L, 'job': '1234', 'program': 'cara',
> 'protein': 'test', 'start_date': 'Tue Nov 28 09:59:07 2006'}
>
> If I do the same thing by hand under psql, it's works fine.
> Where is the problem?
>
> Thanks
>
--
Julien Cigar
Belgian Biodiversity Platform
http://www.biodiversity.be
Université Libre de Bruxelles
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
office: [EMAIL PROTECTED]
home: [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---