[sqlalchemy] Re: Session will not commit within a class

2009-08-05 Thread kportertx

UGGG!  I have been fighting with this for a while.  I never thought to
just use an actual file for my db instead of using memory.  I was
using memory because I was only wanting to test things and didn't want
to keep the data.  Seems that perhaps due to cherrypy the database was
being deleted.  I later moved the create_all() statement into the
index sub and found that it worked.  Following that when I loaded a
lot of info into the db and browsed to an outside website and back all
the data was gone.

My original code now works, all I had to do it use a db file instead
of a db in memory.  I'm glad I found a solution.  But the number of
times I read through sqlalchemy docs to find my problem just to
realize there really wasn't anything wrong all along is very
frustrating lol.

Thanks for the help.

Again I am new to SQLAlchemy so if you know any best practices or
have any suggestions in general for web development in python, please
shoot them my way.

V/R
Kevin
--~--~-~--~~~---~--~~
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: Alchemy + Firebird Generators

2009-08-05 Thread León

Yeah!
That's what I was looking for...and I didn't find. Actually I'm using
a declarative model thru declarative_base: every column in the table
is an attribute in the class, so I have a column very similar to the
one you wrote.

The problem was that I was looking for generator instead of
sequence in the SA documentation.

Thanks a lot.

León

On 4 ago, 16:49, Werner F. Bruhin wbru...@gmail.com wrote:
 León wrote:
  Hi,

  does anybody know how can I use the default param in the Column
  class to define a new value which comes from aFirebirdgenerator? I
  get the same thing with

  cod_objeto = self.conexion.execute('SELECT FIRST 1 NEXT VALUE FOR GEN_
  %d FROM RDB$DATABASE' % cod_clase).fetchone()[0]

  *self.conexion = Session()

  but I'd like something smarter.

 When defining your model (I use declarative) you can do this:
 sa.Column(u'id', sa.Integer(), sa.Sequence('gen_i18n_keys_id'),
 primary_key=True, nullable=False),

 Hope I understood your question correctly.

 Werner
--~--~-~--~~~---~--~~
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: Backref introspection

2009-08-05 Thread nail.xx

I just discovered answer for myself:

from sqlalchemy.orm.properties import RelationProperty
from sqlalchemy.orm import class_mapper

def foo(entity_class, collection_property):
rel_prop = class_mapper(entity_class, compile=False).get_property
(collection_property)
related_entity_class = rel_prop.backref.prop.parent.class_  #
equals to class Sea
backref_attr = rel_prop.backref.key  # equals to 'ocean'

Cool!


On Aug 4, 10:31 pm, nail.xx nail...@gmail.com wrote:
 Hi all!

 I have following model classes:

 Entity = sqlalchemy.ext.declarative.declarative_base(name='Entity')
 class Ocean(Entity):
     __tablename__ = 'oceans'
     id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
     name = sqlalchemy.Column(sqlalchemy.String(20), nullable=False)
 class Sea(Entity):
     __tablename__ = 'seas'
     id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
     name = sqlalchemy.Column(sqlalchemy.String(20), nullable=False)
     ocean_id = sqlalchemy.Column(sqlalchemy.String(20),
 sqlalchemy.ForeignKey(Ocean.id))
     ocean = sqlalchemy.orm.relation(Ocean, backref='seas')

 So instances of Ocean have seas property. The question is, if I have a
 function:

 def foo(entity_class, collection_property):
      # ...

 that is called width args entity_class=Ocean,
 collection_property='seas' could I anyhow to understand from within
 this function that 'seas' is assotiated with Sea class and that
 Sea.ocean is used to bind a Sea to the Ocean?

 Is it ever possible? 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: Session will not commit within a class

2009-08-05 Thread Gaetan de Menten

On Wed, Aug 5, 2009 at 08:16, kportertxkporte...@gmail.com wrote:

 O on a side note would you recommend elixir over declarative_base?

The biggest difference between the two is that Elixir can generate
some columns and tables for you (using common patterns). Michael
Bayer probably won't recommend Elixir since he wrote declarative and
he doesn't like much the generate stuff approach taken by Elixir.
Whether you like/want that feature or not should decide whether you go
with Elixir or declarative.

-- 
Gaëtan de Menten
http://openhex.org

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



[sqlalchemy] Re: Session will not commit within a class

2009-08-05 Thread Gaetan de Menten

On Wed, Aug 5, 2009 at 08:13, kportertxkporte...@gmail.com wrote:

 UGGG!  I have been fighting with this for a while.  I never thought to
 just use an actual file for my db instead of using memory.  I was
 using memory because I was only wanting to test things and didn't want
 to keep the data.  Seems that perhaps due to cherrypy the database was
 being deleted.  I later moved the create_all() statement into the
 index sub and found that it worked.  Following that when I loaded a
 lot of info into the db and browsed to an outside website and back all
 the data was gone.

In case you were wondering, the reason for all your troubles is
simple: cherrypy is multi-threaded. SQLite in-memory databases are
thread-local. If you call create_all in all your threads, you create
tables in all the different databases created by each thread. When you
later revisited your site, cherrypy served you the page through
another thread, hence another database, hence you saw no data.

-- 
Gaëtan de Menten
http://openhex.org

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

2009-08-05 Thread dusans

Netezza = data warehouse appliance server

1. yes its SQL
2. I can connect to it via pyodbc

ok will take a look at it :)

On Aug 4, 4:52 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 dusans wrote:

  Is there a possibility to connect to Netezza db server?

 to use SQLalchemy with a certain backend, you have to answer these questions:

 1. is it SQL ?

 2. is there a python DBAPI available ?

 yes to both, then a new dialect module can be constructed that interfaces
 with this database.  I'd advise looking into the 0.6 codebase for
 examples.
--~--~-~--~~~---~--~~
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] share objects with threads and scoped_session

2009-08-05 Thread drakkan

Hi all,

I'm trying to share an object with a thread, I already tryed to use
Session.merge but I'm doing something wrong,

here is a test case:

from sqlalchemy import
*
from sqlalchemy.orm import
*

e = create_engine('postgres://postgres:postg...@127.0.0.1/test',
echo=True)
m = MetaData(e)
t1 = Table('t1', m, Column('a', Integer, primary_key=True),
Column('b', Integer))

class A(object):
 def __init__(self, a, b):
 self.a = a
 self.b = b

mapper(A, t1)

m.create_all()

Session = scoped_session(sessionmaker())

Session.add(A(1, 1))
Session.commit()

import threading

def testthread(a):
a.a=2
Session.add(a)
Session.commit()


a = Session.query(A).get(1)
t=threading.Thread(target=testthread,args=(a,))
t.start()


and this is the generated expection:

Traceback (most recent call last):
  File /usr/lib/python2.6/threading.py, line 525, in
__bootstrap_inner
self.run()
  File /usr/lib/python2.6/threading.py, line 477, in run
self.__target(*self.__args, **self.__kwargs)
  File testthread.py, line 28, in testthread
Session.add(a)
 .
InvalidRequestError: Object 'A at 0x2dbf390' is already attached to
session '47955344' (this is '47969872')

what is the correct way to share object between different threads?

regards
drakkan
--~--~-~--~~~---~--~~
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: Netezza

2009-08-05 Thread dusans

a link to a example would be nice. tnx :)

On 4 avg., 16:52, Michael Bayer mike...@zzzcomputing.com wrote:
 dusans wrote:

  Is there a possibility to connect to Netezza db server?

 to use SQLalchemy with a certain backend, you have to answer these questions:

 1. is it SQL ?

 2. is there a python DBAPI available ?

 yes to both, then a new dialect module can be constructed that interfaces
 with this database.  I'd advise looking into the 0.6 codebase for
 examples.
--~--~-~--~~~---~--~~
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] missing parenthesis on generated query?

2009-08-05 Thread Wichert Akkerman

I have a fairly complex SQL query which looks like this:

sql.or_(
 sql.and_(model.SurveyTreeItem.type==module,
  model.SurveyTreeItem.skip_children==False,
 sql.exists().correlate(model.Risk.__table__).where(sql.and_(
  model.Risk.session_id==model.SurveyTreeItem.session_id,
  model.Risk.type==risk,
  model.Risk.inventory==no,
  model.Risk.depthmodel.SurveyTreeItem.depth,
  model.Risk.path.like(model.SurveyTreeItem.path+%,
 sql.and_(model.Risk.id==model.SurveyTreeItem.id,
  model.Risk.type==risk,
  model.Risk.inventory==no))

When printing the resulting clause list I get this:

tree.type = :type_1 AND tree.skip_children = :skip_children_1 AND 
(EXISTS (SELECT *
FROM tree
WHERE tree.session_id = tree.session_id AND tree.type = :type_2 AND 
risk.inventory = :inventory_1 AND tree.depth  tree.depth AND tree.path 
LIKE tree.path || :path_1)) OR tree.id = tree.id AND tree.type = :type_3 
AND risk.inventory = :inventory_2

 From what I can see this is not correct: there should be parenthesis to 
make sure the ANDs and ORs are grouped correctly. Does this look like a 
bug, or am I missing something?

Wichert.

-- 
Wichert Akkerman wich...@wiggy.net   It is simple to make things.
http://www.wiggy.net/  It is hard to make things simple.

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

2009-08-05 Thread dusans

a link to a example would be nice. tnx :)

what would be the simplest interface that only performes SELECT,
INSERT, UPDATE, DELETE (netezza uses standard sql for that...)
since i dont want to create tables with sqlalchemy... netezza has a
bit different syntax and more simple types

btw. netezza is a PostGres derivative for DataWarehousing



On 5 avg., 10:39, dusans dusan.smit...@gmail.com wrote:
 Netezza = data warehouse appliance server

 1. yes its SQL
 2. I can connect to it via pyodbc

 ok will take a look at it :)

 On Aug 4, 4:52 pm, Michael Bayer mike...@zzzcomputing.com wrote:



  dusans wrote:

   Is there a possibility to connect to Netezza db server?

  to use SQLalchemy with a certain backend, you have to answer these 
  questions:

  1. is it SQL ?

  2. is there a python DBAPI available ?

  yes to both, then a new dialect module can be constructed that interfaces
  with this database.  I'd advise looking into the 0.6 codebase for
  examples.
--~--~-~--~~~---~--~~
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: missing parenthesis on generated query?

2009-08-05 Thread Mike Conley
SQL precedence will evaluate the AND's before the OR's. So unless there is
an OR condition embedded within a series of AND's the parenthesis are not
needed. I do agree that using parenthesis can make the intent clearer, but
will not change the result.

The clauses
a AND b OR c
   (a AND b) OR c
are equivalent.

When a or b is a complex condition that also has OR then parenthesis are
probably needed.

In this case, it appears that the condition is an OR of two conditions that
consist entirely of AND conditions. If that is the case then parenthesis are
not required.

-- 
Mike Conley

--~--~-~--~~~---~--~~
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] GIS support for SQLAlchemy

2009-08-05 Thread Sanjiv Singh

Hi,

I have been working on supporting spatial data types and spatial
operations on SQLAlchemy as my summer of code project. The code is
available at http://bitbucket.org/sanjiv/geoalchemy/  and a demo TG2
app using it is at http://geo.turbogears.org/ .

I started out by following the postgis example included in sqlalchemy
package. Till now I have added support for PostGIS, MySQL and
Spatialite.

It would be nice to have some suggestions / criticisms before I make
the first release. I am quite sure the code needs a lot of
improvement.

regards
Sanjiv

--~--~-~--~~~---~--~~
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: Advice on modeling a many-to-many relationship

2009-08-05 Thread Hollister

That was exactly the conclusion I reached before I read your reply. I
modeled it that way and it seems to work perfectly. Guess I was just
overthinking it.

Thanks for getting back to me, Mike.

On Aug 3, 11:41 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Aug 3, 2009, at 5:21 PM, Hollister wrote:





  I have 2 tables which are related to each other through an M:N
  relationship (Keyword  Action). Additionally, the relationship itself
  has attributes, which I have as non-key attributes in a third table
  (KeywordAction). I've modeled this dozens of different ways, but have
  yet to get exactly what I want from the model.

  At the ORM level, I want Keyword to have a property that is a
  collection of KeywordAction instances. Each KeywordAction instance
  would have a single Action instance property, so I could do things
  like this:

  ---
  for ka in keyword.keyword_actions:
     if ka.status == 'open':
         ka.action.do_something()

  keyword.keyword_actions.append(KeywordAction(action, status = 'open'))
  ---

  I've tried using the association_proxy, but I get the feeling that's
  not the right tool for this job.

 the above example doesn't seem like it would need association proxy, a  
 simple collection of relation()s, i.e. Keyword.keyword_actions,  
 KeywordAction.action would do based on the navigation illustrated.
--~--~-~--~~~---~--~~
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: Hierarchical data: Get all (sub-) children? Parents?

2009-08-05 Thread allen.fowler



On Jul 28, 12:17 pm, David Gardner dgard...@creatureshop.com wrote:
 Just thought I would toss in my 2-cents here, since I have lots of
 hierarchical data and have
 at one time or another used most of the below methods.

 Choice #1 is the option that I have found that works the best.
 I Use a file path-like primary key (actually I am storing data about
 files), this allows me to easily do
 things like:
 nodes=session.query(Node).filter(Node.path.like('root/path/sub/%')).order_by(Node.path).all()

 Choice #3 works well with Choice #1, especially if you are interested in
 a particular node, and know ahead of time
 you also want that node's grandparent.



I've read up a bit on the suggested links.  Thank you for the leads.


If I am understanding this, it seems that choice #1 is very much like
the materialised path method as mentioned in:

http://sqlamp.angri.ru/  , and
http://www.dbazine.com/oracle/or-articles/tropashko4

I will experiment some and report back. (My max depth is about 10
levels with under 1000 total nodes.)


Thank you,
:)


--~--~-~--~~~---~--~~
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: share objects with threads and scoped_session

2009-08-05 Thread drakkan

Seems that once I defined a scoped session as:

Session = scoped_session(sessionmaker())

I can switch to a non scoped session simply calling:

sess=Session()

infact:

sess=Session
sess
sqlalchemy.orm.scoping.ScopedSession object at 0x1debbd0

sess=Session()
sess
sqlalchemy.orm.session.Session object at 0x2383050

is this the intended behaviuor?

thanks
drakkan

On 5 Ago, 11:27, drakkan drakkan1...@gmail.com wrote:
 Hi all,

 I'm trying to share an object with a thread, I already tryed to use
 Session.merge but I'm doing something wrong,

 here is a test case:

 from sqlalchemy import
 *
 from sqlalchemy.orm import
 *

 e = create_engine('postgres://postgres:postg...@127.0.0.1/test',
 echo=True)
 m = MetaData(e)
 t1 = Table('t1', m, Column('a', Integer, primary_key=True),
 Column('b', Integer))

 class A(object):
      def __init__(self, a, b):
          self.a = a
          self.b = b

 mapper(A, t1)

 m.create_all()

 Session = scoped_session(sessionmaker())

 Session.add(A(1, 1))
 Session.commit()

 import threading

 def testthread(a):
     a.a=2
     Session.add(a)
     Session.commit()

 a = Session.query(A).get(1)
 t=threading.Thread(target=testthread,args=(a,))
 t.start()

 and this is the generated expection:

 Traceback (most recent call last):
   File /usr/lib/python2.6/threading.py, line 525, in
 __bootstrap_inner
     self.run()
   File /usr/lib/python2.6/threading.py, line 477, in run
     self.__target(*self.__args, **self.__kwargs)
   File testthread.py, line 28, in testthread
     Session.add(a)
  .
 InvalidRequestError: Object 'A at 0x2dbf390' is already attached to
 session '47955344' (this is '47969872')

 what is the correct way to share object between different threads?

 regards
 drakkan
--~--~-~--~~~---~--~~
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] Suggestions for db connect string configuration?

2009-08-05 Thread AF

Hello,

Where do you folks recommend storing the database connection string in
my application.  Clearly not in the same file with my declaratively
defined model objects.

And more generally, how do you recommend laying out an SQLAlchemy
based application?  (In what files to define the engine, session,
other objects, etc..)

Sort of looking for best practices, I guess

Thank you,
:)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---