imgrey ha scritto:
> Good Day sqlalchemy.
>
> I was searching, but didn't found a way to delete records from db not
> executing selection first.
>   
You must istantiate an istance of the obj to be deleted.
This is an Object Manager, so all operation is available on object.
 
or you can execute a plain string-sql  direclty from engine

connection = engine.connect()
connection.execute("DELETE FROM a WHERE b = c")




> So, how to represent this SQL statement in slqalchemy ORM :
> """ DELETE FROM a WHERE b = c """ ?
>
> not it look like this :
> stuff = session.query(A).select_from(a_table).filter(A.c.b==c).first()
> session.delete(stuff)
>
>
> P.S.
>
> How to understand the following :
>
> Traceback (most recent call
> last):
>   File "threading.py", line 442, in
> __bootstrap
>  
> self.run()
>   File "./camper.py", line 173, in
> run
>  
> session.delete(stuff)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/scoping.py",
> line 74, in
>  
> do
>     return getattr(self.registry(), name)(*args,
> **kwargs)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py",
> line 849, i
> n
> delete
>  
> self._delete_impl(object)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py",
> line 1007,
> in
> _delete_impl
>     raise exceptions.InvalidRequestError("Instance '%s' is not
> persisted" % mapp
> erutil.instance_str(obj))
> InvalidRequestError: Instance '[EMAIL PROTECTED]' is not persisted
>
>   

seems your object is not attached to session.

>
> It occurs sometimes in threaded application in this code :
>
> """
> from sqlalchemy.orm import mapper, relation, backref, create_session,
> scoped_session
> session = scoped_session(create_session)
> stuff =
> session.query(Path).select_from(f_table.join(u_table)).filter(User.c.id==theone.id).first()
> session.delete(stuff)
> """
>
>   
i don't use scoped_session.

but try instead

stuff.delete()



Glauco

-- 
+------------------------------------------------------------+
 Glauco Uri  
 glauco(at)sferacarta.com 
                               
          Sfera Carta Software®       info(at)sferacarta.com
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054
+------------------------------------------------------------+



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to