Thanks, I'm not sure its a good thing that I found new ways to use SA that were unintended by the author :). In this case the raw sql query should return only a single row.
Michael Bayer wrote: > I dont think this was ever known behavior in 0.4 and its a little > strange that it worked....it "works" in 0.5 as of r5458, but keep in > mind first() still fetches the full result set of the query. > > > On Dec 10, 2008, at 3:14 PM, David Gardner wrote: > > >> It seems what when using .first() with from_statement() I get a >> traceback with 0.5rc4 when no rows are found (works when a row is >> fount): >> >> using 0.4.8 I get: >> /usr >> 0.4.8 >> >> with 0.5rc4 I get: >> /users/dgardner/dev >> 0.5.0rc4 >> Traceback (most recent call last): >> File "assetdb_test.py", line 38, in <module> >> session.query(Note).from_statement(qry%(uid,name,updated)).first() >> File >> "/users/dgardner/dev/lib/python2.5/site-packages/SQLAlchemy-0.5.0rc4- >> py2.5.egg/sqlalchemy/orm/query.py", >> line 1025, in first >> return list(self)[0] >> IndexError: list index out of range >> >> >> >> My test: >> -------------------- >> import sys >> print sys.prefix >> from sqlalchemy import * >> import sqlalchemy >> from sqlalchemy.orm import * >> >> DB_HOST = 'localhost' >> DB_NAME = 'transitional' >> DB_USER = 'sqluser' >> DB_PASS = 'not_my_password' >> >> db_uri = 'postgres://%s:[EMAIL PROTECTED]/%s' % >> (DB_USER,DB_PASS,DB_HOST,DB_NAME) >> >> db = create_engine (db_uri, pool_size=200,max_overflow=200) >> #db.echo = True >> metadata = MetaData(db) >> >> class Note(object): >> pass >> >> note_table = Table('note', metadata, >> Column('id', Integer, primary_key=True), >> Column('created', DateTime, default=func.now()), >> Column('updated', DateTime, default=func.now(), >> onupdate=func.current_timestamp()), >> Column('author', >> String(255),ForeignKey('users.userid')), >> Column('note', String), >> Column('asset', String(20), >> ForeignKey('nodehierarchy.uid'), nullable=False) >> ) >> mapper(Note, note_table) >> >> print sqlalchemy.__version__ >> qry="""SELECT note.* FROM note_task JOIN note ON >> note_task.note=note.id >> WHERE note_task.task_asset='%s' AND note_task.task_name='%s' AND >> note.updated='%s'""" >> uid='00420123774551347239' >> name='UV' >> updated='2008-12-05 16:45:46.299124-08:00' >> session = create_session() >> >> session.query(Note).from_statement(qry%(uid,name,updated)).first() >> >> >> sys.exit(0) >> >> -- >> David Gardner >> Pipeline Tools Programmer, "Sid the Science Kid" >> Jim Henson Creature Shop >> [EMAIL PROTECTED] >> >> >> >> > > > > > > -- David Gardner Pipeline Tools Programmer, "Sid the Science Kid" Jim Henson Creature Shop [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---