[sqlalchemy] Re: mod_wsgi, SQLite3 and a threading anomaly because connection is not returned to pool by session.remove()

2010-06-11 Thread Vinay Sajip
On Jun 10, 10:08 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 First off, the absolute recommended behavior for SQLite if a file-based 
 database is to not use pooling.  I would suggest you use a NullPool to 
 eliminate any connection pooling.  Some detail on this 
 athttp://www.sqlalchemy.org/docs/reference/dialects/sqlite.html#threadi   
 Seems like I mention it in the linked thread as well.


Indeed. I understand about NullPool, and the setup I'm using is a test
setup for multi-db operation. I would expect the session.remove() to
clean up any SQLA connections used during the request, but it's not
happening some of the time - I was hoping to find the cause; of course
if I switched to NullPool the problem would go away.

 You then need to ensure no sqlalchemy-session-bound objects in your web 
 application are shared between threads.  When you put things into your HTTP 
 session, assuming its an in-memory HTTP session, make sure objects that go in 
 there arent attached to a SQLAlchemy session.  Use expunge() or similar for 
 this.  Calling remove() at the end of the request will work, except for the 
 fact that a concurrent thread might be accessing the HTTP session before you 
 get that far.

In the failing case, requests are not actually happening concurrently
- mod_wsgi just happens to use different threads for servicing the
sequential requests, which are a second or two apart. The problem is
caused by a connection sometimes not being found when session.remove()
is called. The connection is always created in response to a query to
get a User object from an integer ID stored in the session. While the
User object is a SQLA mapped object, it's not stored in the session,
only the ID is.

Note that the problem occurs during clean up via session.remove()
(connection not found to return to pool) but manifests itself on the
next request (a second or two later). I'm wondering if there's some
reason why an opened connection might sometimes not be registered
properly [ has() returning False ] which is why it's not returned to
the pool.

Concurrent thread access to the session isn't (I believe) happening in
this case as the server is on my local test machine with no other load
than me accessing via Firefox locally. There are concurrent requests
but only for static files.

   I would recommend using cookie based HTTP sessions in any case (see Beaker 
for this functionality).

I presume you mean where all session state is stored in the cookie. I
can do this but I'm working on a framework component which also needs
to support server-side sessions.

 That thread regarded someone using an extremely rare tool called PyISAPIe, 
 which had threading bugs in it.  That doesn't apply to a basic mod_wsgi 
 configuration.

I see now. It was a clutching-at-straws kind of thing :-)

Thanks  regards,

Vinay Sajip

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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: help with 0.6 migration

2010-06-11 Thread Alexander Zhabotinskiy
Sorry, I found error...

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



RE: [sqlalchemy] Kerberos authentication with sybase

2010-06-11 Thread Cserna, Zsolt

The DBAPI is python-sybase (http://python-sybase.sourceforge.net/).

Here is an example:

conn = Sybase.connect(hostname, , , delay_connect=1)
conn.set_property(Sybase.CS_SEC_NETWORKAUTH, Sybase.CS_TRUE)
conn.set_property(Sybase.CS_SEC_SERVERPRINCIPAL, principal)
conn.connect()

The variable principal would come from connection string.


Zsolt


 -Original Message-
 From: sqlalchemy@googlegroups.com 
 [mailto:sqlalch...@googlegroups.com] On Behalf Of Michael Bayer
 Sent: Thursday, June 10, 2010 15:58
 To: sqlalchemy@googlegroups.com
 Subject: Re: [sqlalchemy] Kerberos authentication with sybase
 
 if you want to show me how that's done with your DBAPI (what 
 DBAPI is this?), sure, though if its something that you pass 
 in via **kw to DBAPI.connect(), you can already do that by 
 passing connect_args to create_engine(), or adding them onto 
 the querystring db://...?foo=bar.
 
 
 
 On Jun 10, 2010, at 9:10 AM, Cserna, Zsolt wrote:
 
  
  Hi all,
  
  Is there any plan to add kerberos authentication to the 
 sybase engine in sqlalchemy?
  
  I've implemented it but it's using the creator parameter of 
 the create_engine function, which is ok, but in certain 
 circumstances when the application using sqlalchemy uses 
 configuration from a text file, I'm not able to do it easily 
 (in pylons I need to modify my templates, or add a bunch of 
 code to each project).
  
  It would be nice if sqlalchemy would be able to accept the 
 server's principal specified in the connection string somehow 
 - and if it's specified use kerberos to authenticate the client.
  
  Is it possible to implement this modification in 
 sqlalchemy? I'm happy to contribute my current implementation.
  
  Thanks,
  Zsolt
  
  
 --
  
  NOTICE: If received in error, please destroy, and notify 
 sender. Sender does not intend to waive confidentiality or 
 privilege. Use of this email is prohibited when received in 
 error. We may monitor and store emails to the extent 
 permitted by applicable law.
  
  --
  You received this message because you are subscribed to the 
 Google Groups sqlalchemy group.
  To post to this group, send email to sqlalch...@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.
  
 
 -- 
 You received this message because you are subscribed to the 
 Google Groups sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
 
 
--
NOTICE: If received in error, please destroy, and notify sender. Sender does 
not intend to waive confidentiality or privilege. Use of this email is 
prohibited when received in error. We may monitor and store emails to the 
extent permitted by applicable law.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] How to map to read only descriptor

2010-06-11 Thread jpeck
I am trying to map to a simple read only property. According to the
docs, I *think* I am supposed to use synonym. The problem is that I am
getting a None value for the mapped descriptor's column.

For example:

import datetime
from sqlalchemy import Column, Table, Integer, String, MetaData,
create_engine
from sqlalchemy.orm import mapper, sessionmaker, synonym

meta = MetaData()
foo_table = Table('foo', meta,
Column('id', String(3), primary_key=True),
Column('description', String(64), nullable=False),
Column('calculated_value', Integer, nullable=False),
)

class Foo(object):
def __init__(self, id, description):
self.id = id
self.description = description

@property
def calculated_value(self):
self._calculated_value = datetime.datetime.now().second + 10
return self._calculated_value

mapper(Foo, foo_table,
properties = {
'calculated_value' : synonym('_calculated_value',
map_column=True)
}
)

engine = create_engine('sqlite:///test.db')
Session = sessionmaker(bind=engine)
meta.create_all(bind=engine)

session = Session()
session.add( Foo('xyz', 'test only') )
session.commit()


Since self._calculated_value is created within the property, it does
not exist until you actually access the property. How do I set this up
to get sqlalchemy to go use the actual return value of the property
when session.commit is called?

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] Session with multiple data insert

2010-06-11 Thread Ghido
Hi all, i have the following situation:

i have a table (imported_data) with data generated from some  wifi
terminals and i have other table (using_data) where user can modify /
delete the data.
Every time i run the program,  i need to copy new data of
imported_data into using_data.
i using this query for get the new data:

def newdata(self,src_table,dst_table):
lista =
config.Sess.query(src_table).outerjoin((dst_table,
src_table.ID==dst_table.ID)).filter(dst_table.ID==None).all()
return lista

So I try to insert all data in the table but always inserts only the
last line:

for rec in dati:
config.Sess.add(rec)
config.Sess.commit()

Thanks a lot for every suggestions.

Ghido

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



Re: [sqlalchemy] How to map to read only descriptor

2010-06-11 Thread Jeff Peck
On Fri, Jun 11, 2010 at 4:16 AM, jpeck peck.j...@gmail.com wrote:
 I am trying to map to a simple read only property. According to the
 docs, I *think* I am supposed to use synonym. The problem is that I am
 getting a None value for the mapped descriptor's column.


Ok, so I got this working with synonym, but I am not sure I am doing
this the best way. As long as I access the descriptor before an insert
or update, the synonym worked ok.

I ended up using a MapperExtension like so:

class UpdatePropertiesExtension(MapperExtension):
def __init__(self, properties):
self.properties = properties

def _update_properties(self, instance):
for p in self.properties:
getattr(instance, p)

def before_insert(self, mapper, connection, instance):
self._update_properties(instance)

def before_update(self, mapper, connection, instance):
self._update_properties(instance)


This works fine for me, but I'm wondering if there is a better way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] Using Inspector with oracle+zxjdbc

2010-06-11 Thread Witzel, Stefan
Hello,

I'm trying to retrieve some column properties from a oracle database using
oracle+zxjdbc:

jdbcUrl =
'%(engine_dialect)s://%(username)s:%(password)s...@%(hostname)s:%(port)d/%(data
base)s' % connection

engine = sa.create_engine(jdbcUrl)

inspector = sa.engine.reflection.Inspector(engine)
tableNames = inspector.get_table_names()
for tableName in tableNames[:4]:
columns = inspector.get_columns(tableName)
print tableName
for column in columns:
print , column['name'], ': ',str(column['type'])

The program termintes with the exception

Traceback (most recent call last):
  File oracle-test-b.py, line 23, in module
tableNames = inspector.get_table_names()
  File
/usr/local/lib/jython251/Lib/site-packages/sqlalchemy/engine/reflection.py
, line 98, in get_table_names
tnames = self.dialect.get_table_names(self.conn,
  File string, line 1, in lambda
  File
/usr/local/lib/jython251/Lib/site-packages/sqlalchemy/engine/reflection.py
, line 40, in cache
ret = fn(self, con, *args, **kw)
  File
/usr/local/lib/jython251/Lib/site-packages/sqlalchemy/dialects/oracle/base.
py, line 764, in get_table_names
schema = self.denormalize_name(schema or self.default_schema_name)
AttributeError: 'OracleDialect_zxjdbc' object has no attribute
'default_schema_name'

Java 1.6.0 / Jython 2.5.1 / sqlalchemy 0.6.1

Thanks in advance.

PS: any problems when using postgresql



smime.p7s
Description: S/MIME cryptographic signature


Re: [sqlalchemy] Kerberos authentication with sybase

2010-06-11 Thread Michael Bayer


On Jun 11, 2010, at 4:50 AM, Cserna, Zsolt wrote:

 
 The DBAPI is python-sybase (http://python-sybase.sourceforge.net/).
 
 Here is an example:
 
 conn = Sybase.connect(hostname, , , delay_connect=1)
 conn.set_property(Sybase.CS_SEC_NETWORKAUTH, Sybase.CS_TRUE)
 conn.set_property(Sybase.CS_SEC_SERVERPRINCIPAL, principal)
 conn.connect()
 
 The variable principal would come from connection string.


OK that is fine, is the above part of some larger pattern of connection styles 
?  like is there some other series of things I can do ater setting NETWORKAUTH 
to TRUE , other options ?   if we want to make a feature out of this, it would 
be best to suit the whole range of use cases.



 
 
 Zsolt
 
 
 -Original Message-
 From: sqlalchemy@googlegroups.com 
 [mailto:sqlalch...@googlegroups.com] On Behalf Of Michael Bayer
 Sent: Thursday, June 10, 2010 15:58
 To: sqlalchemy@googlegroups.com
 Subject: Re: [sqlalchemy] Kerberos authentication with sybase
 
 if you want to show me how that's done with your DBAPI (what 
 DBAPI is this?), sure, though if its something that you pass 
 in via **kw to DBAPI.connect(), you can already do that by 
 passing connect_args to create_engine(), or adding them onto 
 the querystring db://...?foo=bar.
 
 
 
 On Jun 10, 2010, at 9:10 AM, Cserna, Zsolt wrote:
 
 
 Hi all,
 
 Is there any plan to add kerberos authentication to the 
 sybase engine in sqlalchemy?
 
 I've implemented it but it's using the creator parameter of 
 the create_engine function, which is ok, but in certain 
 circumstances when the application using sqlalchemy uses 
 configuration from a text file, I'm not able to do it easily 
 (in pylons I need to modify my templates, or add a bunch of 
 code to each project).
 
 It would be nice if sqlalchemy would be able to accept the 
 server's principal specified in the connection string somehow 
 - and if it's specified use kerberos to authenticate the client.
 
 Is it possible to implement this modification in 
 sqlalchemy? I'm happy to contribute my current implementation.
 
 Thanks,
 Zsolt
 
 
 --
 
 NOTICE: If received in error, please destroy, and notify 
 sender. Sender does not intend to waive confidentiality or 
 privilege. Use of this email is prohibited when received in 
 error. We may monitor and store emails to the extent 
 permitted by applicable law.
 
 --
 You received this message because you are subscribed to the 
 Google Groups sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
 
 
 -- 
 You received this message because you are subscribed to the 
 Google Groups sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
 
 
 --
 NOTICE: If received in error, please destroy, and notify sender. Sender does 
 not intend to waive confidentiality or privilege. Use of this email is 
 prohibited when received in error. We may monitor and store emails to the 
 extent permitted by applicable law.
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
 

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



Re: [sqlalchemy] How to map to read only descriptor

2010-06-11 Thread Michael Bayer

On Jun 11, 2010, at 5:16 AM, jpeck wrote:

 I am trying to map to a simple read only property. According to the
 docs, I *think* I am supposed to use synonym. The problem is that I am
 getting a None value for the mapped descriptor's column.
 
 For example:
 
 import datetime
 from sqlalchemy import Column, Table, Integer, String, MetaData,
 create_engine
 from sqlalchemy.orm import mapper, sessionmaker, synonym
 
 meta = MetaData()
 foo_table = Table('foo', meta,
Column('id', String(3), primary_key=True),
Column('description', String(64), nullable=False),
Column('calculated_value', Integer, nullable=False),
)
 
 class Foo(object):
def __init__(self, id, description):
self.id = id
self.description = description
 
@property
def calculated_value(self):
self._calculated_value = datetime.datetime.now().second + 10
return self._calculated_value
 
 mapper(Foo, foo_table,
properties = {
'calculated_value' : synonym('_calculated_value',
 map_column=True)
}
 )


wouldn't this be simpler ?

class Foo(object):
def __init__(self, id, description):
self.id = id
self.description = description
self.calculated_value = datetime.now().second + 10

mapper(Foo, foo_table)

want it read only ?


class Foo(object):
def __init__(self, id, description):
self.id = id
self.description = description
self._calculated_value = datetime.now().second + 10

@property
def calculated_value(self):
return self._calculated_value

mapper(Foo, foo_table, 
properties={'_calculated_value':foo_table.c.calculated_value})


another option is to stick datetime.now().second + 10 into theTable directly 
as a default for the Column.  If it were still empty at flush time, it would 
get persisted at that point.

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



Re: [sqlalchemy] Using Inspector with oracle+zxjdbc

2010-06-11 Thread Michael Bayer

On Jun 11, 2010, at 11:17 AM, Michael Bayer wrote:

 
 On Jun 11, 2010, at 7:46 AM, Witzel, Stefan wrote:
 
 Hello,
 
 I'm trying to retrieve some column properties from a oracle database using
 oracle+zxjdbc:
 
 jdbcUrl =
 '%(engine_dialect)s://%(username)s:%(password)s...@%(hostname)s:%(port)d/%(data
 base)s' % connection
 
 engine = sa.create_engine(jdbcUrl)
 
 inspector = sa.engine.reflection.Inspector(engine)
 
 use Inspector.from_engine(engine) here.   

correction, its a slight inaccuracy in how the inspector is doing its work.  
Just pass a connection, i.e. engine.connect(), to the Inspector, not an engine. 
   We will try to create a fix for this.



 
 
 
 
 
 tableNames = inspector.get_table_names()
 for tableName in tableNames[:4]:
   columns = inspector.get_columns(tableName)
   print tableName
   for column in columns:
   print , column['name'], ': ',str(column['type'])
 
 The program termintes with the exception
 
 Traceback (most recent call last):
 File oracle-test-b.py, line 23, in module
   tableNames = inspector.get_table_names()
 File
 /usr/local/lib/jython251/Lib/site-packages/sqlalchemy/engine/reflection.py
 , line 98, in get_table_names
   tnames = self.dialect.get_table_names(self.conn,
 File string, line 1, in lambda
 File
 /usr/local/lib/jython251/Lib/site-packages/sqlalchemy/engine/reflection.py
 , line 40, in cache
   ret = fn(self, con, *args, **kw)
 File
 /usr/local/lib/jython251/Lib/site-packages/sqlalchemy/dialects/oracle/base.
 py, line 764, in get_table_names
   schema = self.denormalize_name(schema or self.default_schema_name)
 AttributeError: 'OracleDialect_zxjdbc' object has no attribute
 'default_schema_name'
 
 Java 1.6.0 / Jython 2.5.1 / sqlalchemy 0.6.1
 
 Thanks in advance.
 
 PS: any problems when using postgresql
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
 

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



Re: [sqlalchemy] Using Inspector with oracle+zxjdbc

2010-06-11 Thread Michael Bayer

On Jun 11, 2010, at 7:46 AM, Witzel, Stefan wrote:

 Hello,
 
 I'm trying to retrieve some column properties from a oracle database using
 oracle+zxjdbc:
 
 jdbcUrl =
 '%(engine_dialect)s://%(username)s:%(password)s...@%(hostname)s:%(port)d/%(data
 base)s' % connection
 
 engine = sa.create_engine(jdbcUrl)
 
 inspector = sa.engine.reflection.Inspector(engine)

use Inspector.from_engine(engine) here.   





 tableNames = inspector.get_table_names()
 for tableName in tableNames[:4]:
columns = inspector.get_columns(tableName)
print tableName
for column in columns:
print , column['name'], ': ',str(column['type'])
 
 The program termintes with the exception
 
 Traceback (most recent call last):
  File oracle-test-b.py, line 23, in module
tableNames = inspector.get_table_names()
  File
 /usr/local/lib/jython251/Lib/site-packages/sqlalchemy/engine/reflection.py
 , line 98, in get_table_names
tnames = self.dialect.get_table_names(self.conn,
  File string, line 1, in lambda
  File
 /usr/local/lib/jython251/Lib/site-packages/sqlalchemy/engine/reflection.py
 , line 40, in cache
ret = fn(self, con, *args, **kw)
  File
 /usr/local/lib/jython251/Lib/site-packages/sqlalchemy/dialects/oracle/base.
 py, line 764, in get_table_names
schema = self.denormalize_name(schema or self.default_schema_name)
 AttributeError: 'OracleDialect_zxjdbc' object has no attribute
 'default_schema_name'
 
 Java 1.6.0 / Jython 2.5.1 / sqlalchemy 0.6.1
 
 Thanks in advance.
 
 PS: any problems when using postgresql
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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 to map to read only descriptor

2010-06-11 Thread jpeck


On Jun 11, 10:13 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 11, 2010, at 5:16 AM, jpeck wrote:





  I am trying to map to a simple read only property. According to the
  docs, I *think* I am supposed to use synonym. The problem is that I am
  getting a None value for the mapped descriptor's column.

  For example:

  import datetime
  from sqlalchemy import Column, Table, Integer, String, MetaData,
  create_engine
  from sqlalchemy.orm import mapper, sessionmaker, synonym

  meta = MetaData()
  foo_table = Table('foo', meta,
     Column('id', String(3), primary_key=True),
     Column('description', String(64), nullable=False),
     Column('calculated_value', Integer, nullable=False),
     )

  class Foo(object):
     def __init__(self, id, description):
         self.id = id
         self.description = description

    �...@property
     def calculated_value(self):
         self._calculated_value = datetime.datetime.now().second + 10
         return self._calculated_value

  mapper(Foo, foo_table,
     properties = {
         'calculated_value' : synonym('_calculated_value',
  map_column=True)
     }
  )

 wouldn't this be simpler ?

 class Foo(object):
     def __init__(self, id, description):
         self.id = id
         self.description = description
         self.calculated_value = datetime.now().second + 10

 mapper(Foo, foo_table)

 want it read only ?

 class Foo(object):
     def __init__(self, id, description):
         self.id = id
         self.description = description
         self._calculated_value = datetime.now().second + 10

     @property
     def calculated_value(self):
         return self._calculated_value

 mapper(Foo, foo_table, 
 properties={'_calculated_value':foo_table.c.calculated_value})

 another option is to stick datetime.now().second + 10 into theTable 
 directly as a default for the Column.  If it were still empty at flush 
 time, it would get persisted at that point.


Michael - thanks for the response. My original post was just a
contrived example, and I should probably have included something
closer to what I was actually doing. In my production code I was using
the read only descriptor to iterate over a list of objects to
calculate a value. I need the property to calculate the value on the
fly in case something gets added/deleted from the list of objects. The
issue I had was that I needed the property to fire just before
insertion into the database to update the value referenced by synonym.
I ended up using MapperExtension to access the property before the
insertion occurred...

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] cross-database joins with MySQL

2010-06-11 Thread Chris Withers

Hi All,

We have engines set up like:

engine1 = create_engine('mysql://username:passw...@server/db1')
engine2 = create_engine('mysql://username:passw...@server/db2')

..and then have them bound to separate sessions, with separate model 
classes mapped to them.


Now, mysql supports cross database joins, eg:

select t1.colwhatever
from db1.table1 as t1,db2.table2 as t2
where t1.something=t2.something

Is it possible to express that in SQLAlchemy, particularly at the ORM 
layer with the multiple session/engine/model setup described above?
(I suppose the case to test would be, if ModelA is bound to engine1 and 
ModelB is bound to engine2, how would we do:


session.query(ModelA,ModelB,ModelA.something==ModelB.something)

...or something similar, if the above isn't possible?

cheers,

Chris

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



Re: [sqlalchemy] cross-database joins with MySQL

2010-06-11 Thread Michael Bayer

On Jun 11, 2010, at 12:51 PM, Chris Withers wrote:

 Hi All,
 
 We have engines set up like:
 
 engine1 = create_engine('mysql://username:passw...@server/db1')
 engine2 = create_engine('mysql://username:passw...@server/db2')
 
 ..and then have them bound to separate sessions, with separate model classes 
 mapped to them.
 
 Now, mysql supports cross database joins, eg:
 
 select t1.colwhatever
 from db1.table1 as t1,db2.table2 as t2
 where t1.something=t2.something
 
 Is it possible to express that in SQLAlchemy, particularly at the ORM layer 
 with the multiple session/engine/model setup described above?
 (I suppose the case to test would be, if ModelA is bound to engine1 and 
 ModelB is bound to engine2, how would we do:
 
 session.query(ModelA,ModelB,ModelA.something==ModelB.something)
 
 ...or something similar, if the above isn't possible?

its not possible across two distinct database connections, no. Only the 
database can do joins, and that requires a single connection session to do so.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] is attribute changes?

2010-06-11 Thread bogun . dmitriy
Hello.

Is sqlachemy allow to check for changes on particallar mapped
attribute? Receive it's old value?

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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] Managing access and permissions to mapped objects and base tables

2010-06-11 Thread Rich
I am somewhat new to sqla and python. I am developing a module of sqla
OR mapped objects that will be used by other developers. Those
developers who will not be involved in the (currently postgres)
database or model details. They will be using the module to write
their own python clients to upload data sets or retrieve and delete
data. Hopefully they will just be using sessions and adding objects or
calling object methods.

Some will be 'power users' that can do most anything, while for
others  I need to be able to restrict what objects they can create,
delete etc or which object methods they can access.

My question is where/how to manage permissions? Is there some example,
template, pattern that could guide me.  Part could be possibly be done
through database permission

Non-power-users should at minimum only be able to create-but-not-
delete data, which might best be at a database user or group
permission-level since someone could inadvertently send damaging pure
sql.

But ideally, be able to think about create/delete/update data as
python objects that belong to them and do damage to others.  Power-
users would be able to most anything across all users.

Perhaps I need a business layer in the database like views or stored
procedures to protect my base tables... or should that layer be on the
python and/or sqlalchemy .  Perhaps I need two modules - one for power
users?

What is recommended? Where do I start? Is there a project out there
somewhere that I can learn from?

Thanks in advance for any help!

Rich

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



Re: [sqlalchemy] good IDE for SQLAlchemy and wxPython?

2010-06-11 Thread Carl Brewer

On 10/06/2010 11:26 PM, werner wrote:

Carl,




That would be nice but I am not aware of one.

Personally I use Boa to develop, it has a GUI designer built in you can
use to generate the dialogs/frames etc and I then use validators to load
data to/from the controls.


I've had a quick look at Boa, it seems to be a bit dead as a project 
though?  The last update was some years ago.  Is that just my poor 
googling skills?





Dabo (http://www.dabodev.com/) might also be an alternative you want to
look at, also it has is own db access stuff - I asked in the past if
they don't want to switch to SA but there doesn't seem to be any
interest in doing this.


I think software written in Dabo would be too 'locked in to Dabo' by the 
look of it.


I like the idea of SQLAlchemy, it's a very compelling toolkit.

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