[sqlalchemy] Re: SQL ALCHEMY instantly refresh

2009-09-18 Thread Christian Démolis
Hello,

Thx for the answer, thx to Alexandre to translate my mail.

Sorry, i continue in english, i tried to do that at the end of my
declaration file :

Base.metadata.create_all(engine)
import sqlalchemy.orm.query
class MyQuery(sqlalchemy.orm.query.Query):
def __init__(*arg, **kw):
   self._populate_existing = True
   super(MyQuery, self).__init__(*arg, **kw)
Session = scoped_session(sessionmaker(autocommit=True, bind=engine))
session = Session()
print Le temps de déclaration SQL ALCHEMY, time.time()-xref

Is it correct? i m not very good in subclassing :S
It seems to not work.
When i add a print in the __init__, i never see it during the execution of
my program so MyQuery is not used i think.
Can u tell me where should i subclass Query? In the declaration.py? in
module sqlalchemy?
I tried to add myquery here
Session = scoped_session(sessionmaker(autocommit=True, bind=engine,
query_cls=MyQuery))
but it does error
  File
C:\Python25\lib\site-packages\sqlalchemy-0.5.6-py2.5.egg\sqlalchemy\orm\
session.py, line 899, in query
return self._query_cls(entities, self, **kwargs)
  File Z:\Declaration.py, line 1451, in __init__
self._populate_existing = True
NameError: global name 'self' is not defined

I can t touch to the sqlalchemy module because the interpreter and libraries
are installed on multiple computers which execute one unique code on a
shared network path.
So it's more easy to change my source code than sqlalchemy code...

i just want to change session.query behavior without change the code of
sqlalchemy itself, please help me.

2009/9/17 Michael Bayer mike...@zzzcomputing.com


 Alexandre Conrad wrote:
 
  Christian,
 
  2009/9/17 Christian Démolis christiandemo...@gmail.com:
  Bonjour,
 
  Tu es français je pense au vu de ton prénom.
  Je continue donc en français.
 
  Nice guess.
 
  I understand it feels more comfortable writing in French rather than
  in English, but many people are reading this list (or is only Mike
  doing support? ;) ) and may be interested at the topic. And more eyes
  and brains may answer your question. So please keep conversations on
  this list to its native language - English. If you really want to
  switch to a non-English language with someone particular, please
  exchange off-list, but I believe you'll dramatically reduce your
  chances of solving your problem.
 
  So for the record, you were explaining that you have 25000 lines of
  code and you'd like to avoid to add refresh or
  session.query().populate_existing() all around the place. You have
  attempted to override the query method but couldn't make it. You have
  pointed out the PreFilteredQuery
  http://www.sqlalchemy.org/trac/wiki/UsageRecipes/PreFilteredQuery but
  was unsuccessful achieving what you wanted.
 
  Sorry, maybe someone else can help you there. I haven't played with
  Query overriding myself.

 a Query subclass which just says

 def __init__(*arg, **kw):
self._populate_existing = True
super(MyQuery, self).__init__(*arg, **kw)

 should do it





 
  Alex
 
  
 


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQL ALCHEMY instantly refresh

2009-09-18 Thread Alexandre Conrad

In Python, you have to pass self as first argument to all methods of a class:

class MyQuery(sqlalchemy.orm.query.Query):

def __init__(self, *arg, **kw):
...

Alex

2009/9/18 Christian Démolis christiandemo...@gmail.com:
 Hello,

 Thx for the answer, thx to Alexandre to translate my mail.

 Sorry, i continue in english, i tried to do that at the end of my
 declaration file :

 Base.metadata.create_all(engine)
 import sqlalchemy.orm.query
 class MyQuery(sqlalchemy.orm.query.Query):
     def __init__(*arg, **kw):
    self._populate_existing = True
    super(MyQuery, self).__init__(*arg, **kw)
 Session = scoped_session(sessionmaker(autocommit=True, bind=engine))
 session = Session()
 print Le temps de déclaration SQL ALCHEMY, time.time()-xref

 Is it correct? i m not very good in subclassing :S
 It seems to not work.
 When i add a print in the __init__, i never see it during the execution of
 my program so MyQuery is not used i think.
 Can u tell me where should i subclass Query? In the declaration.py? in
 module sqlalchemy?
 I tried to add myquery here
 Session = scoped_session(sessionmaker(autocommit=True, bind=engine,
 query_cls=MyQuery))
 but it does error
   File
 C:\Python25\lib\site-packages\sqlalchemy-0.5.6-py2.5.egg\sqlalchemy\orm\
 session.py, line 899, in query
     return self._query_cls(entities, self, **kwargs)
   File Z:\Declaration.py, line 1451, in __init__
     self._populate_existing = True
 NameError: global name 'self' is not defined

 I can t touch to the sqlalchemy module because the interpreter and libraries
 are installed on multiple computers which execute one unique code on a
 shared network path.
 So it's more easy to change my source code than sqlalchemy code...

 i just want to change session.query behavior without change the code of
 sqlalchemy itself, please help me.

 2009/9/17 Michael Bayer mike...@zzzcomputing.com

 Alexandre Conrad wrote:
 
  Christian,
 
  2009/9/17 Christian Démolis christiandemo...@gmail.com:
  Bonjour,
 
  Tu es français je pense au vu de ton prénom.
  Je continue donc en français.
 
  Nice guess.
 
  I understand it feels more comfortable writing in French rather than
  in English, but many people are reading this list (or is only Mike
  doing support? ;) ) and may be interested at the topic. And more eyes
  and brains may answer your question. So please keep conversations on
  this list to its native language - English. If you really want to
  switch to a non-English language with someone particular, please
  exchange off-list, but I believe you'll dramatically reduce your
  chances of solving your problem.
 
  So for the record, you were explaining that you have 25000 lines of
  code and you'd like to avoid to add refresh or
  session.query().populate_existing() all around the place. You have
  attempted to override the query method but couldn't make it. You have
  pointed out the PreFilteredQuery
  http://www.sqlalchemy.org/trac/wiki/UsageRecipes/PreFilteredQuery but
  was unsuccessful achieving what you wanted.
 
  Sorry, maybe someone else can help you there. I haven't played with
  Query overriding myself.

 a Query subclass which just says

 def __init__(*arg, **kw):
    self._populate_existing = True
    super(MyQuery, self).__init__(*arg, **kw)

 should do it





 
  Alex
 
  
 





 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQL ALCHEMY instantly refresh

2009-09-18 Thread Christian Démolis
^^

I m so shameful

It works very well now.

I post the subclass complete if anyone need it in future

Base.metadata.create_all(engine)
import sqlalchemy.orm.query

from sqlalchemy.orm.query import Query
class Query(Query):
def __init__(self, *arg, **kw):
   print I pass here
   self._populate_existing = True
   super(Query, self).__init__(*arg, **kw)

Session = scoped_session(sessionmaker(autocommit=True, bind=engine,
query_cls=Query))
session = Session()

The new query class must be passed to the session call.

thx for all

2009/9/18 Alexandre Conrad alexandre.con...@gmail.com


 In Python, you have to pass self as first argument to all methods of a
 class:

 class MyQuery(sqlalchemy.orm.query.Query):

 def __init__(self, *arg, **kw):
...

 Alex

 2009/9/18 Christian Démolis christiandemo...@gmail.com:
  Hello,
 
  Thx for the answer, thx to Alexandre to translate my mail.
 
  Sorry, i continue in english, i tried to do that at the end of my
  declaration file :
 
  Base.metadata.create_all(engine)
  import sqlalchemy.orm.query
  class MyQuery(sqlalchemy.orm.query.Query):
  def __init__(*arg, **kw):
 self._populate_existing = True
 super(MyQuery, self).__init__(*arg, **kw)
  Session = scoped_session(sessionmaker(autocommit=True, bind=engine))
  session = Session()
  print Le temps de déclaration SQL ALCHEMY, time.time()-xref
 
  Is it correct? i m not very good in subclassing :S
  It seems to not work.
  When i add a print in the __init__, i never see it during the execution
 of
  my program so MyQuery is not used i think.
  Can u tell me where should i subclass Query? In the declaration.py? in
  module sqlalchemy?
  I tried to add myquery here
  Session = scoped_session(sessionmaker(autocommit=True, bind=engine,
  query_cls=MyQuery))
  but it does error
File
  C:\Python25\lib\site-packages\sqlalchemy-0.5.6-py2.5.egg\sqlalchemy\orm\
  session.py, line 899, in query
  return self._query_cls(entities, self, **kwargs)
File Z:\Declaration.py, line 1451, in __init__
  self._populate_existing = True
  NameError: global name 'self' is not defined
 
  I can t touch to the sqlalchemy module because the interpreter and
 libraries
  are installed on multiple computers which execute one unique code on a
  shared network path.
  So it's more easy to change my source code than sqlalchemy code...
 
  i just want to change session.query behavior without change the code of
  sqlalchemy itself, please help me.
 
  2009/9/17 Michael Bayer mike...@zzzcomputing.com
 
  Alexandre Conrad wrote:
  
   Christian,
  
   2009/9/17 Christian Démolis christiandemo...@gmail.com:
   Bonjour,
  
   Tu es français je pense au vu de ton prénom.
   Je continue donc en français.
  
   Nice guess.
  
   I understand it feels more comfortable writing in French rather than
   in English, but many people are reading this list (or is only Mike
   doing support? ;) ) and may be interested at the topic. And more eyes
   and brains may answer your question. So please keep conversations on
   this list to its native language - English. If you really want to
   switch to a non-English language with someone particular, please
   exchange off-list, but I believe you'll dramatically reduce your
   chances of solving your problem.
  
   So for the record, you were explaining that you have 25000 lines of
   code and you'd like to avoid to add refresh or
   session.query().populate_existing() all around the place. You have
   attempted to override the query method but couldn't make it. You have
   pointed out the PreFilteredQuery
   http://www.sqlalchemy.org/trac/wiki/UsageRecipes/PreFilteredQuery but
   was unsuccessful achieving what you wanted.
  
   Sorry, maybe someone else can help you there. I haven't played with
   Query overriding myself.
 
  a Query subclass which just says
 
  def __init__(*arg, **kw):
 self._populate_existing = True
 super(MyQuery, self).__init__(*arg, **kw)
 
  should do it
 
 
 
 
 
  
   Alex
  
   
  
 
 
 
 
 
  
 

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Tables reflected in Postgresql + MySQL but not Oracle.

2009-09-18 Thread tomolds

Thanks for the help, I'm still having problems but I'm closer.

Okay so I have taken the following steps:

1) Installed 0.6 from trunk.
2) Added echo='debug' to create_engine()

When I add tables to the database I always specify them as
schem.table_name as you mention.

The SQL statement that SQLAlchemy generates is like this:

SELECT table_name FROM all_tables WHERE nvl(tablespace_name, 'no
tablespace') NOT IN ('SYSTEM', 'SYSAUX') AND OWNER = :owner
2009-09-18 11:23:46,596 INFO sqlalchemy.engine.base.Engine.0x...d60c
{'owner': 'SCHEM'}

This actually returns no results, therefore presents my problem.

However, when I run the following query on the database, I get the
desired tables:

SELECT table_name FROM all_tables WHERE owner = 'SCHEM';

How do you suppose I proceed?

Thanks,
Tom

On 18 Sep, 02:24, Michael Bayer mike...@zzzcomputing.com wrote:
 On Sep 17, 2009, at 11:20 AM, tomolds wrote:





  Hi,

  I have exactly the same schema in Postgresql, MySQL and Oracle.

  I am reflecting the tables in my application using: self.meta.reflect
  (bind=self.engine, schema='schem')

  This works perfectly for MySQL and Postgresql but for Oracle I get no
  tables reflected and cannot understand why. I can however run this
  kind of query and get results with Oracle:

         outp = text('select l_name from schem.person',
  bind=self.engine).execute()

         for i in outp:
             print i[0]

  Can anyone either suggest what my problem might be or perhaps even
  suggest a further test I can do to determine the problem.

 the first step would be to turn on echo='debug' on your create_engine
 ().   That will illustrate the queries SQLA is doing to locate the  
 table and the results it's getting back.

 I notice you're prefixing the table name with schem, so you'd have  
 to specify this as the schema argument when constructing the Table  
 object.

 Also for Oracle you should defnitely be on SQLA version 0.5.6 at the  
 very least.   the trunk (which is 0.6) also has full test coverage for  
 oracle.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Tables reflected in Postgresql + MySQL but not Oracle.

2009-09-18 Thread Mike Conley
Did you verify that the full query gives results?

SELECT table_name FROM all_tables
WHERE nvl(tablespace_name, 'no tablespace') NOT IN ('SYSTEM', 'SYSAUX')
AND owner = 'SCHEM';

I've been away from Oracle for a while, but I do remember it is unusual, but
still possible for user's tables to be in the SYSTEM or SYSAUX tablespaces.

Double check with

SELECT table_name, tablespace_name  FROM all_tables WHERE owner = 'SCHEM';

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Tables reflected in Postgresql + MySQL but not Oracle.

2009-09-18 Thread tomolds

Yes, I forgot to say about this.

The first query (the one that is conducted by SQLAlchemy) doesn't work
when run on the database.

The second query you provided, does work so it appears that my tables
are actually stored in the SYSTEM tablespace.

Do you know of a way around this?

On 18 Sep, 11:52, Mike Conley mconl...@gmail.com wrote:
 Did you verify that the full query gives results?

 SELECT table_name FROM all_tables
 WHERE nvl(tablespace_name, 'no tablespace') NOT IN ('SYSTEM', 'SYSAUX')
 AND owner = 'SCHEM';

 I've been away from Oracle for a while, but I do remember it is unusual, but
 still possible for user's tables to be in the SYSTEM or SYSAUX tablespaces.

 Double check with

 SELECT table_name, tablespace_name  FROM all_tables WHERE owner = 'SCHEM';
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Tables reflected in Postgresql + MySQL but not Oracle.

2009-09-18 Thread Mike Conley
What does the second query report for tablespace_name? SYSTEM?

If so, you need to talk to your DBA about why the default tablespace for
your owner is SYSTEM. Normally the system is configured to have user tables
go somewhere else.



From the SQLAlchemy side, the maintainers of databases/oracle.py might
consider removing SYSTEM, SYSAUX condition from the table_names query when
schema is provided. I'm not sure of side effects, but should be OK, because
table list will still be filtered by schema name.

You could experiment with this yourself to see if that is the issue and
submit a ticket

A crude experiment (no guarantees, this might break everything) is to do
this early in your script, some time before creating engine and reflecting
the tables.

import sqlalchemy.databases.oracle

def my_table_names(self, connection, schema):# a modified version of
OracleDialect.table_names()
# note that table_names() isnt loading DBLINKed or synonym'ed tables
if schema is None:
s = select table_name from all_tables where
nvl(tablespace_name, 'no tablespace') NOT IN ('SYSTEM', 'SYSAUX')
cursor = connection.execute(s)
else:
# remove SYSTEM, SYSAUX tablespace filter from original query
s = select table_name from all_tables where OWNER = :owner  #
removed SYSTEM tablespace filter
cursor = connection.execute(s, {'owner':
self._denormalize_name(schema)})
return [self._normalize_name(row[0]) for row in cursor]

sqlalchemy.databases.oracle.OracleDialect.table_name = my_table_names

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Tables reflected in Postgresql + MySQL but not Oracle.

2009-09-18 Thread tomolds

Okay it is clear that this is a tablespaces issue. I should have
spotted it earlier. I'm sure all my problems will be resolved once I
just change the tablespaces to something other than system or sysaux
and get the default tablespace for the user changed.

Thanks for the assistance.

On 18 Sep, 13:02, Mike Conley mconl...@gmail.com wrote:
 What does the second query report for tablespace_name? SYSTEM?

 If so, you need to talk to your DBA about why the default tablespace for
 your owner is SYSTEM. Normally the system is configured to have user tables
 go somewhere else.

 From the SQLAlchemy side, the maintainers of databases/oracle.py might
 consider removing SYSTEM, SYSAUX condition from the table_names query when
 schema is provided. I'm not sure of side effects, but should be OK, because
 table list will still be filtered by schema name.

 You could experiment with this yourself to see if that is the issue and
 submit a ticket

 A crude experiment (no guarantees, this might break everything) is to do
 this early in your script, some time before creating engine and reflecting
 the tables.

 import sqlalchemy.databases.oracle

 def my_table_names(self, connection, schema):    # a modified version of
 OracleDialect.table_names()
         # note that table_names() isnt loading DBLINKed or synonym'ed tables
         if schema is None:
             s = select table_name from all_tables where
 nvl(tablespace_name, 'no tablespace') NOT IN ('SYSTEM', 'SYSAUX')
             cursor = connection.execute(s)
         else:
             # remove SYSTEM, SYSAUX tablespace filter from original query
             s = select table_name from all_tables where OWNER = :owner  #
 removed SYSTEM tablespace filter
             cursor = connection.execute(s, {'owner':
 self._denormalize_name(schema)})
         return [self._normalize_name(row[0]) for row in cursor]

 sqlalchemy.databases.oracle.OracleDialect.table_name = my_table_names
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] SQLAlchemy and logging

2009-09-18 Thread Vinay Sajip

Hi,

I've just been discussing Python's logging package with Armin Ronacher
of Pocoo over on stdlib-sig:

http://mail.python.org/pipermail/stdlib-sig/2009-September/000671.html

In that post, Armin says that the SQLAlchemy development team had a
lot of problems with Python logging and had to do an Incredible
dance relating to loggers for temporary database connections.

I like dancing as much as the next guy, and the more incredible the
better, but *unnecessary* incredible dancing is a different thing
altogether ;-)

Seriously, as the author of the logging package, I'm sorry if you've
had any problems with logging, and I'm reasonably responsive to issues
raised on Python's bug tracker. I don't recall seeing anything from
the SQLAlchemy developers,but I could have missed it.

Can someone enlighten me as to the specifics of these problems, and
what I can do to help?

Thanks and regards,

Vinay Sajip

P.S. I think SQLAlchemy is great!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Oracle sequences

2009-09-18 Thread Kaukas

Hello.

Should this be considered a bug?

 import sqlalchemy
 seq = sqlalchemy.Sequence('test_sequence', start=20)
 seq.create(my_oracle_engine)
 seq.execute(my_oracle_engine)
1

Thank you!

Linas

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQLAlchemy and logging

2009-09-18 Thread Michael Bayer

Vinay Sajip wrote:

 Hi,

 I've just been discussing Python's logging package with Armin Ronacher
 of Pocoo over on stdlib-sig:

 http://mail.python.org/pipermail/stdlib-sig/2009-September/000671.html

 In that post, Armin says that the SQLAlchemy development team had a
 lot of problems with Python logging and had to do an Incredible
 dance relating to loggers for temporary database connections.

hmmm OK I think what he may be referring to is that we have this flag
called echo which works like this:

engine = create_engine(url, echo=True)

what echo does is a shortcut to setting up logging and enabling INFO
logging for the logger named sqlalchemy.engine.   In order to ensure
output, it does a basicConfig() to standard out.

What happens though, particularly when people use Pylons or similar, is
that they have a logging configuration in their conf file, which already
sets up handlers for logging.  then they'd like to use the echo flag for
debugging, but it ends up setting up a second handler, so in the case of
already logging to stdout you get double log messages.

It would be nice if there were some APIish way we could check that
handlers have already been configured, so that the echo flag wouldn't do
a second handler configuration.


 Seriously, as the author of the logging package, I'm sorry if you've
 had any problems with logging, and I'm reasonably responsive to issues
 raised on Python's bug tracker. I don't recall seeing anything from
 the SQLAlchemy developers,but I could have missed it.

the echo issue is not really a big deal.  the other issue we have is one
I'm not sure much can be done about.  We have logging calls which we would
like to make within extremely performance critical sections, like when
fetching results.  However if you look at our source code we jump through
hoops to avoid an unnecessary method call, like:

if self._should_log_debug:
self.log_debug(...)

otherwise the log_debug() would result in about three method calls per row
even when logging is disabled.   A bad side effect of this is that in many
cases _should_log_debug is determined when an engine or session is first
created (based on logging.isDebugEnabled() etc.) - so an application has
to take care to set up their logging config before the rest of their
SQLAlchemy objects are generated.

Those are pretty much the only two things we have, thanks for the interest !

 P.S. I think SQLAlchemy is great!

thanks !



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Oracle sequences

2009-09-18 Thread Michael Bayer

Kaukas wrote:

 Hello.

 Should this be considered a bug?

 import sqlalchemy
 seq = sqlalchemy.Sequence('test_sequence', start=20)
 seq.create(my_oracle_engine)
 seq.execute(my_oracle_engine)
 1

 Thank you!

 Linas

I would say its a pending enhancement but since the start parameter is
accepted sure its a bug :).   I thought there was a ticket for this one in
trac but it seems not.  I've added #1545.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQLAlchemy and logging

2009-09-18 Thread Vinay Sajip

On Sep 18, 3:49 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Vinay Sajip wrote:

 hmmm OK I think what he may be referring to is that we have this flag
 called echo which works like this:

 engine = create_engine(url, echo=True)

 what echo does is a shortcut to setting up logging and enabling INFO
 logging for the logger named sqlalchemy.engine.   In order to ensure
 output, it does a basicConfig() to standard out.

 What happens though, particularly when people use Pylons or similar, is
 that they have a logging configuration in their conf file, which already
 sets up handlers for logging.  then they'd like to use the echo flag for
 debugging, but it ends up setting up a second handler, so in the case of
 already logging to stdout you get double log messages.

 It would be nice if there were some APIish way we could check that
 handlers have already been configured, so that the echo flag wouldn't do
 a second handler configuration.

If you are literally calling basicConfig, that checks for handlers
added to the root logger (as it's intended to configure the root
logger for casual/novice usage, though of course anyone can use it).
If the root logger already has loggers configured, then it doesn't do
anything. If you're using basicConfig(), then it's probably just an
ordering problem - your code gets called first, configures the root
logger, then Pylons or other framework adds another handler
explicitly. This can perhaps be handled by documentation, as it's
(IMO) mainly an interaction between SQLA and the other framework. I'll
take a peek at SQLA code sometime soon and make suggestions if I think
any changes are needed, if that's OK.


 the echo issue is not really a big deal.  the other issue we have is one
 I'm not sure much can be done about.  We have logging calls which we would
 like to make within extremely performance critical sections, like when
 fetching results.  However if you look at our source code we jump through
 hoops to avoid an unnecessary method call, like:

 if self._should_log_debug:
     self.log_debug(...)

 otherwise the log_debug() would result in about three method calls per row
 even when logging is disabled.   A bad side effect of this is that in many
 cases _should_log_debug is determined when an engine or session is first
 created (based on logging.isDebugEnabled() etc.) - so an application has
 to take care to set up their logging config before the rest of their
 SQLAlchemy objects are generated.


Okay, let me think about that for a bit, and look at your source to
see exactly what those methods do.

 Those are pretty much the only two things we have, thanks for the interest !


So - Armin's statement

SQLAlchemy for example does an incredible dance to get separate
loggers for temporary database connections.

doesn't ring any bells?

Also - do you have any performance numbers or even rough metrics as to
the overhead from logging in your tight loops?

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



[sqlalchemy] Re: OrderingList with a secondary table

2009-09-18 Thread Ritesh Nadhani

Hi

I am looking for something similar.

Any chance you can post an example?

On Mon, May 25, 2009 at 5:13 AM, Christophe de VIENNE
cdevie...@gmail.com wrote:
 Hi again,

 Sorry for answering my own message, but it seems that I found the solution.
 I will be using a combination of orderinglist and AssociativeProxy.

 Thanks,

 Christophe


 2009/5/25 Christophe de VIENNE cdevie...@gmail.com

 Hi,

 I tried to use the orderinglist collection on a (many-to-many) relation
 with secondary table, having the position field on the secondary table.
 It does not work because the collection expect the ordering field to be on
 the target object, not on the secondary table.

 Is there a standard way to obtain this behavior ?

 Thanks,

 Christophe


 




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



[sqlalchemy] checking a relationship exists

2009-09-18 Thread joeformd

Is there a simple way in SQLA to check if a relationship exists
between two rows in a many-to-many situation, where the relationship
is defined using another table?

eg. the join table might look like this:

user_towns = Table('user_towns', Base.metadata,
Column('user_id', Integer, ForeignKey('users.id')),
Column('town_id', Integer, ForeignKey('towns.id'))
)

to check if a relationship exists, the SQL would be fairly simple,
with no joins required (is there a row in this table where user.id =
user_id and town.id = town_id)

Is there a simple way of asking this using SQLA, with the query
syntax?

thanks for your time
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Strange LIKE behavior with TypeDecorator

2009-09-18 Thread Mike Orr

I have the following TypeDecorator type to store a tuple of strings as
a delimited string.  It works fine but I discovered an abnormality
with LIKE.  The right side of a like expression is being passed to the
converter, so it has to be a one-item tuple instead of a string.  This
makes my model unintuitive.  Am I doing something wrong or is this
just a corollary of how TypeDecorator works?


 m.Chemical.synonyms.like((like,)) # Ugly

 q = q.filter(m.UN.synonyms.like((% + term + %,))) # Ugly


class MultiText(sa.types.TypeDecorator):
Store a tuple of string values as a single delimited string.

Legal values are a tuple of strings, or ``None`` for NULL.
Lists are not allowed because SQLAlchemy can't recognize in-place
modifications.

Note that during SQL queries (e.g., column LIKE %ABC%), the
comparision is against the delimited string.  This may cause unexpected
results if the control value contains the delimeter as a substring.


impl = sa.types.Text

def __init__(self, delimiter, *args, **kw):
Constructor.

The first positional arg is the delimiter, and is required.

All other positional and keyword args are passed to the underlying
column type.

if not isinstance(delimiter, basestring):
msg = arg ``delimiter`` must be string, not %r
raise TypeError(msg % delimiter)
self.delimiter = delimiter
sa.types.TypeDecorator.__init__(self, *args, **kw)

def process_bind_param(self, value, dialect):
Convert a tuple of strings to a single delimited string.

Exceptions:
``TypeError`` if the value is neither a tuple nor ``None``.
``TypeError`` if any element is not a string.
``ValueError`` if any element contains the delimeter as a substring.

if value is None:
return None
if not isinstance(value, tuple):
msg = %s value must be a tuple, not %r
tup = self.__class__.__name__, value
raise TypeError(msg % tup)
for i, element in enumerate(value):
if self.delimiter in element:
msg = delimiter %r found in index %d of %s: %r
tup = (self.delimiter, i, self.__class__.__name, value)
raise ValueError(msg % tup)
return self.delimiter.join(value)

def process_result_value(self, value, dialect):
Convert a delimited string to a tuple of strings.
if value is None:
return None
elif value == :
return ()
elements = value.split(self.delimiter)
return tuple(elements)

def copy(self):
return self.__class__(self.delimiter, self.impl.length)




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



[sqlalchemy] Re: checking a relationship exists

2009-09-18 Thread Michael Bayer


On Sep 18, 2009, at 7:44 PM, joeformd wrote:


 Is there a simple way in SQLA to check if a relationship exists
 between two rows in a many-to-many situation, where the relationship
 is defined using another table?

 eg. the join table might look like this:

 user_towns = Table('user_towns', Base.metadata,
Column('user_id', Integer, ForeignKey('users.id')),
Column('town_id', Integer, ForeignKey('towns.id'))
 )

 to check if a relationship exists, the SQL would be fairly simple,
 with no joins required (is there a row in this table where user.id =
 user_id and town.id = town_id)

 Is there a simple way of asking this using SQLA, with the query
 syntax?

the simplest would be query(User.id).join(User.towns).filter 
(User.id==uid).filter(Town.id==tid). 
  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Strange LIKE behavior with TypeDecorator

2009-09-18 Thread Michael Bayer


On Sep 18, 2009, at 7:47 PM, Mike Orr wrote:


 I have the following TypeDecorator type to store a tuple of strings as
 a delimited string.  It works fine but I discovered an abnormality
 with LIKE.  The right side of a like expression is being passed to the
 converter, so it has to be a one-item tuple instead of a string.  This
 makes my model unintuitive.  Am I doing something wrong or is this
 just a corollary of how TypeDecorator works?

the purpose of process_bind_param() is to marshal data from a  
particular in-python format into a format that is understood by the  
database.It seems here that you'd like it in some situations to  
allow the database-understood format to pass right through, and that  
maybe you're using it more as a validator specific to INSERT/UPDATE  
statements and not SELECT.

The two ways around it would be to allow your process_bind_param() to  
accept strings, or to place your validation at a level that does  
distinguish between CRUD and SELECT - validation with the ORM is  
easiest by using the @validates decorator, for example.

There's a ticket out there which would add some extra capabilities to  
types, allowing them to be consulted to generate SQL expressions for  
example.   Maybe additional info about the statement could be passed  
to the bind/result methods (i.e. the ExecutionContext).




 m.Chemical.synonyms.like((like,)) # Ugly

 q = q.filter(m.UN.synonyms.like((% + term + %,))) # Ugly


 class MultiText(sa.types.TypeDecorator):
Store a tuple of string values as a single delimited string.

Legal values are a tuple of strings, or ``None`` for NULL.
Lists are not allowed because SQLAlchemy can't recognize in-place
modifications.

Note that during SQL queries (e.g., column LIKE %ABC%), the
comparision is against the delimited string.  This may cause  
 unexpected
results if the control value contains the delimeter as a substring.


impl = sa.types.Text

def __init__(self, delimiter, *args, **kw):
Constructor.

The first positional arg is the delimiter, and is required.

All other positional and keyword args are passed to the  
 underlying
column type.

if not isinstance(delimiter, basestring):
msg = arg ``delimiter`` must be string, not %r
raise TypeError(msg % delimiter)
self.delimiter = delimiter
sa.types.TypeDecorator.__init__(self, *args, **kw)

def process_bind_param(self, value, dialect):
Convert a tuple of strings to a single delimited string.

Exceptions:
``TypeError`` if the value is neither a tuple nor ``None``.
``TypeError`` if any element is not a string.
``ValueError`` if any element contains the delimeter as a  
 substring.

if value is None:
return None
if not isinstance(value, tuple):
msg = %s value must be a tuple, not %r
tup = self.__class__.__name__, value
raise TypeError(msg % tup)
for i, element in enumerate(value):
if self.delimiter in element:
msg = delimiter %r found in index %d of %s: %r
tup = (self.delimiter, i, self.__class__.__name, value)
raise ValueError(msg % tup)
return self.delimiter.join(value)

def process_result_value(self, value, dialect):
Convert a delimited string to a tuple of strings.
if value is None:
return None
elif value == :
return ()
elements = value.split(self.delimiter)
return tuple(elements)

def copy(self):
return self.__class__(self.delimiter, self.impl.length)




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