[sqlalchemy] Re: SqlSoup joins broken in 0.5.3

2009-04-01 Thread Stu.Axon
Cheers, both of these worked. On Mar 31, 5:19 pm, Michael Bayer mike...@zzzcomputing.com wrote: oh, you could send that as a tuple to join, i.e. db.devmap_device.join((db.devmap_manufacturer,   db.devmap_device.manufacturer_id == db.devmap_manufacturer.id)).first() this because join()

[sqlalchemy] Invalid Transaction error

2009-04-01 Thread chingi
Hi all, I am facing a strange problem . sometimes when i try to access my web server i get Invalid Transaction error. Can anyone help me in this regard The error description : Traceback (most recent call last): File c:\python25\lib\site-packages\cherrypy-2.2.1-py2.5.egg\cherrypy

[sqlalchemy] compare 2 tables

2009-04-01 Thread menuge
Hi, I have to write a table comparator. Actually, I have 2 sqlite files (file1.db, file2.db) with the same schema (2 tables tab1, tab2). I d like to compare the values of the tables (values added, values deleted, values modified). I don't know how to start. Can someone help me? Thanks in

[sqlalchemy] How to use distinct on a particular column?

2009-04-01 Thread Stu.Axon
I'm having another go at converting some sql to sqlalchemy: select count(distinct build.device_id) from channelbuild join build on build.id = channelbuild.build_id where channelbuild.channel_id = 9

[sqlalchemy] Many to One relation, correct like this?

2009-04-01 Thread Frank Broniewski
Hi all, I want to know if I am using SQLAlchemy in a correct and proper way for Many to One Relations between objects and database tables. I have created a test case for Cars and Brands. Each car can have a name and one Brand. I wonder if I use the setter in the Car Class correctly and if the

[sqlalchemy] Re: How to use distinct on a particular column?

2009-04-01 Thread Michael Bayer
Stu.Axon wrote: I'm having another go at converting some sql to sqlalchemy: select count(distinct build.device_id) from channelbuild join build on build.id = channelbuild.build_id where

[sqlalchemy] Re: concurrent 'upsert'

2009-04-01 Thread Michael Bayer
Jyotirmoy wrote: I want to know what is the best way to write code using sqlalchemy that given a value of the primary key inserts a record if no record with that key exists or updates the value of the other columns if the key already exists. I wrote a naive version which get()s the value

[sqlalchemy] Re: Many to One relation, correct like this?

2009-04-01 Thread Michael Bayer
its almost an example fit for a tutorial. I'd just lose the setBrand() method and just assign car.brand = somebrand. the brand_id gets populated by the ORM when things are flushed. Frank Broniewski wrote: Hi all, I want to know if I am using SQLAlchemy in a correct and proper way for

[sqlalchemy] Re: patch to accept query parameters on Oracle TNS entries

2009-04-01 Thread Michael Bayer
see my comments on the ticket for further discussion. Catherine Devlin wrote: Hey, SQLAlchemy folks... sorry to bug you during your sprint (wish I could be there - next year, I hope), but I've got a patch for you that I hope will be really quick and easy to review and apply. I've attached

[sqlalchemy] Stale ORM Objects Locking Best Practice (for nested sets)

2009-04-01 Thread Randy Syring
I have a nested set implementation that I am working on. Currently, the steps involved to make a change to the table are: 1) Retrieve parent node (ORM Object) 2) Create new node (same ORM object as #1) 3) Calculate UPDATE boundaries, etc. from anchor node 4) Create UPDATE SQL based on #3 5)

[sqlalchemy] Re: How does query.get() work?

2009-04-01 Thread Christiaan Putter
What I would do is simply iterate through the list of id's the user gives. Then use sess.query(SomeClass).get(id) to retrieve the required instance, apply changes if needed and loop to the next id. Then issue sess.commit() at the end. SA will take care of either updating things from the db,

[sqlalchemy] Re: How to use distinct on a particular column?

2009-04-01 Thread Stu.Axon
I tried this session\ .query(func.count(distinct(build.device_id)))\ .filter(channelbuild.channel_id == 9)\ .filter(build.in_icp == False)\ .scalar() It generated this sql: SELECT count(DISTINCT backfill_build.device_id) AS count_1 FROM backfill_build,

[sqlalchemy] Re: Stale ORM Objects Locking Best Practice (for nested sets)

2009-04-01 Thread Michael Bayer
there's a nested set demo in the examples/ folder of the distribution, which uses MapperExtension as well as a little-used flag on the mapper called batch=False. are you building off of that ? as far as multithread/process, the UPDATE statements which nested sets requires would result in a

[sqlalchemy] Re: How to use distinct on a particular column?

2009-04-01 Thread Michael Bayer
Stu.Axon wrote: I tried this session\ .query(func.count(distinct(build.device_id)))\ .filter(channelbuild.channel_id == 9)\ .filter(build.in_icp == False)\ .scalar() It generated this sql: SELECT count(DISTINCT backfill_build.device_id) AS count_1 FROM

[sqlalchemy] Generating a _BinaryExpression

2009-04-01 Thread Hinrich Winther
Hi, I need to generate a sqlalchemy.sql.expression._BinaryExpression by hand. So I looked into the docu and found that I need a left, right and a operator. I am stuck at the left :) type() says it is a sqlalchemy.sql.util.AnnotatedColumn. But I can't find the class definition anywhere in

[sqlalchemy] Re: Generating a _BinaryExpression

2009-04-01 Thread Michael Bayer
Hinrich Winther wrote: Hi, I need to generate a sqlalchemy.sql.expression._BinaryExpression by hand. So I looked into the docu and found that I need a left, right and a operator. I am stuck at the left :) type() says it is a sqlalchemy.sql.util.AnnotatedColumn. But I can't find the class

[sqlalchemy] Re: How to use distinct on a particular column?

2009-04-01 Thread Stu.Axon
Doh, must be tired. That works cool... finally have my first SQLAlchemy ORM stuff working. Thanks... Is it best practice to move the joins into the filter(where) clause like this, (in this case channelbuild.build_id is FK to the PK build.id)? I tried putting the join inside the distinct

[sqlalchemy] Re: concurrent 'upsert'

2009-04-01 Thread Yassen Damyanov
You may prefer to use session.merge() leaving the SELECT and the subsequent decision to INSERT or UPDATE to SQLAlchemy (see http://www.sqlalchemy.org/docs/05/session.html?highlight=merge#merging) The main section of your example should look like this then: ---snip--- id =

[sqlalchemy] Session and pre/post callable methods

2009-04-01 Thread Laurent Rahuel
Hi, I'm currently trying to port a Django based application using sqlalchemy and I'm a bit confused with some Django's orm features I'm not able to find in sqlalchemy. To avoid triggers I used to redefine the save() and delete() methods from Django's models to be able to update some other

[sqlalchemy] Re: Session and pre/post callable methods

2009-04-01 Thread Michael Bayer
look into using MapperExtension and/or SessionExtension to add hooks within the flush process. Laurent Rahuel wrote: Hi, I'm currently trying to port a Django based application using sqlalchemy and I'm a bit confused with some Django's orm features I'm not able to find in sqlalchemy. To

[sqlalchemy] Re: Generating a _BinaryExpression

2009-04-01 Thread Hinrich Winther
Maybe there is a better way of doing it. To be exact: I want to disassemble a given _BinaryExpression into basic elements (a list of strings, arrays, integers ...) and reassemble it somewhere else out of this basic elements. On 01.04.2009, at 18:14, Michael Bayer wrote: Hinrich

[sqlalchemy] Re: Generating a _BinaryExpression

2009-04-01 Thread Michael Bayer
well its part of a traversable expression tree, its just left, right and op, if you want generic traversal take a look at the sql.visitors module. Hinrich Winther wrote: Maybe there is a better way of doing it. To be exact: I want to disassemble a given _BinaryExpression into basic elements

[sqlalchemy] Re: Generating a _BinaryExpression

2009-04-01 Thread Michael Bayer
i.e. the operator is a function: my_binary = column('foo') == column('bar') my_new_binary = my_binary.operator(my_binary.left, my_binary.right) make sense ? Hinrich Winther wrote: Maybe there is a better way of doing it. To be exact: I want to disassemble a given _BinaryExpression into

[sqlalchemy] Re: Generating a _BinaryExpression

2009-04-01 Thread az
i have similar thing, but by keeping an expression in my own terms and rendering into different things, like text, SQL, SA-expresion, etc. u define what is a variable, const, functor, overload all the operators, etc etc; then have a visitor that walks and translates (interprets) it into

[sqlalchemy] Re: Session and pre/post callable methods

2009-04-01 Thread az
u have MapperExtensions, per class, and u have SessionExtension, per session. Both exhibit various events, in different life-span points. i think there are some decorators for declarative... On Wednesday 01 April 2009 19:26:35 Laurent Rahuel wrote: Hi, I'm currently trying to port a Django

[sqlalchemy] patch: PGUuid type not compatible with Python uuid module

2009-04-01 Thread Jonathan Gardner
The PGUuid doesn't accept Python's uuid.UUID type. Here's a simple patch to fix that: diff --git a/lib/python2.5/site-packages/SQLAlchemy-0.5.3-py2.5.egg/sqlalchemy/databases/po index 038a9e8..394c293 100755 ---

[sqlalchemy] Re: patch: PGUuid type not compatible with Python uuid module

2009-04-01 Thread Michael Bayer
I think we should put this in 0.6 since 0.5.3 is already out with the non-UUID version, code that expects a string to be returned will break. Im using a TypeDecorator myself to integrate with UUID at the moment. class GUIDType(TypeDecorator): impl = PGUuid def process_bind_param(self,

[sqlalchemy] breakage in 0.5.3 self-reference inherited types

2009-04-01 Thread kris
I am getting a new error with 0.5.3, I've tried to work around it but can't seem to find the right magic. Can't determine relation direction for relationship 'Taggable.owner' - foreign key columns are present in both the parent and the child's mapped tables. Specify 'foreign_keys' argument. An

[sqlalchemy] Re: Stale ORM Objects Locking Best Practice (for nested sets)

2009-04-01 Thread Randy Syring
Michael, Thanks for your reply. On Apr 1, 11:46 am, Michael Bayer mike...@zzzcomputing.com wrote: there's a nested set demo in the examples/ folder of the distribution, which uses MapperExtension as well as a little-used flag on the mapper called batch=False.   are you building off of that ?

[sqlalchemy] Re: concurrent 'upsert'

2009-04-01 Thread Jyotirmoy
On Apr 1, 9:22 pm, Yassen Damyanov yassen@gmail.com wrote: Jyotirmoy wrote: I want to know what is the best way to write code using sqlalchemy that given a value of the primary key inserts a record if no record with that key exists or updates the value of the other columns if the key