Hi,

I'm trying to use the sqlalchemy compiler to generate insert statements
that I can feed myself to MySQLdb.  With a sqlalchemy table definition, I'm
able to get a nice SQL statement using the following.

query =
str(table.insert().values(**kwargs).compile(dialect=MySQLDialect(paramstyle='pyformat')))

However, if the table has literal default values for any of the columns,
those column names end up in the generated SQL statement as variables even
if kwargs does not contain that key .   How can I get a dict of the literal
keys to merge with ones passed in when I execute the query?

Example:

Table('fubar', metadata,
            Column('id', Integer, primary_key=True),
            Column('status_id', Integer, nullable=False, default=1),
            Column('modified', DateTime, default=func.current_timestamp(),
onupdate=func.current_timestamp()),
            Column('created', DateTime, default=func.current_timestamp()),
            mysql_engine='InnoDB'
        )

produces

INSERT INTO fubar (status_id, modified, created) VALUES (%(status_id)s,
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)

I need to get a dict of literal defaults from somewhere so that I can pass
in {'status_id': 1} to cursor.execute()

Thanks,

Roger

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to