Exemplo n.º 1
0
def get_all_messages(sender, receiver):
    view = []
    try:
        mycursor = DBManager.getCursor()
        mycursor.execute("SELECT * FROM messages WHERE (sender_username = %(sender)s AND receiver_username = %(receiver)s) " +
                        "OR (receiver_username = %(sender)s AND sender_username = %(receiver)s)" +
                        "ORDER BY sending_date ASC", { 'sender': sender, 
                                                        'receiver': receiver})
        view = mycursor.fetchall()
        DBManager.closeConnection()
    except Exception as error:
        print(f'error in get_all_messages: {str(error)}')
    return view
Exemplo n.º 2
0
def get_all_chats(sender_username):
    view = []
    try:
        mycursor = DBManager.getCursor()
        mycursor.execute("SELECT d.username FROM dogs d " +
                            "INNER JOIN likes l ON l.dog_id = d.dog_id " +
                            "WHERE l.username=%(sender)s " +
                            "AND d.dog_id NOT IN (SELECT dog_id FROM adopted) " +
                            "AND d.username <> %(sender)s " +
                            "AND l.answer='yes'" + 
                            "UNION " +
                            "SELECT l.username FROM dogs d " +
                            "INNER JOIN likes l ON l.dog_id = d.dog_id " +
                            "WHERE d.username=%(sender)s " +
                            "AND l.username <> %(sender)s " +
                            "AND l.answer='yes'" +
                            "AND d.dog_id NOT IN (SELECT dog_id FROM adopted) " +
                        "ORDER BY 1 ASC", { 'sender': sender_username, })
        view = mycursor.fetchall()
        DBManager.closeConnection()
    except Exception as error:
        print(f'error in get_all_chats: {str(error)}')
    return view