[sqlalchemy] Re: Creating Oracle Triggers on Table Create

2008-08-19 Thread Michael Bayer


On Aug 19, 2008, at 1:59 PM, Gerrat wrote:


 Is there a way to easily hook into the table creation mechanism so
 that whenever a Sequence was specified as part of a Column definition,
 a similiar trigger could be inserted (substituting some names
 obviously)?  I know I can manually issue the DDL after-the-fact for
 each table create, but would prefer it be more implicit.


I'm assuming that you mean you're already familiar with the DDL()  
construct, which is documented at:

http://www.sqlalchemy.org/docs/05/sqlalchemy_schema.html#docstrings_sqlalchemy.schema_DDL

So the next step is to create your own Table function along the lines  
of:

from sqlalchemy.schema import Table as _Table, Sequence, DDL

def Table(name, meta, *args, **kw):
t = _Table(name, meta, *args, **kw)
for c in t.c:
if c.default and isinstance(c.default, Sequence):
DDL(your per-sequence DDL 
here).execute_at('after-create', t)
return t




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



[sqlalchemy] Re: Creating Oracle Triggers on Table Create

2008-08-19 Thread Gerrat



On Aug 19, 2:11 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Aug 19, 2008, at 1:59 PM, Gerrat wrote:



  Is there a way to easily hook into the table creation mechanism so
  that whenever a Sequence was specified as part of a Column definition,
  a similiar trigger could be inserted (substituting some names
  obviously)?  I know I can manually issue the DDL after-the-fact for
  each table create, but would prefer it be more implicit.

 I'm assuming that you mean you're already familiar with the DDL()  
 construct, which is documented at:

 http://www.sqlalchemy.org/docs/05/sqlalchemy_schema.html#docstrings_s...

 So the next step is to create your own Table function along the lines  
 of:

 from sqlalchemy.schema import Table as _Table, Sequence, DDL

 def Table(name, meta, *args, **kw):
         t = _Table(name, meta, *args, **kw)
         for c in t.c:
                 if c.default and isinstance(c.default, Sequence):
                         DDL(your per-sequence DDL 
 here).execute_at('after-create', t)
         return t


Thanks for the super-quick response, Michael.
That's exactly what I was looking for!

...not sure where my head was at...didn't think of just browsing the
sources to look at the Table class.  Pretty straight forward - thanks
again!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Creating Oracle Triggers on Table Create

2008-08-19 Thread Michael Bayer


On Aug 19, 2008, at 5:08 PM, Gerrat wrote:


 This doesn't quite work:

 the DDL class (well, the method '_TextClause' in the module
 'expression' actually) parses out any sql containing a ':' (colon) as
 if it were a bind variable.
 Althouth the documentation says: SQL bind parameters are not
 available in DDL statements, it still looks for anything that
 resembles a bind variable, then binds these variables to the None
 value.  Sqlalchemy then sends these invalid bind variables off to the
 database with the sql.

 I get an error back from the database with my trigger sql text,
 followed by {'new':None, 'old':None}.
 The special keywords in Oracle ':new', and ':old', aren't actually
 bind variables when used in PL/SQL.

 Any ideas for a workaround?
 I'm using version 0.5.0beta3-py2.5

the colon can be escaped using a backslash, i.e. \: .

Maybe it would be a good idea for DDL() to construct _Text() with a  
flag to disable bind parameter matching.


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