[sqlalchemy] Dynamic making of the where clause

2009-06-23 Thread Ash

Hello,

I am tryin to make the dynamic where clause using append_whereclause.

But how i can do that,  For eg :

I have a==b and c in (1,2,3,4) or d like %s

So i made three sqlalchemy expression

1. a==b
2. c in (1,2,3,4) [ using in_]
3. d like %s [using like]

now i want this 3 to stuff in where clause .

I created select like sel = select()

How can i make the where clause which have and and  or both uisng
append_whereclause.

Thnks in advance


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Oracle: There are multiple tables visible...

2009-06-23 Thread Sven A. Schmidt

Hi,

I've hit a problem very recently with autoloading of table info from
an oracle schema which I believe is caused by a problem inside the
_resolve_synonym method of oracle/base.py. I've googled around a bit
but didn't find this issue reported previously. It may well be a
problem with our db setup but I'm hoping folks on this list will be
able to shed some light on it either way :)

What's happening is that in the db there are two rows returned when
running the query

select OWNER, TABLE_OWNER, TABLE_NAME, SYNONYM_NAME from ALL_SYNONYMS
WHERE table_name = 'REQUESTS';

Result:

AINV_REPORT AINV_OWNER  REQUESTSREQUESTS
AINV_USER   AINV_OWNER  REQUESTSREQUESTS

Inside _resolve_synonym this query is run and if len(rows) 1 the
following error is raised:

There are multiple tables visible to the schema, you must specify
owner

I tried specifying the owner (AINV_USER) by using the schema parameter
of Tables() but that in turn causes errors because parent/child
relations cannot be automatically determined (which they can just fine
if the script runs from the table owner's schema). The error is:
Could not determine join condition between parent/child tables on
relation... It looks like synonyms don't make the foreign key
constraints visible, just the table names themselves (but that's just
a guess).

Since I rely heavily on autoload, I'd have to specify a lot of
primaryjoins for the relations if I used the schema parameter.

I was thinking that perhaps the query used inside _resolve_synonyms
could/should include a check on the synonym owner to exclude multiple
matches of the same table exists as a synonym in another user's
schema. Or would that break other things?

In the meantime I'm trying to get rid of the extra synonyms but I'm
not sure if that can always be avoided nor if that's too fragile
overall. In the end that would mean that by creating extra synonyms
for another user a working script could break. Or am I missing
something here?

Any insight greatly appreciated! :)

Cheers,
Sven

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Why has sum been removed from sqlalchemy.orm.query.Query ?

2009-06-23 Thread Dan

Using sqlalchemy version 0.5.2, I've noticed that the sum method
seems to have been removed from Query :

session.query(MyClass).sum(MyClass.price)

'Query' object has no attribute 'sum'

I can't find this change documented anywhere : it was present in 0.4
as I recall.

Any reason for this ?

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: sqlalchemy 0.4.6 + python 2.3: many-to-many relation problem

2009-06-23 Thread Michael Bayer

david.radkow...@googlemail.com wrote:

 ha! got it! you were right, it's a vendor's python implementation
 problem. the custom python runtime put an instrumentation layer on top
 of  other classes and that why it breaks :D
 switched to the genuine python 2.3.5 and now it's fine :)

sowhy not switch to genuine python 2.6 ?  :)




 thanks for your input, as you pointed me in the right direction.

 cheers Michael !

 On Jun 22, 9:09 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 david.radkow...@googlemail.com wrote:

  Hi

  I'm a bit concerned why the same code works with SA 0.5. Actually when
  there is no data in the relation, the query returns an empty list;
  however, as soon as I put some data in, I got the error :O
  I tried with 0.4.9dev...something as well, the same result though :/

  Am missing the point here? Do all tables/mappers have to be defined in
  the same context/module?

 no.  As I said, as far as what the stack trace indicates, you are doing
 something with pickling, direct __dict__ access, or custom
 instrumentation
 mods that is not compatible with 0.4.  It might be something else too,
 but
 none of the sample code you have provided provides any insight into what
 might be causing the error.  you would have to provide a succinct and
 fully reproducing (read: we can run it here) test case in order to
 provide
 more clues.



  Thanks

  On Jun 22, 8:38 pm, Michael Bayer mike...@zzzcomputing.com wrote:
  that error would have something to do with pickling, direct __dict__
  access on instances, or playing around with instrumentation
 extensions.
   
   that's as much as can be said based on what you've given.

  aside from whatever reasons for using Py2.3, why ever would you go
  straight to 0.4.6 and not 0.4.8 ?

  david.radkow...@googlemail.com wrote:

   Hi

   I've got a small problem with my python code proted from 0.5 (p2.5)
 to
   0.4.6 (p2.3).
   When I try to load query objects from many-to-many relation (mapped
   via secondary keyword) I get most weird error:

   Traceback (most recent call last):
     File string, line 86, in ?
     File X, line 17, in call_from_unix
     File X, line 12, in test
     File
 /usr/lib/python2.3/site-packages/SQLAlchemy-0.4.6-py2.3.egg/
   sqlalchemy/orm/attributes.py, line 44, in __get__
       return self.impl.get(instance._state)
     File
 /usr/lib/python2.3/site-packages/SQLAlchemy-0.4.6-py2.3.egg/
   sqlalchemy/orm/attributes.py, line 281, in get
       return self.set_committed_value(state, value)
     File
 /usr/lib/python2.3/site-packages/SQLAlchemy-0.4.6-py2.3.egg/
   sqlalchemy/orm/attributes.py, line 635, in set_committed_value
       collection.append_without_event(item)
     File
 /usr/lib/python2.3/site-packages/SQLAlchemy-0.4.6-py2.3.egg/
   sqlalchemy/orm/collections.py, line 540, in append_without_event
       getattr(self._data(), '_sa_appender')(item,
 _sa_initiator=False)
   AttributeError: 'InstrumentedList' object has no attribute
   '_sa_appender'

   Any idea what is going on? It doesn't happen with sa  0.5

   Any help will be much appreciated
   Cheers

   The tables look like follows:
   -
   import sqlalchemy;
   import sqlalchemy.orm;
   import rfang.model.rfablcklstinstr;
   import rfang.model.rfaruntime;

   t_RfaEnvironment = None;
   t_RfaEnvironment_RfaBlcklstInstr = None;

   def initializeTable(metadata): #{{{
       global t_RfaEnvironment;
       global t_RfaEnvironment_RfaBlcklstInstr;
       if(t_RfaEnvironment == None):
           t_RfaEnvironment = sqlalchemy.Table(RuntimeConfigType,
   metadata,
               sqlalchemy.Column
   (id,sqlalchemy.types.Integer,sqlalchemy.schema.Sequence
   (id_RuntimeConfigType),primary_key=True),
               sqlalchemy.Column(name,sqlalchemy.types.Unicode
   (10),nullable=False,unique=True),
               sqlalchemy.Column(filename,sqlalchemy.types.Unicode
   (100),nullable=False),
               sqlalchemy.Column(filtername,sqlalchemy.types.Unicode
   (255),nullable=False),
               useexisting=True
           );
           rfang.model.rfablcklstinstr.initializeTable(metadata);
           t_RfaEnvironment_RfaBlcklstInstr = sqlalchemy.Table
   (RuntimeConfigType_Blacklist, metadata,
               sqlalchemy.Column
   (runtimeConfigType_id,sqlalchemy.types.Integer,sqlalchemy.ForeignKey
   ('RuntimeConfigType.id')),
               sqlalchemy.Column
   (blacklist_id,sqlalchemy.types.Integer,sqlalchemy.ForeignKey
   ('Blacklist.id')),
               useexisting=True
           );
       return;
   #def }}}

   def initializeMapper(): #{{{
       global t_RfaEnvironment;
       global t_RfaEnvironment_RfaBlcklstInstr;
       sqlalchemy.orm.mapper( RfaEnvironment, t_RfaEnvironment,
   properties = {
           rfaruntimes : sqlalchemy.orm.relation
   (rfang.model.rfaruntime.RfaRuntime,backref=rfaenvironment,cascade=all,delete,delete-
  

[sqlalchemy] Re: Validators: Define at table / mapper level ?

2009-06-23 Thread Michael Bayer

AF wrote:

 Hello,

 Can validators be defined at table / mapper level?   (Is it even a
 good idea?)

 I ask, since it's at the table definition layer that I define what
 datatypes my columns have, so it seems natural to place the policing
 function there as well.


a table level validator would be a database-side CHECK CONSTRAINT or
trigger.

If you have mapper definitions separate from classes, theres nothing
stopping you from adding attributes to the class over there, i.e.

mapper(MyClass, mytable)

MyClass.foo = some_validation_decorator(MyClass.foo)

Personally I wouldn't bother (then again I use declarative for everything
now).




 :)
 



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Oracle: There are multiple tables visible...

2009-06-23 Thread Michael Bayer

Sven A. Schmidt wrote:

 Hi,

 I've hit a problem very recently with autoloading of table info from
 an oracle schema which I believe is caused by a problem inside the
 _resolve_synonym method of oracle/base.py. I've googled around a bit
 but didn't find this issue reported previously. It may well be a
 problem with our db setup but I'm hoping folks on this list will be
 able to shed some light on it either way :)

 What's happening is that in the db there are two rows returned when
 running the query

 select OWNER, TABLE_OWNER, TABLE_NAME, SYNONYM_NAME from ALL_SYNONYMS
 WHERE table_name = 'REQUESTS';

 Result:

 AINV_REPORT   AINV_OWNER  REQUESTSREQUESTS
 AINV_USER AINV_OWNER  REQUESTSREQUESTS

 Inside _resolve_synonym this query is run and if len(rows) 1 the
 following error is raised:

 There are multiple tables visible to the schema, you must specify
 owner

 I was thinking that perhaps the query used inside _resolve_synonyms
 could/should include a check on the synonym owner to exclude multiple
 matches of the same table exists as a synonym in another user's
 schema. Or would that break other things?


this assumes that you need to use the resolve_synonyms feature in the first
place (its off by default).   oracle_resolve_synonyms is probably not
worth using if you aren't using DBLINK (and maybe not even if you are) -
that was the original use case for it.   If you leave the feature off and
just reflect requests, the whole function won't get involved.



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Why has sum been removed from sqlalchemy.orm.query.Query ?

2009-06-23 Thread Michael Bayer

Dan wrote:

 Using sqlalchemy version 0.5.2, I've noticed that the sum method
 seems to have been removed from Query :

 session.query(MyClass).sum(MyClass.price)

 'Query' object has no attribute 'sum'

 I can't find this change documented anywhere : it was present in 0.4
 as I recall.

looks like we did apply_sum() but not sum().   its redundant.   use
query.value(func.sum(somecolumn)).



--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Why has sum been removed from sqlalchemy.orm.query.Query ?

2009-06-23 Thread Dan Jacob

That worked great, thanks for your help.

2009/6/23 Michael Bayer mike...@zzzcomputing.com:

 Dan wrote:

 Using sqlalchemy version 0.5.2, I've noticed that the sum method
 seems to have been removed from Query :

 session.query(MyClass).sum(MyClass.price)

 'Query' object has no attribute 'sum'

 I can't find this change documented anywhere : it was present in 0.4
 as I recall.

 looks like we did apply_sum() but not sum().   its redundant.   use
 query.value(func.sum(somecolumn)).



 




-- 
Dan Jacob
Skype: danjac40
Mobile: (++44) (0)7735452075

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: many-to-many relation, 'secondaryjoin' is needed as well

2009-06-23 Thread Aculeus

Can you post your solution?

On Jun 2, 6:38 am, Gera88 gger...@gmail.com wrote:
 Oh I did it

 Thanks!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Oracle: There are multiple tables visible...

2009-06-23 Thread Sven A. Schmidt

Michael,

thanks for your reply! Unfortunately, I believe I have to use the
synonyms feature, because I cannot use the table owner's schema owner
to access the database. Everything works if I use the table owner's
schema (AINV_OWNER) but the db policies forbid this for production, so
I have to somehow get this to work from another account.

I should have elaborated on this in my initial mail -- I went through
the following combinations of options as I far as I am aware of them
to try and work around the problem:

1. no synonym parameter, no schema parameter on Table(...)
Results in the error: Couldn't find any column information... This
is obvious: AINV_USER doesn't own the tables and in the absence of the
schema parameter SQLA can't find any table info

2. no synonym parameter, schema = 'AINV_OWNER' on Table(...)
Results in the error: Could not determine join condition between
parent/child tables... I had expected this to work but it seems that
for some reason SQLA doesn't see the constraint info on tables in
another user's schema. Is that a bug? I could work around this but it
would mean I have to manually specify all relations which are
correctly read from the db if I connect with the table owner schema.
I'd like to avoid doing that, because I'm lazy ;)

3. synonym parameter, no schema parameter on Table(...)
Results in the error: There are multiple tables visible... As
described, this results from the _resolve_synonym call in base.py.

4. synonym parameter, schema = 'AINV_OWNER' on Table(...)
Results in the error: Could not determine join condition between
parent/child tables... See 2) above.

It seems I'm stuck between a rock and a hard place here ;)

Cheers,
Sven

On Jun 23, 5:03 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Sven A. Schmidt wrote:

  Hi,

  I've hit a problem very recently with autoloading of table info from
  an oracle schema which I believe is caused by a problem inside the
  _resolve_synonym method of oracle/base.py. I've googled around a bit
  but didn't find this issue reported previously. It may well be a
  problem with our db setup but I'm hoping folks on this list will be
  able to shed some light on it either way :)

  What's happening is that in the db there are two rows returned when
  running the query

  select OWNER, TABLE_OWNER, TABLE_NAME, SYNONYM_NAME from ALL_SYNONYMS
  WHERE table_name = 'REQUESTS';

  Result:

  AINV_REPORT        AINV_OWNER      REQUESTS        REQUESTS
  AINV_USER  AINV_OWNER      REQUESTS        REQUESTS

  Inside _resolve_synonym this query is run and if len(rows) 1 the
  following error is raised:

  There are multiple tables visible to the schema, you must specify
  owner

  I was thinking that perhaps the query used inside _resolve_synonyms
  could/should include a check on the synonym owner to exclude multiple
  matches of the same table exists as a synonym in another user's
  schema. Or would that break other things?

 this assumes that you need to use the resolve_synonyms feature in the first
 place (its off by default).   oracle_resolve_synonyms is probably not
 worth using if you aren't using DBLINK (and maybe not even if you are) -
 that was the original use case for it.   If you leave the feature off and
 just reflect requests, the whole function won't get involved.
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Oracle: There are multiple tables visible...

2009-06-23 Thread Michael Bayer

Sven A. Schmidt wrote:

 Michael,

 thanks for your reply! Unfortunately, I believe I have to use the
 synonyms feature, because I cannot use the table owner's schema owner
 to access the database. Everything works if I use the table owner's
 schema (AINV_OWNER) but the db policies forbid this for production, so
 I have to somehow get this to work from another account.

its been awhile since I've used oracle, but I seem to recall that the
permissions on a synonym have no bearing on whether or not you can access
the underlying table - you need permissions on both.   am I incorrect on
this ?


 2. no synonym parameter, schema = 'AINV_OWNER' on Table(...)
 Results in the error: Could not determine join condition between
 parent/child tables... I had expected this to work but it seems that
 for some reason SQLA doesn't see the constraint info on tables in
 another user's schema. Is that a bug?

that would be a bug, yes.   but, try specifying schema and all the names
using lowercase characters (not ALL_UPPERCASE as you may be doing) - SQLA
will ensure that it uses case insensitive identifiers (it converts to
uppercase as needed when talking to oracle).  its possible that there is a
mismatch between target names and specified names causing this issue.  or
maybe the oracle dialect just doesn't interpret the owner part of a
foreign key constraint correctly yet (im not easily able to test things
like that with Oracle XE).

Also, if your reflection can't read the tables directly, that would also
be a potential explanation for this problem.


 3. synonym parameter, no schema parameter on Table(...)
 Results in the error: There are multiple tables visible... As
 described, this results from the _resolve_synonym call in base.py.

did you propose that the current default owner on the connection would
match to the synonym owner ?


 4. synonym parameter, schema = 'AINV_OWNER' on Table(...)
 Results in the error: Could not determine join condition between
 parent/child tables... See 2) above.

thats a dupe of #2.


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Validators: Define at table / mapper level ?

2009-06-23 Thread allen.fowler


 If you have mapper definitions separate from classes, theres nothing
 stopping you from adding attributes to the class over there, i.e.

 mapper(MyClass, mytable)

 MyClass.foo = some_validation_decorator(MyClass.foo)

 Personally I wouldn't bother (then again I use declarative for everything
 now).



Perhaps I should try declarative... are there any gotcha's to know
about?


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: sqlalchemy 0.4.6 + python 2.3: many-to-many relation problem

2009-06-23 Thread david.radkow...@googlemail.com

no chance :( legacy third party C extension libraries :(

On Jun 23, 3:50 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 david.radkow...@googlemail.com wrote:

  ha! got it! you were right, it's a vendor's python implementation
  problem. the custom python runtime put an instrumentation layer on top
  of  other classes and that why it breaks :D
  switched to the genuine python 2.3.5 and now it's fine :)

 sowhy not switch to genuine python 2.6 ?  :)



  thanks for your input, as you pointed me in the right direction.

  cheers Michael !

  On Jun 22, 9:09 pm, Michael Bayer mike...@zzzcomputing.com wrote:
  david.radkow...@googlemail.com wrote:

   Hi

   I'm a bit concerned why the same code works with SA 0.5. Actually when
   there is no data in the relation, the query returns an empty list;
   however, as soon as I put some data in, I got the error :O
   I tried with 0.4.9dev...something as well, the same result though :/

   Am missing the point here? Do all tables/mappers have to be defined in
   the same context/module?

  no.  As I said, as far as what the stack trace indicates, you are doing
  something with pickling, direct __dict__ access, or custom
  instrumentation
  mods that is not compatible with 0.4.  It might be something else too,
  but
  none of the sample code you have provided provides any insight into what
  might be causing the error.  you would have to provide a succinct and
  fully reproducing (read: we can run it here) test case in order to
  provide
  more clues.

   Thanks

   On Jun 22, 8:38 pm, Michael Bayer mike...@zzzcomputing.com wrote:
   that error would have something to do with pickling, direct __dict__
   access on instances, or playing around with instrumentation
  extensions.
    
    that's as much as can be said based on what you've given.

   aside from whatever reasons for using Py2.3, why ever would you go
   straight to 0.4.6 and not 0.4.8 ?

   david.radkow...@googlemail.com wrote:

Hi

I've got a small problem with my python code proted from 0.5 (p2.5)
  to
0.4.6 (p2.3).
When I try to load query objects from many-to-many relation (mapped
via secondary keyword) I get most weird error:

Traceback (most recent call last):
  File string, line 86, in ?
  File X, line 17, in call_from_unix
  File X, line 12, in test
  File
  /usr/lib/python2.3/site-packages/SQLAlchemy-0.4.6-py2.3.egg/
sqlalchemy/orm/attributes.py, line 44, in __get__
    return self.impl.get(instance._state)
  File
  /usr/lib/python2.3/site-packages/SQLAlchemy-0.4.6-py2.3.egg/
sqlalchemy/orm/attributes.py, line 281, in get
    return self.set_committed_value(state, value)
  File
  /usr/lib/python2.3/site-packages/SQLAlchemy-0.4.6-py2.3.egg/
sqlalchemy/orm/attributes.py, line 635, in set_committed_value
    collection.append_without_event(item)
  File
  /usr/lib/python2.3/site-packages/SQLAlchemy-0.4.6-py2.3.egg/
sqlalchemy/orm/collections.py, line 540, in append_without_event
    getattr(self._data(), '_sa_appender')(item,
  _sa_initiator=False)
AttributeError: 'InstrumentedList' object has no attribute
'_sa_appender'

Any idea what is going on? It doesn't happen with sa  0.5

Any help will be much appreciated
Cheers

The tables look like follows:
-
import sqlalchemy;
import sqlalchemy.orm;
import rfang.model.rfablcklstinstr;
import rfang.model.rfaruntime;

t_RfaEnvironment = None;
t_RfaEnvironment_RfaBlcklstInstr = None;

def initializeTable(metadata): #{{{
    global t_RfaEnvironment;
    global t_RfaEnvironment_RfaBlcklstInstr;
    if(t_RfaEnvironment == None):
        t_RfaEnvironment = sqlalchemy.Table(RuntimeConfigType,
metadata,
            sqlalchemy.Column
(id,sqlalchemy.types.Integer,sqlalchemy.schema.Sequence
(id_RuntimeConfigType),primary_key=True),
            sqlalchemy.Column(name,sqlalchemy.types.Unicode
(10),nullable=False,unique=True),
            sqlalchemy.Column(filename,sqlalchemy.types.Unicode
(100),nullable=False),
            sqlalchemy.Column(filtername,sqlalchemy.types.Unicode
(255),nullable=False),
            useexisting=True
        );
        rfang.model.rfablcklstinstr.initializeTable(metadata);
        t_RfaEnvironment_RfaBlcklstInstr = sqlalchemy.Table
(RuntimeConfigType_Blacklist, metadata,
            sqlalchemy.Column
(runtimeConfigType_id,sqlalchemy.types.Integer,sqlalchemy.ForeignKey
('RuntimeConfigType.id')),
            sqlalchemy.Column
(blacklist_id,sqlalchemy.types.Integer,sqlalchemy.ForeignKey
('Blacklist.id')),
            useexisting=True
        );
    return;
#def }}}

def initializeMapper(): #{{{
    global t_RfaEnvironment;
    global 

[sqlalchemy] Re: preview an update?

2009-06-23 Thread Catherine Devlin
On Thu, Jun 18, 2009 at 4:57 PM, Michael Bayermike...@zzzcomputing.com wrote:

 you can get most of this stuff from the session without any flush
 occurring.  at the object level are the new, dirty, and deleted
 collections on Session.   At the attribute level the
 attributes.get_history() method will illustrate the full changes made
 since the last flush on an individual object attribute.  get_history()
 should be in the API docs.

Thank you!  get_history is just what I needed.  However, I spent a
long time being confused by something that I think is a very obscure
bug.

If you make an update to a table that has a relation to a view, then
get_history on an attribute in the view, then the history is
forgotten.  I'm attaching a file that duplicates it completely, but
here's the gist of it (after setting up as described in the docs' ORM
tutorial):

 ed = session.query(User).first()
 print sqlalchemy.orm.attributes.get_history(ed, 'fullname')
((), [u'Ed Jones'], ())
 ed.fullname = 'Eduardo Jones'
 print sqlalchemy.orm.attributes.get_history(ed, 'fullname')
(['Eduardo Jones'], (), [u'Ed Jones'])
 # so far so good
 print sqlalchemy.orm.attributes.get_history(ed.userview, 'name')
((), [u'ed'], ())
 print sqlalchemy.orm.attributes.get_history(ed, 'fullname')
((), ['Eduardo Jones'], ())

... now get_history thinks fullname has always been Eduardo Jones.

Is this a bug I should file, or something I should have expected?

Thanks as always!
-- 
- Catherine
http://catherinedevlin.blogspot.com/
*** PyOhio * July 25-26, 2009 * pyohio.org ***

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---

from sqlalchemy import create_engine
engine = create_engine('sqlite:///:memory:', echo=False)
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
metadata = MetaData()
users_table = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(12)),
Column('fullname', String(40)),
Column('password', String(40))
)
metadata.create_all(engine) 

class User(object):
def __init__(self, name, fullname, password):
self.name = name
self.fullname = fullname
self.password = password

def __repr__(self):
   return User('%s','%s', '%s') % (self.name, self.fullname, self.password)

from sqlalchemy.orm import mapper, relation, backref
mapper(User, users_table) 

ed_user = User('ed', 'Ed Jones', 'edspassword')

from sqlalchemy.orm import sessionmaker
Session = sessionmaker(bind=engine)
session = Session()
session.add(ed_user)
session.commit()

#
# everything up to here comes from the ORM tutorial at http://www.sqlalchemy.org/docs/05/ormtutorial.html

engine.connect().execute('CREATE VIEW userview AS SELECT id, name FROM users')
class UserView(object):
pass
userview = Table('userview', metadata, 
 Column('id', ForeignKey('users.id'), primary_key=True), 
 autoload=True, autoload_with=engine)
mapper(UserView, userview,
   properties={'user': relation(User, uselist=False, lazy=True,
   backref=backref('userview', uselist=False))})   

import sqlalchemy.orm.attributes
ed = session.query(User).first()
print sqlalchemy.orm.attributes.get_history(ed, 'fullname')
ed.fullname = 'Eduardo Jones'
print sqlalchemy.orm.attributes.get_history(ed, 'fullname')
print sqlalchemy.orm.attributes.get_history(ed.userview, 'name')
print sqlalchemy.orm.attributes.get_history(ed, 'fullname')


[sqlalchemy] Re: preview an update?

2009-06-23 Thread Michael Bayer

Catherine Devlin wrote:
 (['Eduardo Jones'], (), [u'Ed Jones'])
 # so far so good
 print sqlalchemy.orm.attributes.get_history(ed.userview, 'name')
 ((), [u'ed'], ())
 print sqlalchemy.orm.attributes.get_history(ed, 'fullname')
 ((), ['Eduardo Jones'], ())

 ... now get_history thinks fullname has always been Eduardo Jones.

 Is this a bug I should file, or something I should have expected?

I'm going to say that ed.userview did a lazy load and triggered an
autoflush.  the autoflush will reset the attributes back to unchanged so
that is expected.

--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: How can I use count with group_by with webhelpers.paginate

2009-06-23 Thread Alisue

Thanks! That is the what i want.

On 6月22日, 午後11:40, Michael Bayer mike...@zzzcomputing.com wrote:
 Alisue wrote:

  Oops. I found the solution with my self.

  like below.

  c.paginator = paginate.Page(
  meta.Session.query(Article).select_from(query.subquery()),
  page=int(request.params.get('page',1)),
  items_per_page=int(request.params.get('items_per_page', 10))
  )

  But why can't I do like below? or similar way?

  query.select_from(query.subquery())

 that is what query.from_self() does.



  On 6月22日, 午後6:34, Alisue
  hello.goodbye.by.beat...@gmail.com wrote:
  I have a Article table may relate with a Room table and I want to find
  Article sometime with Room.name.
  So I wrote the code like below.

  query = meta.Session.query(Article)
  query = query.outerjoin('rooms')
  if room_name is not None:
  query = query.filter(Room.name == room_name)
  query = query.group_by(Article.id)
  return query

  A result is correct. I got all Article name without room_name and
  Articles which has rooms named as room_name.

  However, when I use this query with webhelpers.paginate(http://
  beta.pylonshq.com/docs/ja/0.9.7/thirdparty/webhelpers/paginate/
  #webhelpers.paginate.Page), everything goes wrong. 'paginator' doesn't
  work correct.

  So I chacked logs and find this output.
   'SELECT COUNT(1) AS count_1 FROM articles LEFT OUTER JOIN rooms ON
  articles.id = rooms.article_id GROUP BY articles.id'

  This is might made by .count() function of sqlalchemy in somewhere in
  webhelpers.paginate code I think. However what I want to get is
  'SELECT COUNT(1) AS count_1 FROM (SELECT * FROM articles LEFT OUTER
  JOIN rooms ON articles.id = rooms.article_id GROUP BY articles.id)'

  I have no idea to fix this problem. Anyone? thank you.

  SQLAlchemy: 0.5.4
  Pylons: 0.9.7
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---