[sqlalchemy] Re: Number of row updated or deleted

2009-09-29 Thread Mike Conley
Use rowcount property of the ResultProxy returned from delete/update result = conn.execute(tbl.delete()) count = result.rowcount Note that the quality of the number will depend on the underlying database and Python dbapi. --~--~-~--~~~---~--~~ You received this

[sqlalchemy] relations with additional criteria

2009-09-29 Thread Martijn Faassen
Hi there, The relation() logic lets you write an additional filter into a relation if you provide your own primaryjoin. The case I'm dealing with is a case where I want to take over the primaryjoin that is autogenerated by the RelationProperty object, but amend it with an extra filter. This

[sqlalchemy] Re: Relation using = operator and literal values

2009-09-29 Thread Michael Bayer
Wyatt Lee Baldwin wrote: I have a relation defined like this in a declarative-style class: route = relation( RouteDef, primaryjoin=( (route_number == RouteDef.route_number) (route_begin_date = RouteDef.route_begin_date) ), )

[sqlalchemy] Re: relations with additional criteria

2009-09-29 Thread Michael Bayer
Martijn Faassen wrote: Hi there, The relation() logic lets you write an additional filter into a relation if you provide your own primaryjoin. The case I'm dealing with is a case where I want to take over the primaryjoin that is autogenerated by the RelationProperty object, but amend it

[sqlalchemy] Re: relations with additional criteria

2009-09-29 Thread Martijn Faassen
Michael Bayer wrote: [snip] Whats missing here is the context. I want to define ORM relations in the mapper that I can access without having to do a manual join. Normally you'd do this: mapper(A, a_table, properties={ 'bs': relation(B , backref='a',

[sqlalchemy] Orm slow to update why?

2009-09-29 Thread Christian Démolis
i made a test i did that without sql alchemy orm: import MySQLdb import time # Establich a connection db = MySQLdb.connection(host=192.168.45.28, user=apm, passwd=apm, db=test_christian) # Run a MySQL query from Python and get the result set xref

[sqlalchemy] Re: Orm slow to update why?

2009-09-29 Thread Michael Bayer
Christian Démolis wrote: i made a test i did that without sql alchemy orm: import MySQLdb import time # Establich a connection db = MySQLdb.connection(host=192.168.45.28, user=apm, passwd=apm, db=test_christian) # Run a MySQL query from

[sqlalchemy] Re: relations with additional criteria

2009-09-29 Thread Michael Bayer
Martijn Faassen wrote: But I'd like to automate this: mapper(A, a_table, properties={ 'bs': my_own_relation(B , backref='a'), }) my_own_relation behaves like relation, except it adds an extra clause restricting the query, say, b_table.c.status == 'FOO'. It

[sqlalchemy] Re: Relation using = operator and literal values

2009-09-29 Thread Wyatt Lee Baldwin
On Sep 29, 7:55 am, Michael Bayer mike...@zzzcomputing.com wrote: Wyatt Lee Baldwin wrote: I have a relation defined like this in a declarative-style class:     route = relation(         RouteDef,         primaryjoin=(             (route_number == RouteDef.route_number)            

[sqlalchemy] Re: Relation using = operator and literal values

2009-09-29 Thread Michael Bayer
Wyatt Lee Baldwin wrote: In my view (which may be warped), a Trip has one Route (and many Trips follow the same Route). Here's more context: class Trip(Base): __tablename__ = 'trip' __table_args__ = dict(schema='trans') __mapper_args__ = dict(

[sqlalchemy] issue with column_property

2009-09-29 Thread Eric Lemoine
Hi Here's my case: I have - my own TypeEngine class, MyTypeEngine - a Table with a Column using MyTypeEngine: table = Table(tablename, metadata, Column(columname, MyTypeEngine()), autoload=True, autoload_with=engine ) - a class: class MyClass(object): pass - and a

[sqlalchemy] Re: issue with column_property

2009-09-29 Thread Michael Bayer
Eric Lemoine wrote: Hi Here's my case: I have - my own TypeEngine class, MyTypeEngine - a Table with a Column using MyTypeEngine: table = Table(tablename, metadata, Column(columname, MyTypeEngine()), autoload=True, autoload_with=engine ) - a class: class

[sqlalchemy] Re: issue with column_property

2009-09-29 Thread Eric Lemoine
On Tue, Sep 29, 2009 at 9:04 PM, Michael Bayer mike...@zzzcomputing.com wrote: Eric Lemoine wrote: Hi Here's my case: I have - my own TypeEngine class, MyTypeEngine - a Table with a Column using MyTypeEngine:   table = Table(tablename, metadata,       Column(columname, MyTypeEngine()),

[sqlalchemy] Re: relations with additional criteria

2009-09-29 Thread Martijn Faassen
Hey, Michael Bayer wrote: OK well I'm sure you noticed that RelationProperty was not designed to be subclassed. Yeah, my subclass isn't pretty. :) I would advise that your my_own_relation() function generate its own primaryjoin and secondaryjoin conditions which it passes as arguments to

[sqlalchemy] Re: Relation using = operator and literal values

2009-09-29 Thread Wyatt Lee Baldwin
On Sep 29, 11:53 am, Michael Bayer mike...@zzzcomputing.com wrote: Wyatt Lee Baldwin wrote: In my view (which may be warped), a Trip has one Route (and many Trips follow the same Route). Here's more context: class Trip(Base):     __tablename__ = 'trip'     __table_args__ =

[sqlalchemy] Re: Relation using = operator and literal values

2009-09-29 Thread Michael Bayer
Wyatt Lee Baldwin wrote: Anyway the primaryjoin here looks fine and does represent the same thing you're getting in your route() @property.   It's a simple many-to-one with an additional criterion.   Nothing needs to be configured in the database as far as foreign keys, configuring it as

[sqlalchemy] Re: Relation using = operator and literal values

2009-09-29 Thread Wyatt Lee Baldwin
On Sep 29, 2:00 pm, Michael Bayer mike...@zzzcomputing.com wrote: Wyatt Lee Baldwin wrote: Anyway the primaryjoin here looks fine and does represent the same thing you're getting in your route() @property.   It's a simple many-to-one with an additional criterion.   Nothing needs to be

[sqlalchemy] SQLAlchemy is dropping columns on Oracle 10g

2009-09-29 Thread Andrew
This is very confusing; I have an ORM generated SQL statement that is joining on a specific id. However, when I run it, for some reason, the specific id (that was joined on) is occasionally None! However, when I run the generated SQL copied from the server's debug log in SQLDeveloper, I get all

[sqlalchemy] Re: Relation using = operator and literal values

2009-09-29 Thread Michael Bayer
Wyatt Lee Baldwin wrote: On Sep 29, 2:00 pm, Michael Bayer mike...@zzzcomputing.com wrote: Wyatt Lee Baldwin wrote: Anyway the primaryjoin here looks fine and does represent the same thing you're getting in your route() @property.   It's a simple many-to-one with an additional

[sqlalchemy] Re: SQLAlchemy is dropping columns on Oracle 10g

2009-09-29 Thread Michael Bayer
Andrew wrote: This is very confusing; I have an ORM generated SQL statement that is joining on a specific id. However, when I run it, for some reason, the specific id (that was joined on) is occasionally None! However, when I run the generated SQL copied from the server's debug log in

[sqlalchemy] Re: Relation using = operator and literal values

2009-09-29 Thread Wyatt Lee Baldwin
On Sep 29, 3:12 pm, Michael Bayer mike...@zzzcomputing.com wrote: Wyatt Lee Baldwin wrote: On Sep 29, 2:00 pm, Michael Bayer mike...@zzzcomputing.com wrote: Wyatt Lee Baldwin wrote: Anyway the primaryjoin here looks fine and does represent the same thing you're getting in your