[sqlalchemy] app not closing when py2exe'd it

2008-05-25 Thread Werner F. Bruhin

I am having a problem with my app not closing correctly when I py2exe'd it.

Trying to track it down but with not much look so far and as sqlalchemy 
is one of the big changes I did in this version of the app (i.e. moved 
from another ORM to sqlalchemy) I wonder if there are some things I have 
to watch out for.

As I suspected SA I make sure that on close all my connections are 
closed and for good measure I also del my session and the engine.

Is there anything else I should watch out for? 

Is there some way I can check that I really closed all my connections?

Is SA using threads?  If yes, do I need to do something special to 
ensure that they are all closed/finished?

Appreciate any hints or tips.

Werner

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Can't figure out how to do query with sub-query and count through SA

2008-05-25 Thread gatto

ha..  i meant I'm now really close, not I'm not really close
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Can't figure out how to do query with sub-query and count through SA

2008-05-25 Thread gatto

On May 24, 10:51 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On May 25, 2008, at 1:04 AM, gatto wrote:
  been working all day long on this, and i don't feel like i've gotten
  any closer than when i started..  read all the related posts on this
  group and couldn't determine what to do based on those.  hoping
  someone can shed some light.

  i'm attempting to convert the codebase of an existing project i've
  developed to use SA.  going ok so far, but i'm stuck on an important
  query that contains a subquery and that subquery has a count
  function.  the original query looks like this:

 SELECT id, name, count
 FROM (
 SELECT t.id, t.name, COUNT(*) AS count
 FROM tags t, object_tags ot
 WHERE t.id= ot.tag_id
 AND ot.object_type_id = 2
 GROUP BY t.id, t.name
 ORDER BY COUNT(*) DESC, t.name ASC
 LIMIT 35
 ) AS t
 ORDER BY name ASC

  tho actually, i will be changing the LIMIT clause and the final ORDER
  BY clause depending on what the user chooses.  this is a query whose
  results are used to render a tag cloud..  i've got an intermediate
  table called 'object_types' that has a lookup of different types of
  entities that could be tagged.  e.g. articles or users.  so articles
  has the object_type_id 2 in the above sql, and that's what i'm
  generating the cloud for.  object_tags is the relation table that maps
  tags and object types to objects..

  i had to do the query this way so that i can first get the top [limit]
  number of tags ordered by count and name, and then being able to order
  that top tag result set further.  basically i'm just saying that i
  don't see a way to do this without the subselect..

  so, how would i go about doing this??  it seems like i need to use
  session.query(Tag) with from_statement, func and add_column, but i
  just can't figure it out.  i'm seriously just about to pull my hair
  out trying to understand what to do. any help is greatly appreciated!

 if you just want the columns back, you can issue the text directly, or
 use a select() construct, which would look like

 s = select([tags.c.id, tags.c.name,
 func.count('*').label('count')]).where(tags.c.id==object_tags.c.tag_id).
 where(object_tags.c.type_id==2).group_by([t.c.id,
 t.c.name]).order_by([func.count('*').desc(), t.c.name]).
 limit(35)

 rows = s.execute().fetchall()

 if you want to map id/name to a Tag object, in 0.4 you'd keep a
 select() like the above and use it with the Query.  it would be along
 the lines of
 sess
 .query(Tag).add_column(s.c.count).select_from(s).order_by(Tag.name) .

 Overall the query is not the best approach as you're mixing aggregates
 with primary keys (assuming tags.id is the primary key).  you really
 want the count of maching object_tags rows, I think:

 select tag.id, tag.name, obj_count from
 tags join
 (select tag_id, count('*') AS obj_count from object_tags where
 object_type_id=2 group by tag_id order by obj_count limit 35) as
 obj_tag_count
 on tags.id=obj_tag_count.id order by tag.name

 that way you keep unneeded columns out of the GROUP BY.  the subquery
 looks like:

 s = select([object_tags.c.tag_id,
 func
 .count('*').label('obj_count')]).where(object_tags.c.object_type_id==2).
 group_by(object_tags.c.tag_id).order_by(func.count('*')).limit(35)

 Note that the order_by() hits the func.count() again.   On some
 databases this is required (i.e., you can't ORDER BY a label).  If you
 truly want to force the label in there, say
 order_by(literal_column(obj_count)).

 then join it into an ORM query using the join:

 sess.query(Tag).add_column(s.c.obj_count).select_from(tags.join(s,
 Tag.id==s.c.tag_id)).order_by(Tag.name)

 The difference between the two approaches is described (in a little
 bit of a rant) here:  
 http://weblogs.sqlteam.com/jeffs/archive/2005/12/14/8546.aspx

you are absolutely correct..  thanks for the education!  i will be
using that technique in the future on all group by clauses.

thanks *so much* for the advice.  i'm not really close to being done
now i think.  i didn't mention before, but i'm actually using Elixir
also.  i didn't think it would matter for the querying, but i may be
wrong..  i got the select() part working well, nice...  but i'm
getting an error when i try to run the session.query() part.  here is
my full code now:

s = select([ObjectTag.c.tag_id, func.count('*').label('obj_count')]).\
where(ObjectTag.c.object_type_id == 2).\
group_by(ObjectTag.c.tag_id).\
order_by(desc(func.count('*'))).\
limit(35)

tags = session.query(Tag).add_column(s.c.obj_count).\
select_from(Tag.table.join(s, Tag.id ==
s.c.tag_id)).order_by(Tag.name)

for t in tags:
t.name

now i'm getting the error: sqlalchemy.exceptions.OperationalError:
(OperationalError) (1248, 'Every derived table must have its own
alias').  is this due to my using elixir?  somehow i don't think so..
i maybe just need to label the subquery?

[sqlalchemy] Fill automatically one column

2008-05-25 Thread Kless

One column could be filled automatically with the value of another 2
columns? If it's possible, how do it?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] New data types for PostgreSQL 8.3

2008-05-25 Thread Kless

PostgreSQL 8.3 has any new data types very interesting as enumerated
(ENUM) [1],  XML [2], Universally Unique Identifiers (UUID) [3].
Another interesting data type would be the monetary type [4].

It would very interesting that could be used from SQLAlchemy.


[1] http://www.postgresql.org/docs/8.3/static/datatype-enum.html
[2] http://www.postgresql.org/docs/8.3/static/datatype-xml.html
[3] http://www.postgresql.org/docs/8.3/static/datatype-uuid.html
[4] http://www.postgresql.org/docs/8.3/static/datatype-money.html

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---



[sqlalchemy] [Solved] Fill automatically one column

2008-05-25 Thread Kless

This is made from constructor --the __init__ method--.

On 25 mayo, 11:54, Kless [EMAIL PROTECTED] wrote:
 One column could be filled automatically with the value of another 2
 columns? If it's possible, how do it?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~--~~~~--~~--~--~---