[sqlalchemy] Re: sqlalchemy migration/schema creation

2008-04-16 Thread az

a separate feature - no. 
but it's not much to do it. here my attempt at this.

try copyall or copydata+autoload from here:
http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/dbcook/misc/metadata/

svn co 
http://dbcook.svn.sourceforge.net/dbcook/trunk/dbcook/misc/metadata/

it's not dbcook/ dependent except some util.attr module 

usage:
$ python copyall.py srcdburl destdburl

we've used this to copy whole from sqlite to postgres to m$sql

ciao
svilen

 Hello,
 Is there maybe a feature in sqlalchemy that would allow me to
 autoload table from one database, and move it over to another
 database?

 1. I would like to print data structure from autoload table. (then
 copy and paste it into new file  and use it to create new
 table)(without typing every data structure)
 2. And/or autoload via one engine and autoupload via different
 engine and create_all()
 3. Analyze csv files and create sqlalchemy definition like
 structure.

 Ideas?

 Lucas

 

--~--~-~--~~~---~--~~
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] (auto-)flush issue

2008-04-16 Thread Lele Gaifax
Hi,

I spent a few hours investigating a strange but very simple problem:
by any chance I'm missing something obvious...

Elaborating on Paul's proc_hash, I now have a similar behaviour on
all my entities. It's not a very important feature, but it surely
makes it easier to introduce test data into the database.

It's a little bit different from Paul's goal, in that I wanna be able
to say, for example:

newobj = MyObject()
session.save(newobj)
newobj.updateFromDictionary(dict(
attribute1='simple attribute',
related_obj=dict(id=1, description='related obj'),
other_objs=[dict(id=1, index=1, ref=dict(description='new ref obj')),
dict(id=2, index=2, ref=dict(id=5))]
))
session.commit()

that is, being able to specify either new subobjects or existing
one: in the former case, using a dictionary containing (maybe) the PK
and other field value; in the latter, with a dictionary carrying just
the primary key of the record. In the example above, related_obj will
be assigned a new instance of the class involved by the relation,
while other_objs will contain two entities, both newly created, but
one is attached to a new instance while the other should reference an
existing record fetched by primary key (that ``ref=dict(id=5)``).

The function is working, but in that particular case it fails: in the
example above, whenever it reaches the second other_objs where the
ref is loaded with something like

ref = session.query(RefObj).get(5)

I can see that SA flushes all pending operation *before* issueing the
SELECT to load the RefObj: in particular it flushes the whole newobj
but at that point it contains an incomplete object and I get a
constraint violation on refid is NULL: that's obvious, since it
isn't assigned yet... but I miss the point! Why the query.get()
triggers the flush? Accordingly to the docs, it should not...

I tried using autoflush=False on the session, as well as with explicit
transactions, with no luck.

I'm attaching the function, should a kind soul shed some light on it: 
the method on my instances just call that function.

But I bet the problem is somewhere else, since I get the same trouble
if I manually do that in a single session like

refobj1 = RefObj(id=1, description=one)
session.save(refobj1)
refobj2 = RefObj(id=2, description=two)
session.save(refobj2)
...
cross = CrossObj(id=1, index=1)
cross.ref = session.query(RefObj).get(1)
newobj.other_objs.append(cross)

What am I missing?

Thanks in advance,
ciao, lele.
-- 
nickname: Lele Gaifax| Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas| comincerò ad aver paura di chi mi copia.
[EMAIL PROTECTED] | -- Fortunato Depero, 1929.

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

def updateFromDictionary(obj, data, mapper=None):
Update a mapped class with data from a Python nested hash/list structure.

The `data` dictionary may contain either single scalar attributes, like
``progressivo = 1``, single dictionary representing a related entity,
or lists of dictionaries for the one-to-many relations.

A single entity is represented by a single dictionary: if it contains just
the primary key, the entity is looked up in the database, otherwise a new
entity is forged and updated with the items in the dictionary.

Example::

iterp.updateFromDictionary(dict(
# A scalar value
descrizione=uEsempio di iter procedurale,
# A foreign key entity, looked up by primary key
contesto = dict(idcontesto=ANAG),
# A list of entities for a one-to-many relation: each entity
# in the list has a sub-entity, the first is created new as
# there is no primary key, while the second gets loaded from
# the database, looked up by its primary key.
fasiiterprocedurale = [dict(progressivo=1, fase=dict(descrizione=uFase estemporanea)),
   dict(progressivo=2, fase=dict(idfase=1))],
))


from sqlalchemy.exceptions import ArgumentError
from sqlalchemy.orm import object_session, object_mapper
from sqlalchemy.orm.properties import PropertyLoader

if not mapper:
mapper = object_mapper(obj)
session = object_session(obj)

for col in mapper.mapped_table.c:
if not col.primary_key and data.has_key(col.name):
setattr(obj, col.name, data[col.name])

xx = [(a,b) for a,b in getattr(mapper, '_Mapper__props').items()
  if isinstance(b, 

[sqlalchemy] Temporary table example?

2008-04-16 Thread Gloria W

Hi again,

I am looking for a good example on how to form a temporary table. I
have two unrelated tables with no foreign keys. But I want to
consolidate the data into a temp table and sort on their date field,
to see all records chronologically from both tables.

I could do it by hand in Python, but I'm trying to find an SqlAlchemy
way to do it.

Thank you in advance,
Gloria


--~--~-~--~~~---~--~~
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] Session binding to existing table: what am I missing?

2008-04-16 Thread Gloria W

Hi all,
I am trying to use the session syntax to bind to an existing table,
but I am apparently missing something. I want my session to be bound
to this:

my_table = sqlalchemy.Table('my_table', meta, autoload=True,
autoload_with=engine)

and if I use the same engine here:

session = sqlalchemy.orm.sessionmaker(bind=engine, autoflush=True,
transactional=True)

isn't the session bound to the table?

But when I run this:

all_records = session.query(my_table).all()

I get this error:

Traceback (most recent call last):
  File /usr/local/python/2.5.2/lib/python2.5/site-packages/
CherryPy-3.1.0beta3-py2.5.egg/cherrypy/_cprequest.py, line 588, in
respond
cherrypy.response.body = self.handler()
  File /usr/local/python/2.5.2/lib/python2.5/site-packages/
CherryPy-3.1.0beta3-py2.5.egg/cherrypy/_cpdispatch.py, line 24, in
__call__
return self.callable(*self.args, **self.kwargs)
  File /home/gloriajw/FU_OP/code/FU_OP.py, line 66, in run_report
all_records = session.query(fu_op_purchases).all()
  File /usr/local/python/2.5.2/lib/python2.5/site-packages/
SQLAlchemy-0.4.5-py2.5.egg/sqlalchemy/orm/session.py, line 739, in
query
q = self._query_cls(mapper_or_class, self, **kwargs)
  File /usr/local/python/2.5.2/lib/python2.5/site-packages/
SQLAlchemy-0.4.5-py2.5.egg/sqlalchemy/orm/query.py, line 63, in
__init__
self.__init_mapper(_class_to_mapper(class_or_mapper,
entity_name=entity_name))
  File /usr/local/python/2.5.2/lib/python2.5/site-packages/
SQLAlchemy-0.4.5-py2.5.egg/sqlalchemy/orm/query.py, line 69, in
__init_mapper
self.table = self._from_obj = self.mapper.mapped_table
AttributeError: 'PGCompiler' object has no attribute 'mapped_table'

The docs I've seen only show session bindings using Table classes, so
please point me to a good example or give me the quick hint.

Thank you in advance,
Gloria

--~--~-~--~~~---~--~~
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: Postgres cascade error ?

2008-04-16 Thread Michael Bayer


On Apr 15, 2008, at 10:32 PM, Dave Harrison wrote:


 Hey all,

 The below code establishes 3 tables (house, dog, owner) and a
 mapper table to associate owners and dogs (friendships).

 When I use either MySQL (5.0.51) or SQLite (3.4.2) as the backend,
 this code works correctly.  However when I use Postgres (either 8.2.7
 or 8.3.1) I get the following integrity error:

 sqlalchemy.exceptions.IntegrityError: (IntegrityError) update or
 delete on table dog violates foreign key constraint
 friendship_dog_id_fkey on table friendship DETAIL:  Key (id)=(1)
 is still referenced from table friendship.  'DELETE FROM dog WHERE
 dog.id = %(id)s' [{'id': 1}, {'id': 2}]

always use delete cascade in conjunction with delete-orphan.   It  
doesnt make much sense to have delete-orphan only and not delete  
cascade. If that doesn't solve your problem here, let me know and Ill  
try running the example script.



--~--~-~--~~~---~--~~
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: Get Mapper for Table

2008-04-16 Thread Michael Bayer


On Apr 16, 2008, at 10:13 AM, Koen Bok wrote:


 Hey all,

 Before 0.4.5 I used this code to get the mapped class for a table. It
 worked fine, but mapper_registry was made private in 0.4.5 and the
 private function does not behave the same way for some reason. But as
 this code is pretty nasty anyway I was wondering if there was a better
 way to do this. If not, can anyone hint me how to make this work
 again?



from sqlalchemy.orm import mapper as _mapper

my_table_registry = {}
def mapper(cls, tbl, **kwargs):
my_table_registry[tbl] = cls
return _mapper(cls, tbl, **kwargs)



--~--~-~--~~~---~--~~
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] Get Mapper for Table

2008-04-16 Thread Koen Bok

Hey all,

Before 0.4.5 I used this code to get the mapped class for a table. It
worked fine, but mapper_registry was made private in 0.4.5 and the
private function does not behave the same way for some reason. But as
this code is pretty nasty anyway I was wondering if there was a better
way to do this. If not, can anyone hint me how to make this work
again?

If you are wondering, I need this for asynchronous updates in
postgres. The modification table holds the table name for a
modification and inserted by a trigger.

Koen

classTableCache = dict()

def classForTable(tableName):
Returns the mapped class for a particular table name.

if classTableCache == dict():
for table in metadata.table_iterator(reverse=False):
for mapper in mapperlib.mapper_registry.values():
if table == mapper.base_mapper.mapped_table:
# This is an extremely ugly hack that 
only works when all patent
mapper names
# are longer than inherited mapper names
if classTableCache.has_key(table.name):
if len(str(mapper.class_)) 
len(str(classTableCache[table.name])):

classTableCache[table.name] = mapper.class_
else:
classTableCache[table.name] = 
mapper.class_

return classTableCache[tableName]
--~--~-~--~~~---~--~~
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] Table constructor ignores quote=False when table name is mixed case

2008-04-16 Thread Dr.T

I am using mixed case for my Elixir Entities in common with other
identifiers.

When these are passed though to SQLAlchemy, the table name is double-
quoted in generated SQL and the database is created with quoted table
names.

This does not matter with SQLite, which ignores quotes in this
context.

Oracle however becomes case sensitive when quotes are used and if a
table is created with a quoted name, you must always quote references
to it thereafter, which most people would not want!

To sort this out, I thought that I could just pass the quote=False
kwarg through to the Table constructor, which Elixir does via its
using_table_options clause.

This does not work however.

To investigate, using the SQLAlchemy tutorial example, I generated a
table directly in SQLAlchemy, as follows:

users_table = Table('usersTable', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(40)),
Column('fullname', String(100)),
Column('password', String(15)),
quote=False
)

Sure enough, the table name is quoted and the quote=False is ignored.

Would it be possible to amend the code to respect the quote kwarg
regardless of the capitalization of the table name?

Thanks for your help,

Tim
--~--~-~--~~~---~--~~
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: Table constructor ignores quote=False when table name is mixed case

2008-04-16 Thread Michael Bayer


On Apr 16, 2008, at 12:22 PM, Dr.T wrote:


 Oracle however becomes case sensitive when quotes are used and if a
 table is created with a quoted name, you must always quote references
 to it thereafter, which most people would not want!

 To sort this out, I thought that I could just pass the quote=False
 kwarg through to the Table constructor, which Elixir does via its
 using_table_options clause.

 This does not work however.

 To investigate, using the SQLAlchemy tutorial example, I generated a
 table directly in SQLAlchemy, as follows:

 users_table = Table('usersTable', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(40)),
Column('fullname', String(100)),
Column('password', String(15)),
quote=False
)

 Sure enough, the table name is quoted and the quote=False is ignored.

 Would it be possible to amend the code to respect the quote kwarg
 regardless of the capitalization of the table name?

Theres no reason to do so, and it would add additional expression  
overhead to the _requires_quotes call which is a very heavily used  
method.  Just specify your tablename as all lowercase, and no quotes  
will be used.  Oracle will record the tablename as USERSTABLE  
regardless of the casing present, if quotes arent used, so the end  
effect is the same.


--~--~-~--~~~---~--~~
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: Table constructor ignores quote=False when table name is mixed case

2008-04-16 Thread Dr.T

Michael,

You are right and that is what I have done.

I didn't appreciate that what I suggested would add overhead ;-(

Perhaps a line could be added to the Table constructor documentation
to point out that the name kwarg is ignored when the table name is
in mixed case (because this is not obvious)?

Thanks for your help,
Tim

On Apr 16, 5:35 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Apr 16, 2008, at 12:22 PM, Dr.T wrote:





  Oracle however becomes case sensitive when quotes are used and if a
  table is created with a quoted name, you must always quote references
  to it thereafter, which most people would not want!

  To sort this out, I thought that I could just pass the quote=False
  kwarg through to the Table constructor, which Elixir does via its
  using_table_options clause.

  This does not work however.

  To investigate, using the SQLAlchemy tutorial example, I generated a
  table directly in SQLAlchemy, as follows:

  users_table = Table('usersTable', metadata,
 Column('id', Integer, primary_key=True),
 Column('name', String(40)),
 Column('fullname', String(100)),
 Column('password', String(15)),
 quote=False
 )

  Sure enough, the table name is quoted and the quote=False is ignored.

  Would it be possible to amend the code to respect the quote kwarg
  regardless of the capitalization of the table name?

 Theres no reason to do so, and it would add additional expression
 overhead to the _requires_quotes call which is a very heavily used
 method.  Just specify your tablename as all lowercase, and no quotes
 will be used.  Oracle will record the tablename as USERSTABLE
 regardless of the casing present, if quotes arent used, so the end
 effect is the same.
--~--~-~--~~~---~--~~
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] association_proxy import fail

2008-04-16 Thread Vortexmind

Hi all
I'm new to python and was playing around with Elixir tutorial (a
wrapper for Sqlalchemy).
I get a failed import with this code

from elixir import *

metadata.bind = sqlite:///movies.sqlite
metadata.bind.echo = True

class Movie(Entity):
title = Field(Unicode(30))
year = Field(Integer)
description = Field(Unicode)

def __repr__(self):
return 'Movie %s (%d)' % (self.title, self.year)


If I load it in a python shell (either python or ipython) I get this
error

ImportError: cannot import name association_proxy

from trace, this is the call that fails
from sqlalchemy.ext.associationproxy import association_proxy

I checked in the SqlAlchemy docs, and I found that it's a feature
present in version = 0.31
As I'm using gentoo linux, I've checked out and I have installed 0.37
so I should have it.

Any clue?



--~--~-~--~~~---~--~~
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: Session binding to existing table: what am I missing?

2008-04-16 Thread jason kirtland

Gloria W wrote:
 Hi all,
 I am trying to use the session syntax to bind to an existing table,
 but I am apparently missing something. I want my session to be bound
 to this:
 
 my_table = sqlalchemy.Table('my_table', meta, autoload=True,
 autoload_with=engine)
 
 and if I use the same engine here:
 
 session = sqlalchemy.orm.sessionmaker(bind=engine, autoflush=True,
 transactional=True)
 
 isn't the session bound to the table?
 
 But when I run this:
 
 all_records = session.query(my_table).all()
 
 I get this error:
 
 Traceback (most recent call last):
[..zip...[
 AttributeError: 'PGCompiler' object has no attribute 'mapped_table'
 
 The docs I've seen only show session bindings using Table classes, so
 please point me to a good example or give me the quick hint.

The ORM maps your Python classes to tables rather than working with 
tables directly.  You're missing a step in the middle like:

class MyClass(object):
   def my_stuff(self):
  self.yadayada

sqlalchemy.orm.mapper(MyClass, my_table)

all_records = session.query(MyClass).all()

The ORM tutorial lays out the steps in more detail: 
http://www.sqlalchemy.org/docs/04/ormtutorial.html



--~--~-~--~~~---~--~~
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: association_proxy import fail

2008-04-16 Thread Vortexmind

You're right
I've installed the 0.45 and it works :)

Thank you!

On Apr 16, 7:33 pm, jason kirtland [EMAIL PROTECTED] wrote:
 The function 'association_proxy' is present starting in 0.3.8+.  The
 0.3.7 release is few days shy of a year old- the current version is
 0.4.5.  I'd suggest upgrading if you're following any of the online
 tutorials for SA or Elixir.

 -j
--~--~-~--~~~---~--~~
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 migration/schema creation

2008-04-16 Thread Lukasz Szybalski

On Wed, Apr 16, 2008 at 1:03 AM,  [EMAIL PROTECTED] wrote:

  a separate feature - no.
  but it's not much to do it. here my attempt at this.

  try copyall or copydata+autoload from here:
  http://dbcook.svn.sourceforge.net/viewvc/dbcook/trunk/dbcook/misc/metadata/

  svn co
  http://dbcook.svn.sourceforge.net/dbcook/trunk/dbcook/misc/metadata/

this works:
svn co 
https://dbcook.svn.sourceforge.net/svnroot/dbcook/trunk/dbcook/misc/metadata/

At which point here is the table created in dst database?


metadata = autoloader.metadata()

here you get the src metadata about tables?!!

dst_engine= sqlalchemy.create_engine( dbdst)
Here you change the engine??
metadata.bind = dst_engine


This will create tables from the first line statement?
metadata.create_all()


Lucas

--~--~-~--~~~---~--~~
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: Postgres cascade error ?

2008-04-16 Thread David Harrison

On 17/04/2008, Michael Bayer [EMAIL PROTECTED] wrote:
  On Apr 15, 2008, at 10:32 PM, Dave Harrison wrote:

  
   Hey all,
  
   The below code establishes 3 tables (house, dog, owner) and a
   mapper table to associate owners and dogs (friendships).
  
   When I use either MySQL (5.0.51) or SQLite (3.4.2) as the backend,
   this code works correctly.  However when I use Postgres (either 8.2.7
   or 8.3.1) I get the following integrity error:
  
   sqlalchemy.exceptions.IntegrityError: (IntegrityError) update or
   delete on table dog violates foreign key constraint
   friendship_dog_id_fkey on table friendship DETAIL:  Key (id)=(1)
   is still referenced from table friendship.  'DELETE FROM dog WHERE
   dog.id = %(id)s' [{'id': 1}, {'id': 2}]

  always use delete cascade in conjunction with delete-orphan.   It
  doesnt make much sense to have delete-orphan only and not delete
  cascade. If that doesn't solve your problem here, let me know and Ill
  try running the example script.

If I use delete, delete-orphan I get the same errors

--~--~-~--~~~---~--~~
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: Postgres cascade error ?

2008-04-16 Thread Michael Bayer


On Apr 16, 2008, at 6:21 PM, David Harrison wrote:


 If I use delete, delete-orphan I get the same errors


Like I mentioned, delete-orphan doesn't work very well separated  
from delete cascade - which means that its only appropriate for a  
one-to-many or one-to-one relation.   When many Friendship rows  
reference the same Dog row, the deletion of any Friendship row  
cascades to the Dog row (since delete cascade is implied by delete- 
orphan cascade) and the constraint fails.

delete-orphan was never designed to track many parents, its just a  
convenience feature for the typical owned by one parent use case.



--~--~-~--~~~---~--~~
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: Postgres cascade error ?

2008-04-16 Thread Michael Bayer


On Apr 16, 2008, at 7:59 PM, David Harrison wrote:


 On 17/04/2008, Michael Bayer [EMAIL PROTECTED] wrote:


 On Apr 16, 2008, at 6:21 PM, David Harrison wrote:


 If I use delete, delete-orphan I get the same errors



 Like I mentioned, delete-orphan doesn't work very well separated
 from delete cascade - which means that its only appropriate for a
 one-to-many or one-to-one relation.   When many Friendship rows
 reference the same Dog row, the deletion of any Friendship row
 cascades to the Dog row (since delete cascade is implied by delete-
 orphan cascade) and the constraint fails.

 delete-orphan was never designed to track many parents, its just a
 convenience feature for the typical owned by one parent use case.

 Why does MySQL and SQLite behave as I expect, but Postgres doesn't  
 though ?


they dont behave like you expect; they dont respect foreign keys, so  
your database is in a slightly corrupted state after the operation  
completes.

--~--~-~--~~~---~--~~
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: Postgres cascade error ?

2008-04-16 Thread Eric Ongerth



On Apr 16, 7:24 am, Michael Bayer [EMAIL PROTECTED] wrote:

 always use delete cascade in conjunction with delete-orphan.   It
 doesnt make much sense to have delete-orphan only and not delete
 cascade.

Oh wow.  That clears up a few things for me.  I don't remember ever
seeing this (or at least I don't remember taking this sense of things
away after reading) in the documentation.  Maybe I developed a blind
spot back around 3.something and never got past it?  I have simply
been avoiding delete-orphan although I looked forward to figuring out
how to use it without errors some day.  I think this was the key fact
that I missed, even though as you pointed out it's kind of the only
way that makes sense.
--~--~-~--~~~---~--~~
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: Postgres cascade error ?

2008-04-16 Thread David Harrison

On 17/04/2008, Michael Bayer [EMAIL PROTECTED] wrote:

  On Apr 16, 2008, at 9:31 PM, Eric Ongerth wrote:

  
   On Apr 16, 7:24 am, Michael Bayer [EMAIL PROTECTED] wrote:
  
   always use delete cascade in conjunction with delete-orphan.   It
   doesnt make much sense to have delete-orphan only and not delete
   cascade.
  
   Oh wow.  That clears up a few things for me.  I don't remember ever
   seeing this (or at least I don't remember taking this sense of things
   away after reading) in the documentation.  Maybe I developed a blind
   spot back around 3.something and never got past it?  I have simply
   been avoiding delete-orphan although I looked forward to figuring out
   how to use it without errors some day.  I think this was the key fact
   that I missed, even though as you pointed out it's kind of the only
   way that makes sense.


 it *could* make sense as this thing that will scan a whole set of
  referenced entities for a link, but thats just not what we have
  implemented right now (and also im less certain about what the real
  use case there is).

For my part, my-use case is that I want to be able to delete an entry
from my mapper table (the friendshipTable in my example code), and
have it collect any of the mapped entries (dogTable) that are no
longer mapped.  Not sure if it's a common use-case.

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