[sqlalchemy] Too many database connections.

2007-08-29 Thread caffecoder

Hello.

I have pylons 0.96 (SVN) and current SQLAlchemy (0.3), and I have bug
that
doesn't exist earlier.

My connection code:
code
import sqlalchemy.mods.threadlocal
from sqlalchemy import DynamicMetaData, objectstore

metadata = DynamicMetaData( case_sensitive = False )

def db_connect( dsn ):
engine = create_engine( dsn, echo=False, echo_pool=False,
encoding='latin2',  convert_unicode=True, pool_recycle=3600,
pool_timeout=15, pool_size=5 )
metadata.connect( engine )
/code

command netstat -an|grep 5432|grep ESTABLISHED|wc -l displays one
more connection after each refresh of page until I have exceptions
such as:

sqlalchemy.exceptions.DBAPIError: (Connection failed)
(OperationalError) FATAL: sorry, too many clients already

What is wrong?


--~--~-~--~~~---~--~~
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] SA 0.4 orm mapped class 'instrumentation time'

2007-08-29 Thread Marco De Felice

With SA 0.4beta4 if I try to access a mapped object field
(Table.c.fieldname) before any query  has been sent to the database the
call fails with a AttributeError(key). Everything works if I do this
after having issued a query.

-- Example: (skip to the __main__ section)

import sqlalchemy as sqa
import sqlalchemy.orm as sqorm

class Table(object):
pass

class Model(object):

def connect(self, u, p, db, h):

dsn =postgres://%(u)s:%(p)[EMAIL PROTECTED](h)s:5432/%(db)s % 
vars()

self.engine = sqa.create_engine(dsn)

metadata = sqa.MetaData()
metadata.bind = self.engine

self.table_table = sqa.Table('table', metadata,
  sqa.Column('id', sqa.Integer,
 primary_key = True),
  sqa.Column('field1', sqa.String(120))
  )

sqorm.mapper(Table, self.table_table)


if __name__ == __main__:

model = Model()
model.connect(user, password, db, host)

session = sqorm.create_session()

filters = []

#THE FOLLOWING WILL FAIL WITH AttributeError: field1
#BUT NOT IF A QUERY HAS ALREADY BEEN ISSUED
#also against another mapped object.
#test = session.query(ANYMAPPEDOBJ).all()
#test = session.query(Table).all()
#uncomment one of the above and it works

filters.append(Table.c.field1.op('ILIKE') (FILTERTEXT))

filter = sqa.and_(*filters)
result = session.query(Table).\
filter(filter).\
all()


session.close()


--~--~-~--~~~---~--~~
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] [ANN] FormAlchemy 0.1 released !

2007-08-29 Thread Alexandre Conrad

Dear SQLAlchemy users,

I am pleased to announce the first release of FormAlchemy !

FormAlchemy: Auto-generated, customizable HTML input form fields from 
your SQLAlchemy mapped classes.

FormAlchemy is a library written in Python that generates HTML form 
fields from your SQLAlchemy's mapped classes.

If you are using SQLAlchemy in a web environment requiring user input 
for your database(s), chances are that you will feel writing the same 
code for your HTML forms than the code you wrote for your SQLAlchemy 
tables. If you are tired of writing, updating, validating your HTML 
forms over and over again, FormAlchemy might get most of the work done 
for you. Get the tedious job done faster and easier without feeling to 
repeat yourself.

Checkout the quick tutorial for basic FormAlchemy usage:

   http://code.google.com/p/formalchemy/wiki/QuickTutorial

Home: http://formalchemy.googlecode.com
Mailing list: http://groups.google.com/group/formalchemy

Feedback is appreciated. :)

Regards,
-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
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: Too many database connections.

2007-08-29 Thread Mike Orr

On 8/28/07, caffecoder [EMAIL PROTECTED] wrote:
 sqlalchemy.exceptions.DBAPIError: (Connection failed)
 (OperationalError) FATAL: sorry, too many clients already

I've been getting a similar but not identical error after upgrading to
SQLAlchemy 0.4, and somebody else on the list also mentioned this
recently.  I don't have the traceback but it was  the error for
exceeding the 'max_overflow' number of connections.

I worked around it by setting the 'max_overflow' engine option from 10
to 30.  I haven't tried the 'threadlocal' pooling strategy, which is
supposed to minimize the number of connections per thread.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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] sqlalchemy.exceptions.TimeoutError with psycopg2

2007-08-29 Thread Jian Luo

Hi List:

I am just doing a test of my pylons site under medium load.
(ab2 -c 20 -n 5000 ...)

and got following errors:

2007-08-29 17:32:34,468 INFO  [paste.httpserver.ThreadPool]
kill_hung_threads status: 10 threads (10 working, 0 idle, 0 starting)
ave time 2.24sec, max time 7.22sec, killed 0 workers
2007-08-29 17:32:40,874 INFO  [paste.httpserver.ThreadPool]
kill_hung_threads status: 10 threads (10 working, 0 idle, 0 starting)
ave time 7.28sec, max time 13.63sec, killed 0 workers
Error - class 'sqlalchemy.exceptions.TimeoutError': QueuePool limit
of size 5 overflow 10 reached, connection timed out, timeout 30
Error - class 'sqlalchemy.exceptions.TimeoutError': QueuePool limit
of size 5 overflow 10 reached, connection timed out, timeout 30

Some Details of test environment:

$ uname -a
Linux scorpio 2.6.21-suspend2-r6 #2 SMP PREEMPT Tue Jul 24 18:13:15
CEST 2007 x86_64 Intel(R) Core(TM)2 CPU T5600 @ 1.83GHz GenuineIntel
GNU/Linux

$ postgres --version
postgres (PostgreSQL) 8.2.4

$ python
Python 2.5.1 (r251:54863, Aug 24 2007, 12:15:43)
[GCC 4.1.2 (Gentoo 4.1.2)] on linux2

 psycopg2.__version__
'2.0.2 (dec dt ext pq3)'
also tested with 2.0.5.1 and 2.0.6, same error

SQLAlchemy is from trunk r3419


I'am using scoped_session with elixir but I don't think it's the
point.
And the db query is simply select * from a single table, without
joins.

Engine is from engine_from_config, no extra options are given.
Swithing to option: poolclass = SingletonThreadPool seems to solve the
Problem.

And here is my model/__init__.py

from pylons import config
from sqlalchemy import MetaData
from sqlalchemy.orm import scoped_session, sessionmaker

# Global session manager.  Session() returns the session object
appropriate for
# the current web request.
Session = scoped_session(
sessionmaker(
autoflush=True, transactional=True,
bind=config['pylons.g'].sa_engine
)
)

import elixir
elixir.objectstore = elixir.Objectstore(Session)
elixir.options_defaults.update({
'shortnames': True,
#'session': Session(),
#'inheritance': 'multi',
})

# Global Metadata
metadata = elixir.metadata
if not metadata.bind:
metadata.bind = config['pylons.g'].sa_engine

del config

# Shortcuts to elixir methods
create_all = elixir.create_all
cleanup_all = elixir.cleanup_all
drop_all = elixir.drop_all
setup_all = elixir.setup_all

from user import User, Group, Permission
from admin import ActionHistory
from localization import *
from meta import *

# preparing orm mapper
setup_all()


Did I do things right? Or just another Bug?

Thanks

Jian


--~--~-~--~~~---~--~~
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] Updating the sequence number

2007-08-29 Thread alex.schenkman

Hi:

I'm new to SQL.
I have to execute the following SQL line, which updates a sequence
number. The table zseq_document_types_lookup has only one record with
this number.

update zseq_document_types_lookup set id=2;


I thought of retrieving the record with something like this:

class Sequence(object):
   pass

def someFunction():
db = create_engine( ... )
metadata = BoundMetadata( db )
session = create_session( bind_to = self.db )
table = Table('zseq_document_types_lookup', metadata,
autoload=True)
mapper(Sequence, table)

'Fetch the only record in the table'
sequenceNumber = session.query(Sequence).selectfirst()

'Increment the sequence number'
sequenceNumber.id += 1

session.flush()


BUT, it doesn't work. I get an error Can't change the identity of
instance sequenceNumber

My guess is that there is a better way of updating this record...

Thanks 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Read only connection with Table reflection

2007-08-29 Thread Jason Koelker

I am attempting to use SQLAlchemy's table reflection to access a MSSQL
2k database.  However the user I can connect with only had
db_datareader access.  When SQLAlchemy tries to load the schema, it
attempts a rollback at the end, which the user does not have
permission to execute:

2007-08-29 11:32:24,400 INFO sqlalchemy.engine.base.Engine.0x..cL SET
nocount ON
2007-08-29 11:32:24,400 INFO sqlalchemy.engine.base.Engine.0x..cL None
2007-08-29 11:32:24,416 INFO sqlalchemy.engine.base.Engine.0x..cL
SELECT [COLUMNS_50b4].[TABLE_SCHEMA], [COLUMNS_50b4].[TABLE_NAME],
[COLUMNS_50b4].[COLUMN_NAME], [COLUMNS_50b4].[IS_NULLABLE],
[COLUMNS_50b4].[DATA_TYPE], [COLUMNS_50b4].[ORDINAL_POSITION],
[COLUMNS_50b4].[CHARACTER_MAXIMUM_LENGTH], [COLUMNS_50b4].
[NUMERIC_PRECISION], [COLUMNS_50b4].[NUMERIC_SCALE], [COLUMNS_50b4].
[COLUMN_DEFAULT]
FROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_50b4]
WHERE [COLUMNS_50b4].[TABLE_NAME] = ? AND [COLUMNS_50b4].
[TABLE_SCHEMA] = ? ORDER BY [COLUMNS_50b4].[ORDINAL_POSITION]
2007-08-29 11:32:24,416 INFO sqlalchemy.engine.base.Engine.0x..cL
['Table', 'dbo']
2007-08-29 11:32:24,416 INFO sqlalchemy.engine.base.Engine.0x..cL
ROLLBACK

Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/jkoelker/lib/python2.5/site-packages/Elixir-0.3.0-
py2.5.egg/elixir/entity.py, line 317, in __init__
desc.setup()
  File /home/jkoelker/lib/python2.5/site-packages/Elixir-0.3.0-
py2.5.egg/elixir/entity.py, line 110, in setup
self.setup_table()
  File /home/jkoelker/lib/python2.5/site-packages/Elixir-0.3.0-
py2.5.egg/elixir/entity.py, line 221, in setup_table
*args, **kwargs)
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/schema.py, line 175, in __call__
metadata._get_engine(raiseerr=True).reflecttable(table)
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/engine/base.py, line 806, in reflecttable
self.dialect.reflecttable(conn, table)
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/databases/mssql.py, line 495, in reflecttable
c = connection.execute(s)
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/engine/base.py, line 517, in execute
return Connection.executors[c](self, object, *multiparams,
**params)
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/engine/base.py, line 557, in
execute_clauseelement
return self.execute_compiled(elem.compile(dialect=self.dialect,
parameters=param), *multiparams, **params)
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/engine/base.py, line 568, in execute_compiled
self._execute_raw(context)
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/engine/base.py, line 581, in _execute_raw
self._execute(context)
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/engine/base.py, line 596, in _execute
self._autorollback()
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/engine/base.py, line 497, in _autorollback
self._rollback_impl()
  File /home/jkoelker/lib/python2.5/site-packages/SQLAlchemy-0.3.10-
py2.5.egg/sqlalchemy/engine/base.py, line 475, in _rollback_impl
raise exceptions.SQLError(None, None, e)
sqlalchemy.exceptions.SQLError: (Error) ('HY000', '[HY000] [FreeTDS]
[SQL Server]Could not perform COMMIT or ROLLBACK (0)') None None

Is there any way to use reflection with a read only connection?

Happy Hacking!

7-11


--~--~-~--~~~---~--~~
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.exceptions.TimeoutError with psycopg2

2007-08-29 Thread jason kirtland

Jian wrote:

 Hi List:

 I am just doing a test of my pylons site under medium load.
 (ab2 -c 20 -n 5000 ...)

 and got following errors:

 2007-08-29 17:32:34,468 INFO  [paste.httpserver.ThreadPool]
 kill_hung_threads status: 10 threads (10 working, 0 idle, 0
 starting) ave time 2.24sec, max time 7.22sec, killed 0 workers
 2007-08-29 17:32:40,874 INFO  [paste.httpserver.ThreadPool]
 kill_hung_threads status: 10 threads (10 working, 0 idle, 0
 starting) ave time 7.28sec, max time 13.63sec, killed 0 workers
 Error - class 'sqlalchemy.exceptions.TimeoutError': QueuePool
 limit of size 5 overflow 10 reached, connection timed out,
 timeout 30 Error - class 'sqlalchemy.exceptions.TimeoutError':
 QueuePool limit of size 5 overflow 10 reached, connection timed
 out, timeout 30

 Some Details of test environment:
 [...snip...]

How are you managing your sessions and connections?  Most likely 
connections are being held somewhere, starving the pool.

A basic setup and query like you've described, served via Paste's 
server doesn't skip a beat for me even when run with 'ab -c 500'.

def wsgi_app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text-plain')])
entities = Data.query.all()
page = ','.join([e.data for e in entities])
elixir.objectstore.close()
return [page]
paste.httpserver.serve(wsgi_app)



--~--~-~--~~~---~--~~
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.exceptions.TimeoutError with psycopg2

2007-08-29 Thread Jian Luo

Hi Jason,

thanks for the reply.

My pylons basecontroller takes care of the session clean up
like this:

class BaseController(WSGIController):
def __call__(self, environ, start_response):
try:
return WSGIController.__call__(self, environ,
start_response)
finally:
model.Session.remove()

When I use model.Session.close(), everything works.
But error comes whenever i change it to model.Session.remove().
AFAIK, remove() make more sense than close() on a real site with
dynamic load
which is learned from SA docs.


I changed your script a little to do the test again.
The result is just the same as described above:

* with Session.close(), everything works just fine even 'ab -c 500'
* with Session.remove(), the script caught timeout exceptions in
minutes.

Best

Jian


On Aug 29, 10:05 pm, jason kirtland [EMAIL PROTECTED] wrote:
 Jian wrote:

  Hi List:

  I am just doing a test of my pylons site under medium load.
  (ab2 -c 20 -n 5000 ...)

  and got following errors:

  2007-08-29 17:32:34,468 INFO  [paste.httpserver.ThreadPool]
  kill_hung_threads status: 10 threads (10 working, 0 idle, 0
  starting) ave time 2.24sec, max time 7.22sec, killed 0 workers
  2007-08-29 17:32:40,874 INFO  [paste.httpserver.ThreadPool]
  kill_hung_threads status: 10 threads (10 working, 0 idle, 0
  starting) ave time 7.28sec, max time 13.63sec, killed 0 workers
  Error - class 'sqlalchemy.exceptions.TimeoutError': QueuePool
  limit of size 5 overflow 10 reached, connection timed out,
  timeout 30 Error - class 'sqlalchemy.exceptions.TimeoutError':
  QueuePool limit of size 5 overflow 10 reached, connection timed
  out, timeout 30

  Some Details of test environment:
  [...snip...]

 How are you managing your sessions and connections?  Most likely
 connections are being held somewhere, starving the pool.

 A basic setup and query like you've described, served via Paste's
 server doesn't skip a beat for me even when run with 'ab -c 500'.

 def wsgi_app(environ, start_response):
 start_response('200 OK', [('Content-Type', 'text-plain')])
 entities = Data.query.all()
 page = ','.join([e.data for e in entities])
 elixir.objectstore.close()
 return [page]
 paste.httpserver.serve(wsgi_app)


--~--~-~--~~~---~--~~
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.exceptions.TimeoutError with psycopg2

2007-08-29 Thread jason kirtland

Jian wrote:

 Hi Jason,

 thanks for the reply.

 My pylons basecontroller takes care of the session clean up
 like this:

 class BaseController(WSGIController):
 def __call__(self, environ, start_response):
 try:
 return WSGIController.__call__(self, environ,
 start_response)
 finally:
 model.Session.remove()

 When I use model.Session.close(), everything works.
 But error comes whenever i change it to model.Session.remove().
 AFAIK, remove() make more sense than close() on a real site with
 dynamic load
 which is learned from SA docs.

I believe that remove() simply detaches the session from the 
current context, it doesn't explicitly close it out or release the 
bound connection for a transactional session.  Try closing before 
you remove.


--~--~-~--~~~---~--~~
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.exceptions.TimeoutError with psycopg2

2007-08-29 Thread Jian Luo

the remove is described in doc as close + extra cleanup
Shouldn't the doc be updated to add that point, which will make the
the life of newbies like me easier =D
Or better: add the explicitly close in remove.

Best

Jian

On Aug 30, 12:10 am, jason kirtland [EMAIL PROTECTED] wrote:
 Jian wrote:

  Hi Jason,

  thanks for the reply.

  My pylons basecontroller takes care of the session clean up
  like this:

  class BaseController(WSGIController):
  def __call__(self, environ, start_response):
  try:
  return WSGIController.__call__(self, environ,
  start_response)
  finally:
  model.Session.remove()

  When I use model.Session.close(), everything works.
  But error comes whenever i change it to model.Session.remove().
  AFAIK, remove() make more sense than close() on a real site with
  dynamic load
  which is learned from SA docs.

 I believe that remove() simply detaches the session from the
 current context, it doesn't explicitly close it out or release the
 bound connection for a transactional session.  Try closing before
 you remove.


--~--~-~--~~~---~--~~
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.exceptions.TimeoutError with psycopg2

2007-08-29 Thread jason kirtland

Jian wrote:

 the remove is described in doc as close + extra cleanup
 Shouldn't the doc be updated to add that point, which will make
 the the life of newbies like me easier =D
 Or better: add the explicitly close in remove.

Yeah, the current remove() implementation in trunk isn't yet in 
sync with the docs.  I'm not sure if it is simply not complete or 
if the feature is in flux...  It will get resolved one way or 
another before the next beta.  But for now, I'm pretty confident 
that having that explicit close() in there won't hurt you going 
forward.


--~--~-~--~~~---~--~~
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: Read only connection with Table reflection

2007-08-29 Thread shday


 Is there any way to use reflection with a read only connection?


I use reflection on an Oracle database with read only permission, no
problems (using SA 0.3.8).

I don't recall seeing SA trying to do a ROLLBACK during reflection
though.

Steve


--~--~-~--~~~---~--~~
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: SA 0.4 orm mapped class 'instrumentation time'

2007-08-29 Thread Michael Bayer

its most likely uncompiled mappers.  the c attribute on the class  
is deprecated; use Table.attribute instead.  Also issue  
compile_mappers() after your mappers have been established to force a  
compile.  The typical usage pattern is that the session.query() is  
created first, which also issues a mapper compile operation.



On Aug 29, 2007, at 3:21 AM, Marco De Felice wrote:


 With SA 0.4beta4 if I try to access a mapped object field
 (Table.c.fieldname) before any query  has been sent to the database  
 the
 call fails with a AttributeError(key). Everything works if I do this
 after having issued a query.

 -- Example: (skip to the __main__ section)

 import sqlalchemy as sqa
 import sqlalchemy.orm as sqorm

 class Table(object):
 pass

 class Model(object):

 def connect(self, u, p, db, h):

 dsn =postgres://%(u)s:%(p)[EMAIL PROTECTED](h)s:5432/%(db)s % 
 vars()

 self.engine = sqa.create_engine(dsn)

 metadata = sqa.MetaData()
 metadata.bind = self.engine

 self.table_table = sqa.Table('table', metadata,
   sqa.Column('id', sqa.Integer,
primary_key = True),
   sqa.Column('field1', sqa.String(120))
   )

   sqorm.mapper(Table, self.table_table)


 if __name__ == __main__:

 model = Model()
 model.connect(user, password, db, host)

 session = sqorm.create_session()

 filters = []

 #THE FOLLOWING WILL FAIL WITH AttributeError: field1
 #BUT NOT IF A QUERY HAS ALREADY BEEN ISSUED
 #also against another mapped object.
 #test = session.query(ANYMAPPEDOBJ).all()
 #test = session.query(Table).all()
 #uncomment one of the above and it works

 filters.append(Table.c.field1.op('ILIKE') (FILTERTEXT))

 filter = sqa.and_(*filters)
 result = session.query(Table).\
   filter(filter).\
   all()


 session.close()


 


--~--~-~--~~~---~--~~
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.exceptions.TimeoutError with psycopg2

2007-08-29 Thread Michael Bayer

Ive committed this fix in r3425.  remove() calls close() on an  
existing session if one is present.


On Aug 29, 2007, at 6:49 PM, jason kirtland wrote:


 Jian wrote:

 the remove is described in doc as close + extra cleanup
 Shouldn't the doc be updated to add that point, which will make
 the the life of newbies like me easier =D
 Or better: add the explicitly close in remove.

 Yeah, the current remove() implementation in trunk isn't yet in
 sync with the docs.  I'm not sure if it is simply not complete or
 if the feature is in flux...  It will get resolved one way or
 another before the next beta.  But for now, I'm pretty confident
 that having that explicit close() in there won't hurt you going
 forward.


 


--~--~-~--~~~---~--~~
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: Read only connection with Table reflection

2007-08-29 Thread Michael Bayer


On Aug 29, 2007, at 1:55 PM, Jason Koelker wrote:

 I am attempting to use SQLAlchemy's table reflection to access a MSSQL
 2k database.  However the user I can connect with only had
 db_datareader access.  When SQLAlchemy tries to load the schema, it
 attempts a rollback at the end, which the user does not have
 permission to execute:


 Is there any way to use reflection with a read only connection?


ive never heard of a DB connection where the user doesnt have  
ROLLBACK permission (considering any transaction is local to that  
user anyway !?).  theres no write operations occuring during a  
reflection otherwise.

While i'll accept tickets/patches to get a dont_issue_rollbacks  
create_engine() flag going, most expedient in your case would be to  
allow your user at least the ability to issue a ROLLBACK.

--~--~-~--~~~---~--~~
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: Read only connection with Table reflection

2007-08-29 Thread Jason Koelker

On Aug 29, 7:27 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Aug 29, 2007, at 1:55 PM, Jason Koelker wrote:

  I am attempting to use SQLAlchemy's table reflection to access a MSSQL
  2k database.  However the user I can connect with only had
  db_datareader access.  When SQLAlchemy tries to load the schema, it
  attempts a rollback at the end, which the user does not have
  permission to execute:

  Is there any way to use reflection with a read only connection?

 ive never heard of a DB connection where the user doesnt have
 ROLLBACK permission (considering any transaction is local to that
 user anyway !?).  theres no write operations occuring during a
 reflection otherwise.


Chalk that up to my inability to administrate windows/mssql. ;)

 While i'll accept tickets/patches to get a dont_issue_rollbacks
 create_engine() flag going, most expedient in your case would be to
 allow your user at least the ability to issue a ROLLBACK.

Roger, I'll figure out how to give just that permissions to the user.

On a side note I did have to change the way SQLAlchemy was passing
the port to the pyodbc library for FreeTDS to be happy.  Instead of:

if 'port' in keys:
connectors.append('Server=%s,%d' % (keys.get('host'),
keys.get('port')))
else:
connectors.append('Server=%s' % keys.get('host'))

What worked for me is:

if 'port' in keys:
connectors.append('Port=%d' % keys.get('port'))
connectors.append('Server=%s' % keys.get('host'))

I looked on technet it looks like the comma syntax is an ado/windows
thing.

Happy Hacking!

7-11


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