[sqlalchemy] Can we include this new url traversal with cherrypy?

2007-02-28 Thread vinjvinj

There was a post about a new url traversal implemented in turbogears
on top of cherrypy (with ideas being borrowed from Nevow):

https://projects.isotoma.com/tgnewtraversal

Looks very cool indeed. Is there any way to integrate this with the
cherrypy distribution?

Vineet


--~--~-~--~~~---~--~~
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: How do I get columns in sqlalchemy group by function

2007-02-28 Thread vinjvinj

Thanks.

On Feb 27, 11:20 am, Jonathan Ellis [EMAIL PROTECTED] wrote:
 group_by_column.clauses[0] is the object you passed to func.sum

 On 2/27/07, vinjvinj [EMAIL PROTECTED] wrote:



  I have the following columns in some of my select columns:

  group_by_column = sqlalchemy.func.sum(column1)

  How do I get column1 from the group_by_column object (In other words
  is there any way to find out what columns the function is going to be
  applied to?). I did a dir(group_by_column) and saw that it had a field
  called columns, but that did not have the values I was looking for.

  Thanks,

  VJ


--~--~-~--~~~---~--~~
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: rev2362 fixes one thing and breaks another

2007-02-28 Thread svilen
ok, here the cleaned case. 

Problem appears if A-B-C, A references B, B-mapper is polymorphic 
too, and there are 3 instances saved - A,B,C.

It is similar as in 
http://groups.google.com/group/sqlalchemy/browse_thread/thread/5f05c11e3c168fb5/3c956e71dc724214#3c956e71dc724214
but there the lazy-load was not loading at all (which 2362 fixed), 
while in current case different object is loaded (C instead of B) - 
for pre-2362 - and mapper-compilation fails in 2362+.


 I really have no idea how this test works, i cant understand what
 conditions are being tested when you say

  expects = [
dict( klas= A, table= table_A, oid= a.db_id, exp_single= str(a),
  exp_multi = [ str(a), str(b), str(c) ]),

well, it just tests if the str(newobject) matches the str(oldobject), 
where the newobject is getby(id) and __str__() is made to include 
everything interesting.

 and im generally fairly uninterested in A-B-C-D inheritance in a
 database, so youll have to put some more effort into breaking this
 problem down into something simple and readable and also with all
 extraneous conditions removed (such as, if you remove the B and C
 polymorphic joins it still fails - please make that effort for me),
 because i really dont have time to decode these tests.

u can remove whole polymorphic_union on A and replace it by 
tableA.select() and it still fails in same way.
But, if u make it work without the union, it may or may not work with 
the union. So that makes 2 testcases then ;-)

i've tried to remove more stuff but then the bug runs away. 
It does not need an instance of C, and it does not need a C-join 
inside B-union, but it needs the C mapper to inherit B-mapper.

ciao
svil

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



_test-ABC-t.py
Description: application/python


[sqlalchemy] Re: contains_eager is somehow not loading all the instances.

2007-02-28 Thread Dennis

That's the problem, if I have use_labels=True, and I include as
somecolumn in the text clause, I still get a generated label.  The
resulting sql =
. as somecolumn as
somelonglabelthatisashortenedversionofthetext.  that creates an sql
error.

On Feb 27, 3:51 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 yeah with text just say as sometable_somecolumn.

 On Feb 27, 2007, at 4:16 PM, Dennis wrote:



  Well, columnname isn't a simple column in the case of a case
  statement... the label is turning out like this:

  casewhenhas_testtrueandscoreisnullandgender1then1whenscoreisnullthen2
  elsescoreend

  I haven't found a way to manually assign a label to a text clause yet,
  but before I tried use_labels=True, I has appended as score to the
  case clause and that worked.

  On Feb 27, 2:44 pm, Michael Bayer [EMAIL PROTECTED] wrote:
  the label is always tablename_columnname.   youd have to show me
  where you need that to be programmatic.

  On Feb 27, 2007, at 2:29 PM, Dennis wrote:

  Thanks for taking a peek.

  Interesting, it does indeed fix the issue to use labels.  Now I have
  another issue though, I have a case statement in my select which
  I was
  specifying like this:

  select ( ['case when  yada yada yada end as something' ] ..

  If use_labels = True, then the query breaks because the generated
  sql
  has two as label parts two it.

  if I delete the as something part, I think don't know
  programatically what the label is though.  I need to know that
  because
  I order by it.

  Isn't there a way to find out a column label from a query?

  -Dennis

  On Feb 27, 12:47 pm, Michael Bayer [EMAIL PROTECTED] wrote:
  if you run it with full blown logging on, i.e.:

  import logging
  logging.basicConfig()
  logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
  logging.getLogger('sqlalchemy.orm').setLevel(logging.DEBUG)

  the issue can be detected when you look at the mapper creating
  instance keys for T (although this is clearly not a novice
  issue):

  DEBUG:sqlalchemy.orm.mapper.Mapper:(T|ts) _instance(): identity key
  (class '__main__.T', (1,), None) not in session[]
  DEBUG:sqlalchemy.orm.mapper.Mapper:(T|ts) _instance(): identity key
  (class '__main__.T', (None,), None) not in session[]
  DEBUG:sqlalchemy.orm.mapper.Mapper:(T|ts) _instance(): identity key
  (class '__main__.T', (3,), None) not in session[]
  DEBUG:sqlalchemy.orm.mapper.Mapper:(T|ts) _instance(): identity key
  (class '__main__.T', (None,), None) not in session[]
  DEBUG:sqlalchemy.orm.mapper.Mapper:(T|ts) _instance(): identity key
  (class '__main__.T', (5,), None) not in session[]

  so its not getting an identity key for every other row, which
  indicates its looking at the wrong column in the result set.   (on
  each of those Nones, its going to skip that entity) looking at
  the
  query:

  SELECT ts.id, ts.dat, other.ts_id, other.other_dat
  FROM ts LEFT OUTER JOIN other ON ts.id = other.ts_id

  we can see that other has a column called ts_id, which looks
  exactly like the label that would be made for id in table
  ts.  so
  thats whats happening here.   so throwing on a use_labels=True to
  the query (or changing the name of ts_id) produces the query:

  SELECT ts.id AS ts_id, ts.dat AS ts_dat, other.ts_id AS
  other_ts_id,
  other.other_dat AS other_other_dat
  FROM ts LEFT OUTER JOIN other ON ts.id = other.ts_id

  that gives the correct results.

  not sure what SA can really do here to make this kind of issue
  easier
  to catch, since the resultproxy itself is where its looking for
  col
  label, col name, , etc.  the generated labels are generally more
  accurate.  i tried playing around with ResultProxy to make it
  detect
  an ambiguity of this nature, but i think it might not be possible
  unless more flags/switches get passed from the statement to the
  result (which id rather not do since it further marginalizes
  straight
  textual queries), since if the select statement uses table/col
  labels
  for each column, there still could be conflicts which dont matter,
  such as the column names the normal eager loader generates:

  'ts_id', 'ts_dat', 'other_4966_ts_id', 'other_4966_other_dat',

  that result is from column ts_id attached to an Alias
  other_4966.  if we said dont allow any Column to be found
  twice in
  the row, then that breaks (since it will match other_4966_ts_id on
  its _label, ts_id on its name).

  On Feb 27, 2007, at 12:09 PM, Dennis Muhlestein wrote:

  from sqlalchemy import *

  e=create_engine('sqlite://memory')
  ts=Table('ts',e,
 Column ( 'id',Integer,primary_key=True),
 Column ( 'dat',Integer,nullable=False))
  ts.create()

  to_oneornone=Table('other',e,
 Column ( 'ts_id', Integer,ForeignKey('ts.id'),
  primary_key=True,
  nullable=False ),
 Column ( 'other_dat', Integer, nullable=False ) )
  to_oneornone.create()

  class T(object): pass
  T.mapper=mapper(T,ts)

  class To(object):pass
  

[sqlalchemy] Re: rev2362 fixes one thing and breaks another

2007-02-28 Thread svilen


 like this one...this does your generating thing.  but much easier
 to understand, since the actual test is clearly spelled out:

 http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/test/orm/
 abc_inheritance.py

does that work under postgress? 
i mean the duplicating id-column issue, for the B-join.

--~--~-~--~~~---~--~~
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] Transaction nesting with session.create_transaction()

2007-02-28 Thread Rick Morrison
Hi all,

I'm trying to mix ORM transactions and SQL transaction as follows:

T1 = S.create_transaction()
# do some ORM stuff
C1 = T1.connection()
C2.execute(sql)

T2 = S.create_transaction()
# nested ORM stuff

C2 = T2.connection()
C2.execute(sql)

T2.commit()  # should not commit (I think), but does!

C1.execute(sql)   # ERROR: this connection is closed

 Is this not supposed to work?

Thx,

Rick

--~--~-~--~~~---~--~~
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: Running initialization code after creating/loading an object

2007-02-28 Thread Rick Morrison
Hi Sanjay,

Mapper Extension is the way to do this. I use one we call our compiler
extension, it fires events before database insert, datase update and after
database load; you can use these events to modify the object as needed. You
can probably hack this into what you need:

class CompilerExtension(MapperExtension):
 Allows for compilation of sub-items into binary blobs stored on
the parent 
def before_insert(self, mapper, connection, instance):
instance.oninsert()
return EXT_PASS
def before_update(self, mapper, connection, instance):
instance.onupdate()
return EXT_PASS
def populate_instance(self, mapper, selectcontext, row, instance,
identitykey, isnew):
if isnew:
mapper.populate_instance(selectcontext, instance, row,
identitykey, isnew)
instance.onload()
return None
return EXT_PASS

The code for the onload is a bit tangled, because SA does not (yet)
provide an after db load, just a before. I've asked Mike for another
after hook (bump, bump), but I think he may have forgotten (bump) about
(bump) it (bump...).

Rick






On 2/28/07, Sanjay [EMAIL PROTECTED] wrote:


 Hi All,

 Needing help badly. Summarizing my problem: I need to run some
 initialization code after an object is retrieved from database. Say I
 have a table Person(first_name, last_name), I need that while the
 object is fetched, another instance variable named full_name is
 assigned as firstname + last_name.

 Tried to use MapperExtension by going through the suggestions in some
 threads, in the FAQ and the doc, but could not secceed. Also, could
 not find out how to use __new__ in this scenario. Surely my
 noviceness, either in Python or SQLAlchemy.

 Some sample code or specific guidence could help a lot.

 thanks
 Sanjay


 


--~--~-~--~~~---~--~~
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: Transaction nesting with session.create_transaction()

2007-02-28 Thread Michael Bayer

the nesting should work fine I just added a small test case to check  
that.  you can look at the test case and see if you can break it.   
the C1 below is closed because your T2 probably is committing for  
some reason but i dont know why.


On Feb 28, 2007, at 11:56 AM, Rick Morrison wrote:

 Hi all,

 I'm trying to mix ORM transactions and SQL transaction as follows:

 T1 = S.create_transaction()
 # do some ORM stuff
 C1 = T1.connection()
 C2.execute(sql)

 T2 = S.create_transaction ()
 # nested ORM stuff

 C2 = T2.connection()
 C2.execute(sql)

 T2.commit()  # should not commit (I think), but does!

 C1.execute(sql)   # ERROR: this connection is closed

  Is this not supposed to work?

 Thx,

 Rick

 


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