On Sep 11, 2010, at 12:59 PM, Faheem Mitha wrote:
>
> Hi,
>
> The following session is never saved to the db, not even a schema is created,
> but a query returns correctly. I assume that there is local caching going on.
> but session.dirty etc doesn't show anything. So, two questions:
>
> First, how (if possible) can I force sqla to hit the db? In this case, how
> can I force it to return an error for the line
>
> print session.execute(q1).fetchall()
The code below does not do any caching. The SQL you are emitting with the
";" is incorrect - DBAPI's execute() method does not generally support multiple
statements in one string (I've only seen that with Microsoft tools in my own
experience). It's a little strange that those executions aren't raising an
error, though. If your test depends on the table being dropped and recreated,
that is probably what's not working as expected below. Take all the
semicolons and "multiple statements in one execute()" out.
>
> ?
>
> Second, how can I get sqla to show there is data unsaved to the db? I tried
> dirty and new. Thanks in advance.
>
> Regards, Faheem
>
> ************************************************************************
>
> dbuser =
> password =
> dbname =
> dbstring = "postgres://%s:%...@localhost:5432/%s"%(dbuser,password, dbname)
> from sqlalchemy import create_engine
> from sqlalchemy.orm sessionmaker
> db = create_engine(dbstring)
> from sqlalchemy import MetaData
> from sqlalchemy.sql import text
> meta = MetaData()
> meta.bind = db
> meta.create_all()
> Session = sessionmaker()
> session = Session(bind=db)
> session.execute("DROP SCHEMA IF EXISTS foo CASCADE; CREATE SCHEMA foo;")
> q = text("DROP TABLE IF EXISTS foo.activity; CREATE TABLE foo.activity AS
> SELECT * FROM pg_stat_activity;")
> session.execute(q)
> q1 = text("select * from foo.activity;")
> print session.execute(q1).fetchall()
> print session.dirty
> print session.new
>
> --
> 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.
>
--
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.