예제 #1
0
    def get_pydrill_conn(self, _connection_conf):
        if not PYDRILL_AVAILABLE:
            raise ImproperlyConfigured('pydrill must be installed.')
        conn = PyDrill(**_connection_conf)

        class cursor:
            def __init__(self):
                self.data = []
                self.description = ''
                self.cursor_index = -1

            def execute(self, sql):
                self.data = conn.query(sql)
                return self.data

            def fetchone(self, *args, **kwargs):
                self.cursor_index += 1
                try:
                    self.description = list(self.data.rows[self.cursor_index].items())
                    return self.description
                except IndexError:
                    return

            def close(self):
                return

        conn.cursor = cursor
        conn.commit = lambda: None
        return conn