Exemplo n.º 1
0
    def query_db(self):
        if self.conn is not None:
            self.conn.autocommit = True
            install_trigger_function(self.conn)
            install_trigger(self.conn, self.table_name)
            register_event_channel(self.conn)
            try:
                print("LIStening for event...")
                while True:
                    row_ids = []
                    for evt in poll(self.conn):
                        print('New Event: {}'.format(evt))
                        row_id = vars(evt)['row_id']
                        row_ids.append(row_id)

                    if len(row_ids) > 0:
                        self.row_id = max(row_ids)

                        self.query_db_basic()
                        self.transform_and_scale()
                        if self.img is not None:
                            self.send(text_data=self.img.decode('utf-8'))
            except KeyboardInterrupt:
                print('User exit via Ctrl-C; Shutting down...')
                unregister_event_channel(connection)
                uninstall_trigger(connection, table_name)
                uninstall_trigger_function(connection)
                print('Shutdown complete.')
Exemplo n.º 2
0
 def test_add_trigger_function_extended(self, connection, rowid, rowidtype,
                                        triggerid, success):
     try:
         trigger.install_trigger_function(connection,
                                          rowid=rowid,
                                          rowidtype=rowidtype,
                                          triggerid=triggerid)
         installed = trigger.trigger_function_installed(
             connection, triggerid)
         assert installed == success
     except Exception as e:
         # assert that it should fail i.e. not success
         assert not success
Exemplo n.º 3
0
    def test_add_trigger_function(self, connection):
        trigger_function_installed = False

        trigger.install_trigger_function(connection)
        try:
            execute(
                connection,
                "SELECT pg_get_functiondef('public.psycopg2_pgevents_create_event'::regproc);"
            )
            trigger_function_installed = True
        except:  # noqa: E722
            # Ignore error, its only use in this test is cause following
            # assertion to fail
            pass

        assert trigger_function_installed
Exemplo n.º 4
0
def triggers_installed(connection):
    install_trigger_function(connection, rowid='id')
    install_trigger(connection, 'settings')
    install_trigger(connection, 'orders', schema='pointofsale')
Exemplo n.º 5
0
def trigger_fn_installed(connection):
    trigger.install_trigger_function(connection)
Exemplo n.º 6
0
def triggers_installed(connection):
    install_trigger_function(connection)
    install_trigger(connection, "settings")
    install_trigger(connection, "orders", schema="pointofsale")