Skip to content

Instantly share code, notes, and snippets.

@pudo
Created December 4, 2011 14:17
Show Gist options
  • Save pudo/1430304 to your computer and use it in GitHub Desktop.
Save pudo/1430304 to your computer and use it in GitHub Desktop.
from uuid import uuid4
def trigger_table(connection, database_name, table):
def insert_handler(row_id):
print "DB: %s, TABLE: %s, ROW: %s" % database_name, table.name, row_id
name = 'callback_' + str(uuid4()).replace('-', 'x')
connection.connection.create_function(name, 1, insert_handler)
connection.connection.execute("""CREATE TRIGGER trigger_%s
AFTER INSERT ON foo BEGIN SELECT %s(NEW.rowid); END;""" % (name, name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment