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).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---