hi jason, after a second thought, i have used your idea for data preloading. it is way more pythonic and portable that ddl.
thanks again, alex On Mon, Sep 8, 2008 at 6:45 PM, jason kirtland <[EMAIL PROTECTED]> wrote: > > alex bodnaru wrote: >> hello friends, >> >> i wanted to do a few sql commands in a ddl construct, but i failed with: >> >> pysqlite2:dbapi2 warning: you can execute one statement at a time >> >> i'm not very familiar with python db layer, but i know sqlite may be invoked >> specifically to execute one, or many statements divided by ';', so i suspect >> it's specifically invoked for one statement. >> >> while this is a good security measure for sql from untrusted sources, like >> user >> input, it's quite annoying for a situation where free sql should be >> specifically >> added. >> >> as for my case, i had a batch of inserts based on an external file, >> and i couldn't >> invoke ddl.execute_at in a loop, so i had to switch to inserting a >> batch of unioned >> selects in one insert, which was nice to learn :). > > The use case behind the DDL() construct is a single statement. You can > fire multiple statements by using multiple DDL()s. But for inserts, > I've found it more useful to write a 'after-create' event listener from > scratch. Here's one that I use in pretty much every project, in some > form or another: > > def fixture(table, column_names, *rows): > """Insert data into table after creation.""" > def onload(event, schema_item, connection): > insert = table.insert() > connection.execute( > insert, > [dict(zip(column_names, column_values)) > for column_values in rows]) > table.append_ddl_listener('after-create', onload) > > Looks like this in use: > > fixture(some_table, > ('x', 'y'), > (1, 2), > (3, 4), > (5, 6)) > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---