On Mon, 4 Sep 2006 16:39:18 +0200
Enrico Morelli <[EMAIL PROTECTED]> wrote:

> On Mon, 4 Sep 2006 16:34:40 +0200
> Enrico Morelli <[EMAIL PROTECTED]> wrote:
> 
> > On Mon, 4 Sep 2006 16:07:51 +0200
> > "Andrija Zaric" <[EMAIL PROTECTED]> wrote:
> > 
> > > If you are going to do script once and outside main application,
> > > maybe this is going to be little faster:
> > > 
> > > users = session.query(Users).select()
> > > 
> > > ref_pairs = []
> > > for u in users:
> > >     ref_pairs.extend([(u.id, int(pr_id)) for pr_id in
> > > u.fk_project.split(',')])
> > > 
> > > #this should do multi-value insert:
> > > users_projects.insert().execute(*ref_pairs)
> > 
> > Sounds good, the only problem is that the fk_project is a field like
> > 1,15,40, and so when I split it I obtain:
> > ['1','15','40','']
> > 
> > So your this method raise an exception ValueError.
> > 
> 
> Ok, I'm stupid. 
> It's sufficient add and if statement:
> ref_pairs.extend([(u.id, int(pr_id)) for pr_id in
> u.fk_project.split(',') if pr_id])
> 
> Thanks again.
> 

No, doesn't work. I raise an exception:

Traceback (most recent call last):
  File "users_projects_create.py", line 48, in ?
    users_projects.insert().execute(*ref_pairs)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 509,
in execute return self.execute_using(self.engine, *multiparams,
**params) File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py",
line 463, in execute_using return self.compile(engine=engine,
parameters=compile_params).execute(*multiparams, **params) File
"/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 502, in
compile compiler.compile() File
"/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 367, in
compile self.statement.accept_visitor(self) File
"/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 1603, in
accept_visitor visitor.visit_insert(self) File
"/usr/lib/python2.4/site-packages/sqlalchemy/ansisql.py", line 490, in
visit_insert if (isinstance(c, schema.SchemaItem) and (self.parameters
is None or self.parameters.get(c.key, None) is None)): AttributeError:
'long' object has no attribute 'get'


-- 
-------------------------------------------------------------------
       (o_
(o_    //\  Coltivate Linux che tanto Windows si pianta da solo.
(/)_   V_/_
+------------------------------------------------------------------+
|     ENRICO MORELLI         |  email: [EMAIL PROTECTED]       |
| *     *       *       *    |  phone: +39 055 4574269             |
|  University of Florence    |  fax  : +39 055 4574253             |
|  CERM - via Sacconi, 6 -  50019 Sesto Fiorentino (FI) - ITALY    |
+------------------------------------------------------------------+

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to