[sqlalchemy] proxied attribute access

2008-05-20 Thread az

g'day
i need to have an attribute with setter/getter, say foo, and so that 
the underlaying DB/SA-attribute (_foo) to be completely hidden for  
users of the class - to avoid someone setting/getting it by mistake. 
is this possible within SA - via new AttributeAccess layer - or else?

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



[sqlalchemy] Re: SqlAlchemy and Stored Procedures with variables

2008-05-20 Thread Mike

Rick,

On May 19, 4:30 pm, Rick Morrison [EMAIL PROTECTED] wrote:
 Does the same statement work in an interactive query window, complete with
 the embedded semicolon you're using?

 Also, you should be able to use positional parameters instead of named
 parameters in your call:
       cur.execute(execute stored_proc 'gra%' )

 Note that as of yet there is no SQLAlchemy support for OUT or IN/OUT
 parameters; currently you can return a single set of results via a SELECT in
 the stored procedure.

 Rick

The SQL works in our SQL analyzer with or without the named parameter
and with the semicolon. We tried it the way you mentioned too, using
positional parameters, and got the same error. I apologize for
forgetting to mention that in my first post.

Any other ideas? I'll look into the OUT parameter that Bayer mentions
in his post.

Mike
--~--~-~--~~~---~--~~
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] existing database/hibernating

2008-05-20 Thread Gregor Kling
Hello Alchemystas,

I have a legacy database, with a self written ORM not to fuss about.
So I want to use a some more intelligent mechanism - sqlalchemy.
I have written a little hibernator, that does nothing more, as to 
ask the database for its metadata via sqlalchemy (heron:0.4.2p3-1) 
and construct classes of the form:

from sqlalchemy import *
from sqlalchemy.orm import mapper

from dvzrv.db import sAmetaData

class SrvDomainTable(object):
   def __init__(self,domain_name=None,srv_id=None):
 self.sAtablename = 'srv_domain'
 self.sAsrv_domain_table = Table(self.sAtablename, sAmetaData, 
autoload=True)
 self.sAmapped_srv_domain = 
mapper(DVZsrvDomainTable,self.sAsrv_domain_table,primary_key=[self.sAsrv_domain_table.c.domain_name])

 self.domain_name = domain_name
 self.srv_id = srv_id

I still do not have clue, how to cope with association tables.
The class SrvDomainTable for example is one of those.
The usage of primary key is only to test functionality.
So my question is, will it suffice to use the primary key list 
listing all foreign keys -like this: 
primary_key=[self.sAsrv_domain_table.c.domain_name,self.sAsrv_domain_table.c.srv_id].
 
Or do I have to use it like the example in
http://www.sqlalchemy.org/docs/04/mappers.html ?
Regrettably I do not grasp the idea of the example up to now,


left_table = Table('left', metadata,
 Column('id', Integer, primary_key=True))

right_table = Table('right', metadata,
 Column('id', Integer, primary_key=True))

association_table = Table('association', metadata,
 Column('left_id', Integer, ForeignKey('left.id')),
 Column('right_id', Integer, ForeignKey('right.id')),
 )

mapper(Parent, left_table, properties={
 'children':relation(Child, secondary=association_table)
})

mapper(Child, right_table)


because it uses only the parent mapper to some things,
whereas the childmapper is unchanged..


thanks
gregor


-- 
Gregor Kling

Abteilung ITS, Sachgebiet DVZ
Fachhochschule Giessen
Tel: 0641/309-1292
E-Mail: [EMAIL PROTECTED]


smime.p7s
Description: S/MIME Cryptographic Signature


[sqlalchemy] Re: existing database/hibernating

2008-05-20 Thread Michael Bayer


On May 20, 2008, at 10:56 AM, Gregor Kling wrote:

 Hello Alchemystas,

 I have a legacy database, with a self written ORM not to fuss about.
 So I want to use a some more intelligent mechanism - sqlalchemy.
 I have written a little hibernator, that does nothing more, as to
 ask the database for its metadata via sqlalchemy (heron:0.4.2p3-1)
 and construct classes of the form:

 from sqlalchemy import *
 from sqlalchemy.orm import mapper

 from dvzrv.db import sAmetaData

 class SrvDomainTable(object):
   def __init__(self,domain_name=None,srv_id=None):
 self.sAtablename = 'srv_domain'
 self.sAsrv_domain_table = Table(self.sAtablename, sAmetaData,
 autoload=True)
 self.sAmapped_srv_domain =
 mapper
 (DVZsrvDomainTable
 ,self
 .sAsrv_domain_table
 ,primary_key=[self.sAsrv_domain_table.c.domain_name])

its not going to work if you create the mapper() (and Table) per class  
instance (i.e. within __init__), although its not clear to me above  
what you're actually doing since I do not know what  
DVZsrvDomainTable is, or what its desired relationship is to  
SrvDomainTable.  It *looks* like the wrong pattern if in fact an  
instance of a SrvDomainTable corresponds to a DVZsrvDomainTable  
instance.  If not, and SrvDomainTable is just created once at the  
configurational level, its still a really hard-to-understand way of  
doing things :).   You might want to look into the declarative  
extension which provides a simple pattern for defining classes,  
mappers, and tables all at once (and if declarative doesn't work for  
you, read the source code to it at least to see a fairly sane way of  
doing things).


 I still do not have clue, how to cope with association tables.
 The class SrvDomainTable for example is one of those.
 The usage of primary key is only to test functionality.
 So my question is, will it suffice to use the primary key list
 listing all foreign keys -like this:
 primary_key 
 = 
 [self 
 .sAsrv_domain_table.c.domain_name,self.sAsrv_domain_table.c.srv_id].

assuming you are creating a Mapper to an association table, yes its  
typical that the FK columns which connect the two target classes  
formulate the primary key for the purposes of mapping (i.e. it  
uniquely identifies the row).

 left_table = Table('left', metadata,
 Column('id', Integer, primary_key=True))

 right_table = Table('right', metadata,
 Column('id', Integer, primary_key=True))

 association_table = Table('association', metadata,
 Column('left_id', Integer, ForeignKey('left.id')),
 Column('right_id', Integer, ForeignKey('right.id')),
 )

 mapper(Parent, left_table, properties={
 'children':relation(Child, secondary=association_table)
 })

 mapper(Child, right_table)

this is not what SQLA refers to as an association mapping, this is  
just a many-to-many which is somethign different.  So im not sure  
which pattern you're trying to use.  The one with the primary keys on  
the mapper is the association object at 
http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_relation_patterns_association
 
  .


--~--~-~--~~~---~--~~
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: SqlAlchemy and Stored Procedures with variables

2008-05-20 Thread Mike



On May 20, 10:13 am, Rick Morrison [EMAIL PROTECTED] wrote:
  The SQL works in our SQL analyzer with or without the named parameter
  and with the semicolon. We tried it the way you mentioned too, using
  positional parameters, and got the same error. I apologize for
  forgetting to mention that in my first post.

 Then perhaps you're not connected to the correct database, or it's a
 permissions issue? The way you're using the DB connection directly,
 SQLAlchemy is not issuing any SQL of it's own: it's a straight pass-through.


I don't think it's a permissions thing...see below...

 Positional parameters work with pymssql, so I assume you're using pyodbc,
 correct? I haven't tried calling a stored procedure using pyodbc, anybody on
 the list have that working?


I think we're using pymssql from a Linux box. Is there a way to tell
which Python module SQLAlchemy is using? We tried running it with
straight pymssql instead and it works in there:

code
import pymssql
db =
pymssql.connect(host=ntsql.ourSite.com,user=user,password=pw,database=ourDB)
cur = db.cursor()
cur.execute(execute sp_EDEN_Vendors @query='gra%';)
print cur.fetchall()
/code



  Any other ideas? I'll look into the OUT parameter that Bayer mentions
  in his post.

 Well if IN parameters don't work, OUT parameters probably aren't going to
 work either. If you're using pyodbc, I would try bringing the issue up on
 the pyodbc list. You're pretty much using the DB-API cursor directly, so
 it's not interference from SQLA.

Crumb. Thanks.

Mike
--~--~-~--~~~---~--~~
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: SqlAlchemy and Stored Procedures with variables

2008-05-20 Thread Paul Johnston
Hi,

  The SQL works in our SQL analyzer with or without the named parameter
   and with the semicolon. We tried it the way you mentioned too, using
   positional parameters, and got the same error. I apologize for
   forgetting to mention that in my first post.


Dunno if this is related, but pyodbc and adodbapi execute each statement in
a separate context. This caused a problem with scope_identity, as in the
original implementation with pyodbc, scope_identity always returned null.

Paul

--~--~-~--~~~---~--~~
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: Access to AS/400 data

2008-05-20 Thread Ken Kuhlman

On Fri, May 16, 2008 at 3:18 PM, Carlos Hanson [EMAIL PROTECTED] wrote:
 On Fri, May 16, 2008 at 10:49 AM, Jim Steil [EMAIL PROTECTED] wrote:
 Carlos Hanson wrote:
 On Fri, May 16, 2008 at 8:14 AM, Michael Bayer [EMAIL PROTECTED]
 wrote:
 On May 16, 2008, at 10:55 AM, Carlos Hanson wrote:
 On Fri, May 16, 2008 at 6:13 AM, Jim Steil [EMAIL PROTECTED] wrote:

 Hi:

 Can anyone tell me if it is possible to access data on an AS/400
 through
 SQLAlchemy?

   -Jim


It's possible if you use db2 connect to make your connection to the
iSeries.  See http://code.google.com/p/ibm-db/.  The support group is
[EMAIL PROTECTED]

Right now, the as/400 is listed as a Future supported database [1],
but there have been some reports from people getting it working.  You
might want to make your needs known on the support list  also follow
up with your IBM rep.

[1] http://code.google.com/p/ibm-db/wiki/README



 I'm connecting to an AS/400 using pyodbc, so I am sure that I can do
 it through SQLAlchemy.  If I have a chances to test it, I'll post my
 success.  But if you get an ODBC connection set up, the re should be
 no problem.


 well, connecting is just the beginning.  to take advantage of SQLA,
 you would also want an AS/400 dialect that knows how to render SQL in
 the way an AS/400 likes.  Im not familiar with anyone working on an AS/
 400 dialect at the moment.   I only know of the DB2 dialect which is a
 separate project (but maybe ask on their list since they work for IBM).


 This is a good point. I have to create aliases to a file/member
 combination to select data. I guess I wouldn't expect SQLAlchemy to
 implement that by default, since most every other database uses
 tables.


Right... but there's no reason you can't drop down to the db-api level
for one-off things like partitioning data with members.   Once the
alias is created, it can be treated like any other table.

-ken

--~--~-~--~~~---~--~~
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: SqlAlchemy and Stored Procedures with variables

2008-05-20 Thread Rick Morrison

 I think we're using pymssql from a Linux box. Is there a way to tell
 which Python module SQLAlchemy is using? We tried running it with
 straight pymssql instead and it works in there:


The MSSQL module does an auto-detect of the supported DB-API modules and
uses the first one that imports without error. The sequence for the 0.4
series is [pyodbc, pymssql, adodbapi]. You can force module selection by
using a 'module=' keyword argument to the create_engine call.


Crumb. Thanks.


Here's another:
   http://rcrumb.com/

--~--~-~--~~~---~--~~
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: SqlAlchemy and Stored Procedures with variables

2008-05-20 Thread Rick Morrison
We should really be using the ODBC sanctioned syntax for procedure call,
which is still unsupported by pyodbc, AFAIK.  ODBC on *nix is over 10 years
old at this point, you'd think we'd have a better story to tell by now,
jeez.


 Dunno if this is related, but pyodbc and adodbapi execute each statement in
 a separate context. This caused a problem with scope_identity, as in the
 original implementation with pyodbc, scope_identity always returned null.


I thought the original impetus for scope_identity was not multiple execution
contexts, but rather things being fouled up for some users where they had
nested INSERTs being done via a trigger on the mapped table, and the
brain-dead SELECT @@identity_insert wasn't able to pluck out the correct PK.
Was there another reason I'm missing?

Jason, how are coming on the dialect refactor? Things are heating up out
here

--~--~-~--~~~---~--~~
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: proxied attribute access

2008-05-20 Thread jason kirtland

[EMAIL PROTECTED] wrote:
 g'day
 i need to have an attribute with setter/getter, say foo, and so that 
 the underlaying DB/SA-attribute (_foo) to be completely hidden for  
 users of the class - to avoid someone setting/getting it by mistake. 
 is this possible within SA - via new AttributeAccess layer - or else?

Yep.  There are examples in examples/custom_attributes plus more in 
test/orm/extendedattr.py and test/orm/instrumentation.py.  Also doc in 
sqlalchemy.orm.attributes.  (You'll need to consult the source on that 
one until we get a doc generator that can extract attribute docstrings.)

--~--~-~--~~~---~--~~
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] 64-bit postgres produces: This SchemaItem is not connected to any Engine

2008-05-20 Thread robert rottermann

Hi there,

I am building a zope/plone site that uses sqlalchemy  (collective.lead).

on two systems I am developping on everything works fine, a third one that
has 64 bit linux installed (all systems use SuSE 10.3) I get an traceback:

  Module ruagaero.intradevcontent.db.db, line 22, in _setup_tables
  Module sqlalchemy.schema, line 166, in __call__
  Module sqlalchemy.schema, line 70, in get_engine
InvalidRequestError: This SchemaItem is not connected to any Engine


how can I fix that?

thanks for your help
robert

--~--~-~--~~~---~--~~
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: existing database/hibernating

2008-05-20 Thread Gregor Kling

Michael Bayer wrote:
from sqlalchemy import *
from sqlalchemy.orm import mapper

from dvzrv.db import sAmetaData

class SrvDomainTable(object):
def __init__(self,domain_name=None,srv_id=None):
  self.sAtablename = 'srv_domain'
  self.sAsrv_domain_table = Table(self.sAtablename, 
sAmetaData,autoload=True)
  self.sAmapped_srv_domain =

mapper(SrvDomainTable,self.sAsrv_domain_table,primary_key=[self.sAsrv_domain_table.c.domain_name])

 its not going to work if you create the mapper() (and Table) per class  
 instance (i.e. within __init__),
It was a typo. It should be all SrvDomainTable.
But why shouldn't it work, I already do the test and it does.
Could you please be more specific about this ?

 [self.sAsrv_domain_table.c.domain_name,self.sAsrv_domain_table.c.srv_id].
 assuming you are creating a Mapper to an association table, yes its  
 typical that the FK columns which connect the two target classes  
 formulate the primary key for the purposes of mapping (i.e. it  
 uniquely identifies the row).
So this is the intended way to map a table which only connects to tables 
with the usage of FKs ?

 this is not what SQLA refers to as an association mapping, this is  
 just a many-to-many which is somethign different.
It could be that I misunderstand the intention of SA in relation to 
association mapping.
What I want, is to map the association table (the table which connects 
two tables, that has only 2 keys - the foreign keys) to an object the 
same as i do with the rest of the tables; which all have nomrally an 
*explicit* pk.
As I run into an error in relation of a missing pk, I tried to cope with 
that.In addition I found some post (anywhere),
which handled this with adding this primary_key=[]-thing for those classes.
So because I have not used SA before, there might be some gaps of 
understanding ;-)

greetings
gregor

--~--~-~--~~~---~--~~
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: (scoped_session.)commit() not doing anything

2008-05-20 Thread jerryji

Finally solved the problem. It was caused by the incorrect way I used
Session --

Previously the _q object is central initialized and shared, problem
went away after I create per object instance.

Jerry

On May 19, 11:00 pm, jerryji [EMAIL PROTECTED] wrote:
 Hi,

 This commit()-not-doing-anything problem is driving me crazy :(
 All my other commits in the same code base are working perfectly,
 it's just this one.

 My Session is a scoped_session --

 
 Session = scoped_session(
 sessionmaker(autoflush=True, transactional=True, ...))
 

 A debug goes --

 
 (Pdb) list
 277  import pdb; pdb.set_trace()
 278  -  item_property = itemproperty_q.filter_by(
 279  a_itemid=a_itemid, b_itemid=b_itemid,
 280  propertyid=propertyid,
 281  userid=userid).first()
 282  item_property.fav_itemid = fav_itemid
 283  model.Session.commit()
 (Pdb) n /item.py(279)compare()

 - a_itemid=a_itemid, b_itemid=b_itemid,
 (Pdb) n /item.py(280)compare()

 - propertyid=propertyid,
 (Pdb) n /item.py(281)compare()

 - userid=userid).first()
 (Pdb) n
 

 So far so good, generates lots of output from the select statement.
 The next statement sets item_property.fav_itemid to 10002 from None --

  /item.py(282)compare()

 - item_property.fav_itemid = fav_itemid
 (Pdb) list
 277  import pdb; pdb.set_trace()
 278  item_property = itemproperty_q.filter_by(
 279  a_itemid=a_itemid, b_itemid=b_itemid,
 280  propertyid=propertyid,
 281  userid=userid).first()
 282  -  item_property.fav_itemid = fav_itemid
 283  model.Session.commit()
 (Pdb) item_property.fav_itemid
 (Pdb) fav_itemid
 10002
 

 But then the next Session.commit() statement does _nothing_ --

 
 (Pdb) n /item.py(283)compare()

 - model.Session.commit()
 (Pdb) item_property.fav_itemid
 10002
 (Pdb) n /item.py(254)compare()

 

 I spent much time ripping the mapped table into an IPython session and
 saw it working fine --

 
 In [82]: item_property.fav_itemid = 10002
 In [83]: Session.commit()
 ...executes the update statement
 

 What could have gong wrong?

 _Many_ thanks in advance!

 Jerry
--~--~-~--~~~---~--~~
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: 64-bit postgres produces: This SchemaItem is not connected to any Engine

2008-05-20 Thread jason kirtland

robert rottermann wrote:
 Hi there,
 
 I am building a zope/plone site that uses sqlalchemy  (collective.lead).
 
 on two systems I am developping on everything works fine, a third one that
 has 64 bit linux installed (all systems use SuSE 10.3) I get an traceback:
 
   Module ruagaero.intradevcontent.db.db, line 22, in _setup_tables
   Module sqlalchemy.schema, line 166, in __call__
   Module sqlalchemy.schema, line 70, in get_engine
 InvalidRequestError: This SchemaItem is not connected to any Engine

0.3.x?  could be an attempt in '_setup_tables' to autoload tables 
without a database configured to load from.


--~--~-~--~~~---~--~~
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: existing database/hibernating

2008-05-20 Thread Michael Bayer


On May 20, 2008, at 12:15 PM, Gregor Kling wrote:


 its not going to work if you create the mapper() (and Table) per  
 class
 instance (i.e. within __init__),
 It was a typo. It should be all SrvDomainTable.
 But why shouldn't it work, I already do the test and it does.
 Could you please be more specific about this ?

the mapper links itself to the class.  additionally, the mapper  
compiles itself and places instrumentation upon the class that  
receives events and tracks history.   Its not valid to create another  
primary mapper for the same class without explcitily removing the  
first one - it will raise an error.  There's a lot of dependencies set  
up at the class level, and things would break very badly if they were  
re-created uniquely on different instances of the same class.  Primary  
mapper construction is also a fairly expensive process in comparison  
with whats appropriate for object instantiation.


 [self 
 .sAsrv_domain_table.c.domain_name,self.sAsrv_domain_table.c.srv_id].
 assuming you are creating a Mapper to an association table, yes its
 typical that the FK columns which connect the two target classes
 formulate the primary key for the purposes of mapping (i.e. it
 uniquely identifies the row).
 So this is the intended way to map a table which only connects to  
 tables
 with the usage of FKs ?

its typical since the set of foreign keys defines uniqueness for the  
row.  We are looking here for a natural primary key, which you can  
see defined at http://en.wikipedia.org/wiki/Primary_key .  But from  
what you've mentioned below, you aren't actually mapping to the  
association table, it's used only within a many-to-many relation().   
So the explicit specification of primary key doesn't apply in that  
case.



 this is not what SQLA refers to as an association mapping, this is
 just a many-to-many which is somethign different.
 It could be that I misunderstand the intention of SA in relation to
 association mapping.
 What I want, is to map the association table (the table which connects
 two tables, that has only 2 keys - the foreign keys) to an object the
 same as i do with the rest of the tables; which all have nomrally an
 *explicit* pk.

this is a plain many-to-many relation.  The example in the docs for  
many-to-many applies, and no mapper for this specific table is  
needed; its sent along as secondary to a relation().

 As I run into an error in relation of a missing pk, I tried to cope  
 with
 that.In addition I found some post (anywhere),
 which handled this with adding this primary_key=[]-thing for those  
 classes.
 So because I have not used SA before, there might be some gaps of
 understanding ;-)

since theres no mapper needed for the secondary table, no primary key  
argument is specified either.


--~--~-~--~~~---~--~~
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: 64-bit postgres produces: This SchemaItem is not connected to any Engine

2008-05-20 Thread robert rottermann

thanks jason,

jason kirtland schrieb:
 robert rottermann wrote:
 Hi there,

 I am building a zope/plone site that uses sqlalchemy  (collective.lead).

 on two systems I am developping on everything works fine, a third one that
 has 64 bit linux installed (all systems use SuSE 10.3) I get an traceback:

   Module ruagaero.intradevcontent.db.db, line 22, in _setup_tables
   Module sqlalchemy.schema, line 166, in __call__
   Module sqlalchemy.schema, line 70, in get_engine
 InvalidRequestError: This SchemaItem is not connected to any Engine
 
 0.3.x?  could be an attempt in '_setup_tables' to autoload tables 
 without a database configured to load from.

I am usin 0.4.6
the same confuguration works on 32 bit linux

robert

--~--~-~--~~~---~--~~
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: 64-bit postgres produces: This SchemaItem is not connected to any Engine

2008-05-20 Thread jason kirtland

robert rottermann wrote:
 thanks jason,
 
 jason kirtland schrieb:
 robert rottermann wrote:
 Hi there,

 I am building a zope/plone site that uses sqlalchemy  (collective.lead).

 on two systems I am developping on everything works fine, a third one that
 has 64 bit linux installed (all systems use SuSE 10.3) I get an traceback:

   Module ruagaero.intradevcontent.db.db, line 22, in _setup_tables
   Module sqlalchemy.schema, line 166, in __call__
   Module sqlalchemy.schema, line 70, in get_engine
 InvalidRequestError: This SchemaItem is not connected to any Engine
 0.3.x?  could be an attempt in '_setup_tables' to autoload tables 
 without a database configured to load from.
 
 I am usin 0.4.6
 the same confuguration works on 32 bit linux

The get_engine function in that traceback don't exist in the 0.4 series. 
  Is it possible you're picking up another (maybe system) SA 
installation instead of 0.4.6?

--~--~-~--~~~---~--~~
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] mapper extension

2008-05-20 Thread Mike Bernson

I am looking for a hook after a instance has been created, attribute
populated and any initialization done. I have found populate_instance
in the MapperExtension. It look like to close thing.

Adding a hook to MapperExtension for after instance is created,
populated, and any initialization by the orm be great.

I am assuming that that lazy loading go thought this interface
also.

Is there any public api to handle the populating of
the attributes and do any initialization that might happen
when I return EXT_STOP ?

The idea would be to do the work of populate_instance and
let my framework do the initialization it needs.

The goal is to have a chance to do more initialization for my
framework after sqlachemy has load any instance from the orm.




--~--~-~--~~~---~--~~
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] ShardedSession and id_chooser

2008-05-20 Thread Marcus Cavanaugh

Some of my tables (in a web application using Pylons) will eventually
need to be partitioned to separate shards, but some tables won't. For
example, imagine that I'd like to partition a Users table across 3
different databases, while leaving others just on one master database.

I've read the ShardedSession docs a few times. The shard_chooser()
callable is straightforward, and thanks to the example [1], I think I
understand how to use query_chooser(); but I need a pointer about how
to use id_chooser() properly. The docs describe id_chooser as this: a
function which can return a list of shard ids which apply to a
particular instance identifier, but that seems unclear to me.

Say I issue the following queries:

1) Session.query(User).filter_by(id=4)
2) Session.query(UnrelatedTable).filter_by(id=567)
3) Session.query(UserProfiles).filter_by(user_id=4) # where
UserProfiles is mapped to a User class

In the first query, the id_chooser would simply return the proper
shard, since I know that I'm querying for a User. The second query
searches for a completely unrelated (non-sharded) table; how would I
inspect the id_chooser()'s query parameter to determine that it's
searching for a user? Lastly, in the third query above, which only
indirectly wants to find a User class, which shard callable would be
invoked and how do I make sure it finds the right shard for the
associated User?

A related question: Should I use a separate Session to separate the
sharded tables from the non-sharded ones, in the case where I would
not need to aggregate queries between the two sessions?

If I were doing this in plain SQL, I'd probably just connect to all of
the databases, and then manually choose which instance to perform
individual queries on (query aggregation between shards doesn't need
to happen much in my current project). Apologies in advance if my
questions are confusing; I'm having trouble grasping whether it's
feasible to use the ORM for this or if it would be simpler/clearer to
take a more manual approach.

[1]: 
http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/sharding/attribute_shard.py
--~--~-~--~~~---~--~~
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] in not implemented for queries?

2008-05-20 Thread andrew cooke


Hi,

Just wanted to check: I am seeing a NotImplementedError (v 0.4.6 on
Linux w Python 2.5) when I try to query some objects with the filter
in.  Does that mean that the feature is not implemented, or is it
more likely an error in my code (eg somehow I'm calling a base class;
Address.email_address.in_ does appear in the ORM tutorial, which
makes me wonder whether it is supported)?

If this is unsupported, what's the best approach?  Just loop over the
various instances myself?

My code looks like:

query = session.query(Measurement)
query = query.filter(Measurement.time_series.in_(time_series))

where Measurement is a mapped class, and time_series is both a list of
TimeSeries instances (another mapped class) and a Measurement
attribute that is mapped via a relation.  If it's relevant -
Measurement is actually a base class for joined table inheritance (the
time series key col is in the base class table).

The trace looks like:
  File /home/andrew/projects/isti/kpi-pilot-2/repository-tool/src/
isti/reptool/core/actions/readonly.py, line 96, in _no_undo
Measurement.time_series.in_(time_series))
  File /usr/lib64/python2.5/site-packages/sqlalchemy/sql/
expression.py, line 1220, in in_
return self.operate(operators.in_op, other)
  File /usr/lib64/python2.5/site-packages/sqlalchemy/orm/
attributes.py, line 56, in operate
return op(self.comparator, *other, **kwargs)
  File /usr/lib64/python2.5/site-packages/sqlalchemy/sql/
operators.py, line 47, in in_op
return a.in_(*b)
  File /usr/lib64/python2.5/site-packages/sqlalchemy/sql/
expression.py, line 1220, in in_
return self.operate(operators.in_op, other)
  File /usr/lib64/python2.5/site-packages/sqlalchemy/sql/
expression.py, line 1181, in operate
raise NotImplementedError()
NotImplementedError

Finally, thanks for this library - it's an excellent piece of
software.  The first ORM/SQL lib that I've felt really works well.

Cheers,
Andrew

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