[sqlalchemy] session of an object

2009-03-25 Thread Alessandro Dentella

Hi,

  is there a way to get the session an object belongs to?
  I have been looking around and cannot find any function/way for that...

  Thanks in advance
  sandro
  *:-)

-- 
Sandro Dentella  *:-)
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

--~--~-~--~~~---~--~~
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: session of an object

2009-03-25 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 24.03.2009 23:01 Uhr, Alessandro Dentella wrote:
 Hi,
 
   is there a way to get the session an object belongs to?
   I have been looking around and cannot find any function/way for that...
 

object_session(obj)

- -aj
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAknJ1kcACgkQCJIWIbr9KYw7jgCgyZtDLWSja9NBFQc+ksbcChlr
QjoAoNmzUD8NNq6zi7ZSIVD6xVJqTWU3
=Duu+
-END PGP SIGNATURE-

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

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd.  Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:i...@zopyx.com
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



[sqlalchemy] deepcopy of sqlalchemy object

2009-03-25 Thread Ash

I have made some sql.expression  and add them in dict like

{'where':[ sqlalchemy.sql.expression._BinaryExpression object at
0x97680ec]} something like this

In the process it goes in some other dict

When now i try to do deepcopy i get error

File /var/lib/python-support/python2.5/sqlalchemy/util.py, line 574,
in __setitem__
 self._list.append(key)
AttributeError: 'OrderedDict' object has no attribute '_list'



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

2009-03-25 Thread alex

It gets result - first row. But I have an error TypeError:
datetime.datetime(2009, 3, 11, 9, 56, 6) is not JSON serializable
--~--~-~--~~~---~--~~
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: 0.5.2 seems to always roll back with mssql

2009-03-25 Thread lurcher

Hi,

I don't know if I can add any further to this, but I have just been
looking at this exact problem with our (Easysoft) SQL Server driver.
And one thing we have found is that you get different results
depending on which version of TDS the driver is using. If we use (for
the moment) the MS drivers on windows the code works as expected with
SQL Server drivers for 2000 and before, but with the new Native client
drivers (2000 sp3 and later) it fails to do the update as reported
above.

The problem seems to be the sequence

Query: set implicit_transactions on
RPC Name: sp_datatype_info
Query: SET IMPLICIT_TRANSACTIONS OFF
Query: BEGIN TRANSACTION

If the sp_datatype_info is not done, then it all works fine, but
because the sp_datatype_info a transaction is stated at this point,
and it seems that everything afterthis point is nested inside this
trasaction. So the commit works and commits the data, but the rollback
that occurs at the end rollsback (what I assume is) the outer
trasaction undoing the effect of the earlier insert and commit.

I in fact added  a flag to our driver to allow the driver to force
2000 type TDS as a way around the problem. Our support team also found
that calling commit() after the connect also worked. I guess this will
close the outer transaction.

Nick
--~--~-~--~~~---~--~~
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 and json

2009-03-25 Thread alex

Thanks, it gets results. But I have an error TypeError:
datetime.datetime(2009, 3, 11, 9, 56, 6) is not JSON serializable
--~--~-~--~~~---~--~~
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: Declarative with Enthoughts Traits framework.

2009-03-25 Thread Christiaan Putter

Hi,

Right now I'm really only using multiple threads for speeding up
downloads over the internet (which I need to update the data).
Actually commiting the data is still done via the gui's thread
session.  At some point speeding up the algorithms would be nice, a
concurrent solution would be ideal seeing as how the calculations for
each record are independent.  Though I might look into RPC for that
instead to get actual speed ups.  That will probably solve the thread
/ session problem in any case.

The unit testing has revealed some serious problems.  Mainly todo with
traits and the declarative extension not knowing how to cooperate (eg.
traits provides a mechanism to set up default values, though the
instrumented attribute obviously overrides that and returns what sql
says it should).  I really don't want to set up the mapper from a
class definition myself, declarative makes that much simpler so i
don't want to give up on that.  So I'll have to create my own
intrumented attribute / traits subclass.  Either a trait that wraps an
instrumented attribute, or an instrumented attribute that wraps a
trait.  I need to somehow provide both traits and SA with the
functionality they need in a single attribute on the instance.  What
do you think will be easiest?

That of course raises the question of what should take precedence.
The value provided by traits or the one from the database.  Or
whichever is not None.

I'll look into the mapper extensions.

I never thought some simple unit testing would cause so many headaches :-)

I'm talking to someone at enthought to maybe integrate that into their
sandbox for now.  I'm sure once someone else with more experience with
the traits framework looks at it we'll be able to figure out what the
simplest way to use sql with traits would be.   And then the
implementation should become clearer as well.

Hope you're having a nice day,
Crhistian

--~--~-~--~~~---~--~~
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: Declarative with Enthoughts Traits framework.

2009-03-25 Thread az

ah. when u don't have an explicit spec, the testcases are the real 
spec. so make sure u really cover all them funny cases (-:

i had the default_values problem too, and to solve it i have split the 
attr.access into two layers: one that sits below SA (as a fake dict), 
and one thin that sits on top of it. First one handles basic stuff / 
data storage, latter does default_values and lazy-autosetting it (in 
terms of static_type/). Look for AutoSetter and related in 
dbcook/usage/static_type/sa2static.py

There is subtle difference in whether the traits/descriptor will 
auto-set the default value or the SA/sql-server, make sure u 
understand it. First case SA/sql would never know about missing 
value.

as of precedence... i have one declaration and i would not care who 
sets the vales as long it is what's in the declaration.

you choose yours
svilen

On Wednesday 25 March 2009 14:47:35 Christiaan Putter wrote:
 Hi,

 Right now I'm really only using multiple threads for speeding up
 downloads over the internet (which I need to update the data).
 Actually commiting the data is still done via the gui's thread
 session.  At some point speeding up the algorithms would be nice, a
 concurrent solution would be ideal seeing as how the calculations
 for each record are independent.  Though I might look into RPC for
 that instead to get actual speed ups.  That will probably solve the
 thread / session problem in any case.

 The unit testing has revealed some serious problems.  Mainly todo
 with traits and the declarative extension not knowing how to
 cooperate (eg. traits provides a mechanism to set up default
 values, though the instrumented attribute obviously overrides that
 and returns what sql says it should).  I really don't want to set
 up the mapper from a class definition myself, declarative makes
 that much simpler so i don't want to give up on that.  So I'll have
 to create my own intrumented attribute / traits subclass.  Either a
 trait that wraps an instrumented attribute, or an instrumented
 attribute that wraps a trait.  I need to somehow provide both
 traits and SA with the functionality they need in a single
 attribute on the instance.  What do you think will be easiest?

 That of course raises the question of what should take precedence.
 The value provided by traits or the one from the database.  Or
 whichever is not None.

 I'll look into the mapper extensions.

 I never thought some simple unit testing would cause so many
 headaches :-)

 I'm talking to someone at enthought to maybe integrate that into
 their sandbox for now.  I'm sure once someone else with more
 experience with the traits framework looks at it we'll be able to
 figure out what the simplest way to use sql with traits would be.  
 And then the implementation should become clearer as well.

 Hope you're having a nice day,
 Crhistian

 


--~--~-~--~~~---~--~~
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] Seperate History Tables

2009-03-25 Thread Suha Onay

Hi,

I am using sqlalchemy for a while in a project.
The project has lots of models like User:
--
from mcmodel import MCModel

Base = declarative_base()

class User(MCModel, Base):
__tablename__ = 'users'

id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.Unicode(12))
fullname = sa.Column(sa.Unicode(40))
password = sa.Column(sa.Unicode(20))
active = sa.Column(sa.Boolean())
type = sa.Column(sa.SmallInteger())
note = sa.Column(sa.Text())
date_created = sa.Column(sa.Date())
--
All of these models inherit from MCModel (nothing doing special).

I want to save all the changes done to a user in a seperate db table
like _hist_users.
The new inserts do not need to be in the hist table.
When a user is updated, the old data of the user will be copied to the
hist table with a column declaring this is an update operation.
When a user is deleted, the old data of the user will be moved to the
hist table with a column declaring this is a delete operation.
With these operations, it is possible to know who modified what and
when.

How can i achieve in this?
By modifying the MCModel to enable all the models aware of history
backup?
Or using class sqlalchemy.orm.interfaces.MapperExtension.after_update
methods? (i do not know how)
Or anything else?

Thanks in advance.

Suha






--~--~-~--~~~---~--~~
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 does query.get() work?

2009-03-25 Thread Dan F

I understand what get() is supposed to do, but it doesn't clear it up
because it still seems like there should be a way of retrieving a
*set* of records back from the database at once.  I only see a couple
choices currently.  Either I can use filter() and retrieve every
record in the set (even the ones that are mapped), or I can use get on
each row individually.  Since get() checks the identity map, it won't
get records it doesn't need to get, but on the other hand, each record
has to get retrieved in its own call.

Does this make sense, and do I have it right?

Thanks.


On Mar 24, 2:08 am, Christiaan Putter ceput...@googlemail.com wrote:
 Hi,

 You won't be able to get() multiple objects at the same time.
 query(SomeClass).get(pk1, pk2, pk3)  takes in a tuple of values
 representing the primary key of some record in your table.  In this
 case the primary key consists of three separate columns (thus a
 composite key), though the record they identify will always be unique
 within your table.  That's sort of the point of it being a primary
 key.  Read the docs for an explanation of what parameters get()
 expects.

 Of course you could use filter() and get the same result.  I'm not
 sure but I guess the actual SQL executed by SA should look exactly the
 same, set echo to True and have a look.

 The difference being of course that you can use filter to return more
 then one record.

 I'm not sure how get() works on databases that don't need primary
 keys.  I'm guessing it won't.  Maybe it's in the docs.

 Hope that cleared things up.

 Regards,
 Christian

 2009/3/23 Dan F danielfal...@gmail.com:



  Hi,

  Is there a difference between using query.get(ident) and using
  query.filter(MyClass.id.in_())?  Specifically with regard to how the
  mapper is used?  If I'm right in my assumption, get() uses the map to
  avoid extra lookups, but I question whether the filter method is doing
  the same.  If I'm correct, shouldn't there be a way to get() multiple
  objects at the same time?

  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] SQLAlchemy 0.5.3 released

2009-03-25 Thread Michael Bayer

I've been a little busy lately so we're a month off on this one, but  
there's a trove of bugfixes in this one, largely related to new  
features that are specific to the 0.5 series, as well as some  
behavioral enhancements to Query and declarative - read the changelog  
for details.  I'm hammering on this release quite fiercely for a real  
project right now (which has driven a good chunk of the fixes) so it  
has my seal of approval.

Download SQLAlchemy 0.5.3 at:  http://www.sqlalchemy.org/download.html .

0.5.3
=
- orm
 - The objects argument to session.flush() is deprecated.
   State which represents the linkage between a parent and
   child object does not support flushed status on
   one side of the link and not the other, so supporting
   this operation leads to misleading results.
   [ticket:1315]

 - Query now implements __clause_element__() which produces
   its selectable, which means a Query instance can be accepted
   in many SQL expressions, including col.in_(query),
   union(query1, query2), select([foo]).select_from(query),
   etc.

 - Query.join() can now construct multiple FROM clauses, if
   needed.  Such as, query(A, B).join(A.x).join(B.y)
   might say SELECT A.*, B.* FROM A JOIN X, B JOIN Y.
   Eager loading can also tack its joins onto those
   multiple FROM clauses.  [ticket:1337]

 - Fixed bug in dynamic_loader() where append/remove events
   after construction time were not being propagated to the
   UOW to pick up on flush(). [ticket:1347]

 - Fixed bug where column_prefix wasn't being checked before
   not mapping an attribute that already had class-level
   name present.

 - a session.expire() on a particular collection attribute
   will clear any pending backref additions as well, so that
   the next access correctly returns only what was present
   in the database.  Presents some degree of a workaround for
   [ticket:1315], although we are considering removing the
   flush([objects]) feature altogether.

 - Session.scalar() now converts raw SQL strings to text()
   the same way Session.execute() does and accepts same
   alternative **kw args.

 - improvements to the determine direction logic of
   relation() such that the direction of tricky situations
   like mapper(A.join(B)) - relation- mapper(B) can be
   determined.

 - When flushing partial sets of objects using  
session.flush([somelist]),
   pending objects which remain pending after the operation won't
   inadvertently be added as persistent. [ticket:1306]

 - Added post_configure_attribute method to  
InstrumentationManager,
   so that the listen_for_events.py example works again.
   [ticket:1314]

 - a forward and complementing backwards reference which are both
   of the same direction, i.e. ONETOMANY or MANYTOONE,
   is now detected, and an error message is raised.
   Saves crazy CircularDependencyErrors later on.

 - Fixed bugs in Query regarding simultaneous selection of
   multiple joined-table inheritance entities with common base
   classes:

   - previously the adaption applied to B on
 A JOIN B would be erroneously partially applied
 to A.

   - comparisons on relations (i.e. A.related==someb)
 were not getting adapted when they should.

   - Other filterings, like
 query(A).join(A.bs).filter(B.foo=='bar'), were erroneously
 adapting B.foo as though it were an A.

  - Fixed adaptation of EXISTS clauses via any(), has(), etc.
in conjunction with an aliased object on the left and
of_type() on the right.  [ticket:1325]

  - Added an attribute helper method ``set_committed_value`` in
sqlalchemy.orm.attributes.  Given an object, attribute name,
and value, will set the value on the object as part of its
committed state, i.e. state that is understood to have
been loaded from the database.   Helps with the creation of
homegrown collection loaders and such.

  - Query won't fail with weakref error when a non-mapper/class
instrumented descriptor is passed, raises
Invalid column expession.

  - Query.group_by() properly takes into account aliasing applied
to the FROM clause, such as with select_from(), using
with_polymorphic(), or using from_self().

- sql
 - An alias() of a select() will convert to a scalar subquery
   when used in an unambiguously scalar context, i.e. it's used
   in a comparison operation.  This applies to
   the ORM when using query.subquery() as well.

 - Fixed missing _label attribute on Function object, others
   when used in a select() with use_labels (such as when used
   in an ORM column_property()).  [ticket:1302]

 - anonymous alias names now truncate down to the max length
   allowed by the dialect.  

[sqlalchemy] Re: 0.5.2 seems to always roll back with mssql

2009-03-25 Thread Rick Morrison
Yep, same here.

..on my mssql 2005, I tried this query batch:


set implicit_transactions on
go
select 'After implicit ON', @@trancount

exec sp_datatype_info
go
select 'After query w/implicit', @@trancount

begin transaction
go
select 'After BEGIN', @@trancount


Here's the output:

-  
After implicit ON 0

 
After query w/implicit  1

  
After BEGIN  2


Our support team also found that calling commit() after the connect also
 worked. I guess this will
 close the outer transaction.


It's a bit of a hack, but it sounds like a simple 2-cent solution. We could
issue something like:

IF @@TRANCOUNT  0
COMMIT

on connection establishment.

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