On Jun 17, 11:15 am, Hans <[EMAIL PROTECTED]> wrote:
> On Jun 17, 11:12 am, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jun 17, 10:36 am, Hans <[EMAIL PROTECTED]> wrote:
>
> > > I'm not sure I completely understand what's going on, so I apologize
> > > is this is obvious use error :)
>
> > > I'm trying to add to the create_all() method (by wrapping in my own
> > > method) for some custom SQL to be executed after the basic
> > > metadata.create_all() method is finished.
>
> > > More specifically, I have something like this:
>
> > > def create_all(metadata, engine):
> > >     metadata.create_all(engine)
> > >     s = Session()
> > >     s.begin()
> > >     engine.func.AddGeometryColumn('mytable', 'geo_col', 4326, 'POINT',
> > > 2).execute()
> > >     s.commit()
>
> > what's going on here is that the Session's transaction has no
> > interaction with the call to engine.func.XXX().execute().  There is no
> > thread-local context in progress by default.  Additionally, the
> > specific call you are making, "AddGeometryColumn", is not recognized
> > by SQLA as an "autocommit" phrase so even the engine.execute() does
> > not issue its own COMMIT.
>
> > Your above app would work if you instead bound the Session to the
> > engine (Session(bind=engine)) and used Session.execute().  Its a
> > little weird to use a Session here at all since no ORM functionality
> > is needed and I'd opt instead to use a Connection/Transaction combo,
> > but even better in this specific case is to use a DDL() construct,
> > which will execute automatically after a table create:
>
> >http://www.sqlalchemy.org/docs/04/sqlalchemy_schema.html#docstrings_s...
>
> Thanks so much for the reply!  -- I think I understand and I agree
> that an ORM transaction is probably not necessary here at all.  I
> *just* finished reading the Transaction page and now I understand that
> distinction.  I'll use a connection directly.

... and actually, after doing some more reading on DDL() I think that
will indeed prove to be the easiest and cleanest.

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