wobsta | 4 Jul 08:17

ordering list: list order not updated on delete (orm)


Hi,

in my following example I don't know how to properly delete items in
an ordered list. I can't call items.remove (as I would violate the
"items must be in a list rule"). If I delete the item, the list order
get's not updated. Is there a way to automate the necessary reorder
call for this case? Additinally, what is the proposed way to reorder
an ordered list such that the positions are updated automatically?

Best,

André

PS: I'm running SQLAlchemy 0.5.4p2 on Python 2.6. The program first
prints  <Item item2 part of <List list> at position 2>, which is
wrong, and after the explicit reorder call it prints the correct <Item
item2 part of <List list> at position 1>.

-------------------------------------------

# -*- encoding: utf-8 -*-

from sqlalchemy import create_engine, MetaData, Table, Column,
Integer, Unicode, ForeignKey, UniqueConstraint
from sqlalchemy.orm import sessionmaker, mapper, relation
from sqlalchemy.ext.orderinglist import ordering_list

metadata = MetaData()

(Continue reading)

cd34 | 4 Jul 03:36

Overload session to add a filter to every query


I'm trying to overload session for an application so that I can add a
filter to every query without having to manually enter it.  I
understand that session is a method, but, I haven't quite figured out
what is required to add my filter.

I have the following:

engine = create_engine('mysql://user:password <at> localhost/database')
session = sessionmaker(bind=engine)
DBSession = session()

class clientSession(session):
    def query(self, *entities, **kwargs):
        #self._query_cls.filter('clients.client_id==1')
        return self._query_cls(entities, self, **kwargs)

clients = cs.query(clients).limit(5).all()
print clients

What I would like to accomplish is have a class that I can call that
always issues .filter('clients.client_id==value') on a query and
update.

I've searched google at length, but, haven't stumbled across the
solution and am hoping someone can at least point me in the right
direction.

Thanks.

(Continue reading)

Brad Wells | 3 Jul 01:21

0.4 to 0.5 upgrade and 'One-to-many relation fails with "unsaved, pending instance and is an orphan"' error


In the process of upgrading from 0.4 to 0.5 I've come across a
troubling issue. With the following setup:

####################################################################################

from sqlalchemy import Table, Column, Integer, String, MetaData,
create_engine, ForeignKey
from sqlalchemy.orm import relation, sessionmaker, scoped_session

engine = create_engine('sqlite:///mystuff.sqlite', echo=True)

Session = scoped_session(sessionmaker(autoflush=True,
transactional=True, bind=engine))
metadata = MetaData()
mapper = Session.mapper

time_zones = Table('time_zones', metadata,
                 Column('id', Integer, primary_key=True),
                 Column('name', String(35)))

contacts = Table('contacts', metadata,
                 Column('id', Integer, primary_key=True),
                 Column('display_as', String(35)),
                 Column('time_zone_id', Integer, ForeignKey
('time_zones.id')))

phone_numbers = Table('phone_numbers', metadata,
                 Column('id', Integer, primary_key=True),
                 Column('number', String(35)),
(Continue reading)

Michael Bayer | 2 Jul 20:00

Re: Applying an aggregate function to a select of a union_all (expr lang)


OK your example doesn't really provide enough information as to what the
problem is, the exact SQL you want to issue can be generated using the a
format as follows, perhaps you can derive the information you need from
it:

from sqlalchemy import *
from sqlalchemy.sql import table, column

invgroups = table('invgroups',
    column('groupname'),
    column('groupid'),
    column('categoryid')
)

aa = table('aa', column('type_id'))

invtypes = table('invtypes',column('typeid'), column('groupid'))

s1 = select([
        func.count('*').label('cnt'),
        invgroups.c.groupname.label('name'),
        invgroups.c.groupid.label('id')
    ]).select_from(
        invgroups.join(invtypes, invgroups.c.groupid==invtypes.c.groupid).
            join(aa, aa.c.type_id==invtypes.c.typeid)
    ).group_by(
        invgroups.c.groupname, invgroups.c.groupid
    )

(Continue reading)

Lukasz Szybalski | 2 Jul 18:49

timestamp as int


Hello,
What is the equivalent of the following but in the integer version.

 Column('_last_updated', DateTime(True),
                                    default=func.current_timestamp(),
                                    onupdate=func.current_timestamp()),

 Column('_last_updated', Integer, default=int(time.time(), onupdate=func.???),

I see that project like trac uses the integer timestamps extensively.
Can it be used safely in any other project or there are some drawbacks
for it?

Thanks,
Lucas

--

-- 
Using rsync. How to setup rsyncd.
http://lucasmanual.com/mywiki/rsync
DataHub - create a package that gets, parses, loads, visualizes data
http://lucasmanual.com/mywiki/DataHub

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

Wayne Witzel | 2 Jul 15:28

Applying an aggregate function to a select of a union_all (expr lang)


I have a pair of selects that I am using with union_all and I'd like
to have better control of aliasing so I can use sum on the column in
the outer select that is made up of the count() and literal columns
from the unioned selects.

s1 = select([count(), id, name], cat_id == 6, [join(item_tbl, aa_tbl,
Item.id == AA.item_id).join(grp_tbl, Group.id == Item.group_id)],
group_by=[Group.name, Group.id])
s2 = select([literal(0), id, name], cat_id == 6, group_by=[Group.name,
Group.id]

u1 = union_all(s1, s2).alias('group_with_zero').select(group_by=
['name','id'])

When I execute u1 I get the expect error that count _1 needs to be
part of the group by or used in an aggregate. Ideally I'd like the
outer select to be performing a sum() on that column. But I'm drawing
a blank in figuring out how to control the aliasing explicitly so I
can make that happen.

Am I going about this backwards or missing the obvious?

Thanks,

Wayne

Here is the SQL I hand crafted before I started building the expr
repr.

(Continue reading)

Carl | 1 Jul 04:12

Error during metadata reflect()


Hi,
Can anyone tell me what's I'm doing worng. The DB itself is fine I
access it via SA successfully from my web app (TG2). But, I need to
write a utility that uses it outside of the web app.

Here is my code:

>>> db = 'sqlite:///data/test.db'
>>> e = create_engine(db)
>>> m = MetaData(bind=e)
>>> m.reflect()

Here is what I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nine/server/tg2env/SQLAlchemy-0.5.1-py2.5.egg/sqlalchemy/
schema.py", line 1702, in reflect
    Table(name, self, **reflect_opts)
  File "/home/nine/server/tg2env/SQLAlchemy-0.5.1-py2.5.egg/sqlalchemy/
schema.py", line 113, in __call__
    return type.__call__(self, name, metadata, *args, **kwargs)
  File "/home/nine/server/tg2env/SQLAlchemy-0.5.1-py2.5.egg/sqlalchemy/
schema.py", line 241, in __init__
    _bind_or_error(metadata).reflecttable(self,
include_columns=include_columns)
  File "/home/nine/server/tg2env/SQLAlchemy-0.5.1-py2.5.egg/sqlalchemy/
engine/base.py", line 1265, in reflecttable
    self.dialect.reflecttable(conn, table, include_columns)
(Continue reading)

allen.fowler | 30 Jun 23:37
Favicon

Re: SQLAlchemy as a FIFO buffer?


> I've attached a proof of concept for how I've approached the "homegrown"
> version of this in the past.   a jobs table has two update passes - one to
> atomically mark jobs as "in progress" by a certain procid, then the
> transaction is released so that other processes can theoretically work on
> other jobs.  after each job is completed the corresponding row is marked
> as "complete" (or failed) within a separate short transaction per row.  
> no long running transactions are used so that there is always room for
> multiple processes to join in the work.   Oftentimes you'll hear people
> doing this with MySQL and dealing with "select...for update" to try to
> lock the rows as they are selected within the transaction but that method
> has never appealed to me.
>
> all that said, I'm sure my approach has issues that are not (or perhaps
> are) readily apparent.   if you want really failproof behavior without
> much tinkering the off the shelf solutions are probably worth a look.
>

Thank you.. I am looking at the code now.  Having not done any
threading or post "orm tutorial" SQL Alchemy programming, I am not
sure what it all does.

Quick questions:
How doe this code handle transactions?
Where in the code does it atomically assign a task to a worker without
making a race condition?   (Or does it?)

Thank you,
:)
--~--~---------~--~----~------------~-------~--~----~
(Continue reading)

allen.fowler | 30 Jun 23:30
Favicon

Re: SQLAlchemy as a FIFO buffer?


On Jun 30, 11:25 am, Didip Kerabat <did...@gmail.com> wrote:
> If you are open to non RDBMS solution, sounds like what you need is message
> queue system.
>
> At work, we use RabbitMQ (memory-only) and have been quite happy with it.
>
> SecondLife posted their discovery about MQ here:http://wiki.secondlife.com/wiki/Message_Queue_Evaluation_Notes
>

RabbitMQ looks very nice.  However, one of the requirements is to be
able run with out any additional resident daemons.   All system
actions are triggered by cron, CGI, and locally SSH executed scripts.

RabbitMQ may make it in to future experiments.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Arthur Pemberton | 30 Jun 20:35

Dumping select data to SQL with relationships


Good day,

I'd like to know if there is a quick way to do the following:
 1) reflect an existing database (I know SA does this well)
 2) SELECT a few entries of a main table Foo, preserving all
relationships
 3) generate INSERT statements to create the selected Foo entries and
their relationships (in the same SQL dialect that they were read)

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

Vishakh | 30 Jun 06:05

Quoting Issue with Sybase ASE


Hello,

I am modifying Alexander Houben's Sybase module in order to get
SQLAlchemy working with Sybase Adaptive Server Enteprise. I am using
Python 2.6, Pylons and Sybase OCS 12.5, with both mxODBC and pyodbc.
So far, I have had some success with reflecting tables and issuing
basic queries. However, when I filter my queries, integer values are
quoted and this causes an error with Sybase since it doesn't support
implicit conversions from varchar to int. Could you please tell me
what change I would have to make in order to not quote integer values
in my modified module?

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


Gmane