'Remove an entire table from the database'

def Drop(self, table):

    txn = None
    try:
        txn = self.env.txn_begin()
        self.db.delete(_columns_key(table), txn=txn)
        cur = self.db.cursor(txn)
        table_key = _search_all_data_key(table)
        while 1:
            try:
                (key, data) = cur.set_range(table_key)
            except db.DBNotFoundError:
                break
            if (key[:len(table_key)] != table_key):
                break
            cur.delete()
        table_key = _search_rowid_key(table)
        while 1:
            try:
                (key, data) = cur.set_range(table_key)
            except db.DBNotFoundError:
                break
            if (key[:len(table_key)] != table_key):
                break
            cur.delete()
        cur.close()
        tablelist = pickle.loads(getattr(self.db, 'get_bytes', self.db.get)(_table_names_key, txn=txn, flags=db.DB_RMW))
        try:
            tablelist.remove(table)
        except ValueError:
            pass
        self.db.delete(_table_names_key, txn=txn)
        getattr(self.db, 'put_bytes', self.db.put)(_table_names_key, pickle.dumps(tablelist, 1), txn=txn)
        txn.commit()
        txn = None
        if (table in self.__tablecolumns):
            del self.__tablecolumns[table]
    except db.DBError as dberror:
        if txn:
            txn.abort()
        raise TableDBError(dberror.args[1])
