[sqlalchemy] RETURNING clause on Insert (Oracle sequences)
Hi, Is there a reason why this is not used to return the id column value? Would cut down on the number of roundtrips for insert statements e.g. insert into bob (id) values (bob_sq.nextval) returning id into :id rather than what seems to be happening at the moment: select bob_sq.nextval from dual; insert into bob (id) values (:id); 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] setting table and mapper arguments with Declarative
I want to set table, mapper arguments automatically. The following is the only way I have found to do this. Is this supported? Am I wasting my time with Declarative and should rather use the non declarative if I want this control? class MyMeta(DeclarativeMeta): def __new__(meta, classname, bases, classdict): # Copy interesting arguments from base classes for base in bases: for arg in (a for a in ('__table_args__', '__tablename__', '__mapper_args__') if a in base.__dict__): classdict[arg] = base.__dict__[arg] return DeclarativeMeta.__new__(meta, classname, bases, classdict) Base = declarative_base(bind=engine) class MyDeclarativeStuff(object): # Set some generic stuff up. __table_args__ = {'autoload':True} class Customer(Base, MyDeclarativeStuff): __metaclass__ = MyMeta __tablename__ = 'customer' Many 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: RETURNING clause on Insert (Oracle sequences)
On Sep 18, 2008, at 4:53 AM, GHZ wrote: Hi, Is there a reason why this is not used to return the id column value? Would cut down on the number of roundtrips for insert statements e.g. insert into bob (id) values (bob_sq.nextval) returning id into :id rather than what seems to be happening at the moment: select bob_sq.nextval from dual; insert into bob (id) values (:id); we have this feature implemented for postgres, though it is not yet integrated with the ORM. it would be a feature add for Oracle as well.My oracle experience dates back to the 8 series where im not sure if this syntax was available. --~--~-~--~~~---~--~~ 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: How to mark an attribute dirty manually?
On Sep 18, 2008, at 5:46 AM, Adam Dziendziel wrote: Hi, I have a column which contains XML, this XML is parsed when a record is loaded and object attributes are populated with values from this XML. When I set an attribute, I would like to mark the XML column modified (in property() setter). I wouldn't need to serialize all attributes and assign a new value to the XML column explicitly when only a single attribute changes. This would generate too much overhead when I set many attributes subsequently. I'd like to just make the XML column (or the whole record) dirty, so that I'm able to serialize attributes to XML only in before_insert/before_update handlers in a MapperExtension. Is this possible with SQLAlchemy? I'm using 0.4.x. This description was very hard to parse, but I think what you're saying is an attribute changes on a *different* object somewhere, which you would like to mark the XML-holding object as dirty. To mark the object dirty you can say instance_state(myobject).modified = True , where instance_state is in sqlalchemy.orm.attributes.Theres no dirty flag on individual attributes, the change status is determined by the contents of the attribute. So just blanking out the XML attribute until needed is a pretty easy approach here too.Yet another option which is the most lightweight would be to use a SessionExtension with an after_flush() method that issues an UPDATE to the XML-holding column directly. --~--~-~--~~~---~--~~ 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] Oracle Express fails 0.5 ORM tutorial
Hello I have Oracle Express Release 10.2.0.1.0, SQLAlchemy 0.4.5, Python 2.5.2 on Ubuntu x86 8.04. When I go through the ORM tutorial at http://www.sqlalchemy.org/docs/04/ormtutorial.html it fails at the first query below the heading *Saving Objects* with an Oracle ORA-01400 error as follows: sqlalchemy.exceptions.DatabaseError: (DatabaseError) ORA-01400: cannot insert NULL into (BRUCE.USERS.ID) 'INSERT INTO users (id, name, fullname, password) VALUES (:id, :name, :fullname, :password)' {'fullname': 'Ed Jones', 'password': 'edspassword', 'name': 'ed', 'id': None} My create_engine string was engine = sa.create_engine('oracle://bruce:[EMAIL PROTECTED]', echo=True) The superficial reason for the error is obvious. Is this an Oracle eccentricity? Is there a workaround? Regards Bruce --~--~-~--~~~---~--~~ 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: Problem using utf-8
Thank you. Switching to 1.2.2 and using connect_args = {'use_unicode': False,'charset': 'utf8'} works fine for me. Jürgen Michael Bayer schrieb: I believe this is the ticket: http://sourceforge.net/tracker/index.php?func=detailaid=1592353group_id=22307atid=374932 its a little ambiguous as to its resolution, maybe I'll ask Shannon what his most recent experiences were. On Sep 17, 2008, at 12:03 PM, Bo Shi wrote: While researching which version to deploy, I had run into a thread post _claiming_ that 1.2.2 had a critical bug which was documented in the fedora bugzilla. I never managed to actually find said bug but it scared me off. The reason we went with 1.2.1p2 was because it was the version the Django people have been using with success. At any rate, the workaround I posted seems to work for us thus far, though I don't have a good understanding of exactly why it works (I suspect it tiptoes around a double-encoding bug in mysqldb). Bo On Wed, Sep 17, 2008 at 11:31 AM, Michael Bayer [EMAIL PROTECTED] wrote: On Sep 17, 2008, at 10:50 AM, Bo Shi wrote: I ran into a similar issue using MySQL-python-1.2.1_p2-1 (mysqldb) with SA 0.4.2p3-1. I would advise upgrading to MySQL-python 1.2.2. I believe some utf-8 issues have been fixed. --~--~-~--~~~---~--~~ 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: grandparent id relation
On Sep 18, 2008, at 6:27 AM, GHZ wrote: Hi, I have a database table : 'Child' that contains the parent_id and grandparent_id. Foreign keys are present for both. I'm using declarative What is best practice to have the grandparent_id column set correctly when I insert? class GrandParent(Base): __tablename__ = 'grandparent' __table_args__ = {'autoload' : True, 'useexisting' : True} children = relation('Parent', backref=backref('parents') class Parent(Base): __tablename__ = 'parent' __table_args__ = {'autoload' : True, 'useexisting' : True} children = relation('Child', backref=backref('parents') class Child(Base): # Table has parent_id and grandparent_id columns __tablename__ = 'child' __table_args__ = {'autoload' : True, 'useexisting' : True} grandparent = GrandParent() parent = Parent() child = Child() grandparent.children = [parent] parent.children = [child] When I flush, I want child.grandparent_id to be set to the newly created grandparent. theres two general ways: 1. quick and dirty: use a before_insert()/before_update() MapperExtension which sets the grandparent_id column on Child. If Child also had a relation() to GrandParent, you'd want to expire() it too. 2. more involved: catch change events and populate a Child.grandparent relation(). 0.5 has made the AttributeExtension API public which would be a good place to catch this event. The advantage to this is that your Child has a grandparent already set before any SQL is issued to the database. --~--~-~--~~~---~--~~ 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: Oracle Express fails 0.5 ORM tutorial
On Sep 18, 2008, at 8:06 AM, Bruce Smith wrote: Hello I have Oracle Express Release 10.2.0.1.0, SQLAlchemy 0.4.5, Python 2.5.2 on Ubuntu x86 8.04. When I go through the ORM tutorial at http://www.sqlalchemy.org/docs/04/ormtutorial.html it fails at the first query below the heading Saving Objects with an Oracle ORA-01400 error as follows: sqlalchemy.exceptions.DatabaseError: (DatabaseError) ORA-01400: cannot insert NULL into (BRUCE.USERS.ID) 'INSERT INTO users (id, name, fullname, password) VALUES (:id, :name, :fullname, :password)' {'fullname': 'Ed Jones', 'password': 'edspassword', 'name': 'ed', 'id': None} My create_engine string was engine = sa.create_engine('oracle://bruce:[EMAIL PROTECTED]', echo=True) The superficial reason for the error is obvious. Is this an Oracle eccentricity? Is there a workaround? With Oracle, SQLA needs you to supply a Sequence for each column which you'd like to have autoincrementing behavior - the tutorial assumes all primary key columns are autoincrementing.SQLA will issue the CREATE SEQUENCE for you upon table.create(), but you need to just give it a name (the Oracle crowd, in my experience, appreciates no names of anything being guessed): Column('id', Integer, Sequence('mytable_id_seq'), primary_key=True) --~--~-~--~~~---~--~~ 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: How to mark an attribute dirty manually?
This description was very hard to parse, but I think what you're saying is an attribute changes on a *different* object somewhere, which you would like to mark the XML-holding object as dirty. Sorry. The same object, but these attributes are pure Python attributes, they aren't mapped to columns in the database. They are defined using property() and act as proxies to nodes in XML document. To mark the object dirty you can say instance_state(myobject).modified = True , where instance_state is in sqlalchemy.orm.attributes. Theres no dirty flag on individual attributes, the change status is determined by the contents of the attribute. So just blanking out the XML attribute until needed is a pretty easy approach here too. Yet another option which is the most lightweight would be to use a SessionExtension with an after_flush() method that issues an UPDATE to the XML-holding column directly. This is what I was looking for. Thank you! Best regards, Adam --~--~-~--~~~---~--~~ 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: Problem using utf-8
Switching to 1.2.2 and using connect_args = {'use_unicode': False,'charset': 'utf8'} works fine for me. Hi Jürgen, I'm curious; if you upgraded to 1.2.2, does the issue persist if you stop using connect_args = {'use_unicode': False,'charset': 'utf8'}? Bo On Thu, Sep 18, 2008 at 3:07 AM, Jürgen Hauptmann [EMAIL PROTECTED] wrote: Thank you. Switching to 1.2.2 and using connect_args = {'use_unicode': False,'charset': 'utf8'} works fine for me. Jürgen Michael Bayer schrieb: I believe this is the ticket: http://sourceforge.net/tracker/index.php?func=detailaid=1592353group_id=22307atid=374932 its a little ambiguous as to its resolution, maybe I'll ask Shannon what his most recent experiences were. On Sep 17, 2008, at 12:03 PM, Bo Shi wrote: While researching which version to deploy, I had run into a thread post _claiming_ that 1.2.2 had a critical bug which was documented in the fedora bugzilla. I never managed to actually find said bug but it scared me off. The reason we went with 1.2.1p2 was because it was the version the Django people have been using with success. At any rate, the workaround I posted seems to work for us thus far, though I don't have a good understanding of exactly why it works (I suspect it tiptoes around a double-encoding bug in mysqldb). Bo On Wed, Sep 17, 2008 at 11:31 AM, Michael Bayer [EMAIL PROTECTED] wrote: On Sep 17, 2008, at 10:50 AM, Bo Shi wrote: I ran into a similar issue using MySQL-python-1.2.1_p2-1 (mysqldb) with SA 0.4.2p3-1. I would advise upgrading to MySQL-python 1.2.2. I believe some utf-8 issues have been fixed. -- Bo Shi 207-469-8264 --~--~-~--~~~---~--~~ 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: RETURNING clause on Insert (Oracle sequences)
Thank you Michael, I found the changeset adding this to Postgresql. Will look into a similar change 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Problem with coverage and sqlalchemy declarative synonym?
With some help from Ned Batchelder I was able to confirm that this is a Python bug: http://bugs.python.org/issue1569356 that has been fixed since the 2.5.2 release. Ned confirmed that the fix is included in Python 2.6a3. Doug On Sep 16, 5:22 pm, Doug Latornell [EMAIL PROTECTED] wrote: Thanks for the quick replies, Jason and Michael, and for the very succinct test case. I will try to raise this with Ned Bachelor over athttp://nedbatchelder.com/code/modules/coverage.html Doug On Sep 16, 4:55 pm, Michael Bayer [EMAIL PROTECTED] wrote: On Sep 16, 2008, at 7:25 PM, Doug Latornell wrote: Over on the TurboGears list a TG2 user pointed out a problem that arises when nosetests --with-coverage is run on a project with a sqlalchemy identity model:http://groups.google.com/group/turbogears/t/7fd3639a5a4d4b8c I dug into it and have reproduced the problem outside of TurboGears 2 and without nose:http://paste.turbogears.org/paste/7051 I've also shown that the problem isn't there for a plain Python property (in contrast to a sqlalchemy synonym):http://paste.turbogears.org/paste/7052 So, it looks like a problem maybe with the metaclass that sqlalchemy uses to build properties, or with coverage not understanding what that metaclass produces, or something. Or is there something else I'm missing? I've seen this identical issue with Bitten, and its not a SQLAlchemy one. Here's the ticket: http://www.sqlalchemy.org/trac/ticket/1138 Replace your test case with this script: def foo(somearg): class Bar(object): def __getattr__(self, attribute): return getattr(somearg, attribute) assert 'somearg' not in Bar.__dict__ foo('hi') I just ran it with the coverage.py that we have in SQLAlchemy and the bug reproduces. --~--~-~--~~~---~--~~ 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: Oracle Express fails 0.5 ORM tutorial
Thanks Michael, that works neatly. - Bruce On Fri, Sep 19, 2008 at 12:03 AM, Michael Bayer [EMAIL PROTECTED]wrote: On Sep 18, 2008, at 8:06 AM, Bruce Smith wrote: Hello I have Oracle Express Release 10.2.0.1.0, SQLAlchemy 0.4.5, Python 2.5.2 on Ubuntu x86 8.04. When I go through the ORM tutorial at http://www.sqlalchemy.org/docs/04/ormtutorial.html it fails at the first query below the heading *Saving Objects* with an Oracle ORA-01400 error as follows: sqlalchemy.exceptions.DatabaseError: (DatabaseError) ORA-01400: cannot insert NULL into (BRUCE.USERS.ID) 'INSERT INTO users (id, name, fullname, password) VALUES (:id, :name, :fullname, :password)' {'fullname': 'Ed Jones', 'password': 'edspassword', 'name': 'ed', 'id': None} My create_engine string was engine = sa.create_engine('oracle://bruce:[EMAIL PROTECTED]', echo=True) The superficial reason for the error is obvious. Is this an Oracle eccentricity? Is there a workaround? With Oracle, SQLA needs you to supply a Sequence for each column which you'd like to have autoincrementing behavior - the tutorial assumes all primary key columns are autoincrementing.SQLA will issue the CREATE SEQUENCE for you upon table.create(), but you need to just give it a name (the Oracle crowd, in my experience, appreciates no names of anything being guessed): Column('id', Integer, Sequence('mytable_id_seq'), primary_key=True) --~--~-~--~~~---~--~~ 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: any effort getting sqlalchemy to work on ironpython is going on ?
Just try IronPython beta5. And it work now. :D On 12 ก.ย., 10:01, sakesun [EMAIL PROTECTED] wrote: I need sqlalchemy to work on ironpython (1.2 or 2.0b) sqlalchemy fail on ironpython even with simple use case like create simple Table definition. from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey metadata = MetaData() users_table = Table('users', metadata, ... Column('id', Integer, primary_key=True), ... Column('name', String), ... Column('fullname', String), ... Column('password', String) ... ) Traceback (most recent call last): File stdin, line 1, in module IndexError: Index was outside the bounds of the array. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---