On Sep 3, 3:45 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Sep 3, 2008, at 4:14 PM, Mike wrote:
>
>
>
> > Replying to my own message seems kind of schizo, but I found one
> > solution. I reflected the view into a Table() object and then used the
> > "select" method along with "and_" and "not_". I would prefer to use
> > the session object, but this works.
>
> > I'm currently converting the following SQL:
>
> > SELECT LNAME, FNAME, NETNAME
> > FROM MyView
> > WHERE (DEPT = '%s') AND (NETNAME <> '')
>
> > I then access it like this:
>
> > <code>
>
> > engine = create_engine('mssql://user:[EMAIL PROTECTED]/DB')
> > meta = MetaData(engine)
> > emp_tbl = Table('MyView', meta, autoload=True)
> > s = select([emp_tbl.c.LNAME,
> >        emp_tbl.c.FNAME,
> >        emp_tbl.c.NETNAME],
> >       and_(emp_tbl.c.HOME_DEPT==deptNum, not_(emp_tbl.c.NETNAME=="")))
> > res = engine.execute(s)
> > row = res.fetchall()
>
> > </code>
>
> > Is there a less messy way to accomplish this? (Yes, I am a SQL newb!)
>
> im surprised the "autoload" works for a view.  If you have that, then  
> you should be able to just make a mapper() to that Table as usual -  
> you might need to specify "primary_key" to your mapper and/or Table  
> (e.g. Table('name', meta, Column('id', Integer, primary_key=True),  
> autoload=True)) .  You just can't issue any changes to the object  
> (unless the view is writeable).

I guess my issue is getting my mind around how to create the class
object to map to. I didn't create this view or the tables that it
manipulates, so I'm not sure what attributes / properties to give the
class. I guess I can get the column names that are returned in SQL
Server Enterprise Manager and see if those work for the class
attributes.

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

Reply via email to