Jason Yamada-Hanff | 6 Sep 19:21

Selectable mapping fails in polymorphic schema?


Below is a simplified case of a problem (bug?) I am running into.  I
have a polymorphic schema using joined-table inheritance.  In my OO
layer, a Group is an Agent, and a Lab is a Group.  In the DB layer,
Lab doesn't actually need to hold any extra information so it doesn't
need a separate table.

Instead, I would like to map the Lab object to the 'groups' table and
select only those types that are identified as a lab by the 'type'
discriminator column in 'agents' table.  I want,t hen, to map Lab to a
selectable.  However, when I try to create and flush a Lab instance
with the setup below, it is obvious that the attributes that should
map into the groups table aren't getting collected into the INSERT
statement correctly.

If I change `lab_select` to the simple join without the select
statement, the Lab instance is persisted correctly.  Of course, this
does nothing for the need to filter out non-lab entries.  Similarly,
if I create a useless extra table called `labs` and map to that
instead, the INSERT works

Any ideas on how to adjust the `lab_select` statement below so that
this works?

Thanks!
-Jason

----

import sqlalchemy as sa
(Continue reading)

gatto | 5 Sep 21:18

Too many connections


hi everyone.  just started using sqlalchemy and elixir recently.  i'm
not having any issues with coding yet, just this one:

OperationalError: (OperationalError) (1040, 'Too many connections')

as a workaround for this problem, i created a cron job to restart
apache once every hour and that is mostly working.  but i really need
to find out what is causing this.  i'm using a custom built mvc
framework that runs atop mod_python, and in the base application class
i have the following code, which executes once at the beginning of the
request:

	metadata.bind = 'mysql://' + app_config.database.user + ':' +
app_config.database.password + '@' + app_config.database.host + ':
3306/' + app_config.database.schema
	metadata.bind.echo = True
	metadata.bind.recycle = 3600

i had thought setting recycle to 3600 in this way would cause the
connections to be reused every 5 minutes if they had remained open.
we're only getting a couple hundred unique visitors per day currently
so i'm surprised that the error happens so quickly.  how can i figure
this out?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlalchemy <at> googlegroups.com
To unsubscribe from this group, send email to sqlalchemy+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
(Continue reading)

Alex K | 5 Sep 19:48

Sqlalchemy + modwsgi: get "Invalid column expression"


Hi All,

I'm using sqlalchemy and mod_wsgi. mod_wsgi is set up to serve request
in multiple threads of the same process.

class looks like that:

class WebSessionRoute(DeclarativeBase):

    __tablename__ = 'web_session_route'

    key = Column('key', Unicode(40), primary_key=True)
    user_id = Column('user_id',Integer, ForeignKey('user_route.id')),
    expires = Column('expires', DateTime)

    def __init__(self,key,user_id,expires):
        self.key = key
        self.user_id = user_id
        self.expires = expires

I'm facing the following issue. The first request goes fine, but on
the second attempt I get:

query.py, line 1620, in __init__
    raise sa_exc.InvalidRequestError("Invalid column expression '%r'"
% column)

on any attempt to execute any query. Instrumented attributes are in
place, but they don't work.
(Continue reading)

Randy Syring | 5 Sep 15:58

Looking for HTML table generator based on SQLAlchemy query


Has anyone written or seen something that would take an SQLAlchemy
query, any query, and turn the resulting recordset into an HTML
table?  Bonus points for providing a sort, filter, and paging feature.

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

guge | 5 Sep 02:44

When the database is to support sql 2005 ?


When the database is to support sql 2005

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

Sam | 5 Sep 01:15

Inserts using reflection...


I woke up today and decided it was time to switch one of my simpler
programs from sqlobject to sqlalchemy.

I'm using reflection.   After some googling I was able to find a way
to insert:
mp = mphones.insert().execute(word=word, mphone=phone)

The above works okay.

But I'd rather be able to do something like this:
mp = mphones(word=word, mphone=phone)
sess.add(mp)

Unfortunately I couldn't make that work.

Here's the setup code I'm using:
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker

engine = create_engine("postgres://postgres:[redacted]/mydb")
meta = MetaData()
meta.bind = engine

Session = sessionmaker(bind=engine)
sess = Session()

mphones = Table('mphones', meta, autoload=True)

This is sqlalchemy 0.5 beta 3.
(Continue reading)

desmaj | 5 Sep 00:02

mssql unicode weirdness: empty nvarchar string is selected as u" "


I'm setting up my first project that will use SA exclusively for
database access and I've run into some behavior that seems odd to me.

If I insert u"" into a column that is defined as nvarchar then when I
select that column, I receive u" ". So I'm receiving a unicode string
containing one space where I would expect to find an empty unicode
string. Does this ring any bells for anyone?

I'm using:
SQLAlchemy 0.5.0beta3
pyodbc 2.0.58
FreeTDS 0.82

Here's a test case:

import
unittest
import
pyodbc
import sqlalchemy as
sa

class
TestMSSQLConnections(unittest.TestCase):

    def
setUp(self):

        self.host
(Continue reading)

Jon | 4 Sep 22:16

bug? order_by + get(some_id) results in InvalidRequestError


I'm using 0.4.6 but I thought I'd give 0.5b3 a try.

An existing (working) query failed with:

Query.__no_criterion() being called on a Query with existing
criterion.

I tracked that down to using order_by when building the query.
An example is below:

q = dbsess.query(Obj)
q = q.order_by(Obj.name)
instance = q.get(some_id)

Why does this happen and is it a bug?

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

Mike | 4 Sep 21:12

Translating a complex SQL Statement to SqlAlchemy


Hi,

I am trying to translate the following SQL into SqlAlchemy session
syntax:

sql = ''' SELECT SUM(reg), SUM(ot), SUM(ce), SUM(hol), SUM(sklv),
SUM(vac), SUM(ct), SUM(conv), SUM(misc)
            FROM tbl_TimeEntries
            WHERE dateworked > = '%s' AND dateworked <= '%s' AND empid
= %s
            ''' % (start_date, end_date, emp_id)

I found the "apply_sum" query method, but this seems to be able to
only be applied to one column at a time. I haven't found a way to use
equality operators (>= or <=) yet. According to the SqlAchemy book by
Copeland, I should be able to use the equality operators with table
methods and the bitwise "&" operator. I prefer using sessions since
they seem easier to clean up in wxPython, but I'm pretty flexible.

Any hints are welcome. Thanks!

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

(Continue reading)

Comparing tuples


Is there a simple way of comparing tuples in the SQLAlchemy query
language, like (User.last_name, User.first_name) < ('Joe', 'Doe')?
SQL-wise it is possible (at least with PostgreSQL), but you cannot write
this as a filter expression.

-- Christoph

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

Re: Orphans not deleted using cascade parameter


and here is the new traceback ;-)

Traceback (most recent call last):
  File "foo.py", line 38, in <module>
    DBSession.flush()
  File "/Users/michael/programming/rumdemo3/lib/python2.5/site-
packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/scoping.py",
line 106, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "/Users/michael/programming/rumdemo3/lib/python2.5/site-
packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/session.py",
line 1409, in flush
    flush_context.execute()
  File "/Users/michael/programming/rumdemo3/lib/python2.5/site-
packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/
unitofwork.py", line 265, in execute
    UOWExecutor().execute(self, tasks)
  File "/Users/michael/programming/rumdemo3/lib/python2.5/site-
packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/
unitofwork.py", line 753, in execute
    self.execute_save_steps(trans, task)
  File "/Users/michael/programming/rumdemo3/lib/python2.5/site-
packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/
unitofwork.py", line 771, in execute_save_steps
    self.execute_dependencies(trans, task, True)
  File "/Users/michael/programming/rumdemo3/lib/python2.5/site-
packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/
unitofwork.py", line 783, in execute_dependencies
    self.execute_dependency(trans, dep, True)
(Continue reading)


Gmane