def get_child_by_parent_id(parent): conn, cursor = get_db_connection("forum") cursor.execute("""select * from comment_hierarchy where parent_comment_id=%s""",str(parent)) row = cursor.fetchall() conn.close() return row
def get_comment_by_id(comment_id): conn, cursor = get_db_connection("forum") cursor.execute("""select * from comments where comment_id=%s""",str(comment_id)) row = cursor.fetchone() conn.close() return row
def getAllTopics(): conn, cursor = get_db_connection("forum") query = 'select * from comments where comment_id IN (select comment_id from comment_hierarchy where parent_comment_id IS NULL);' cursor.execute(query) row = cursor.fetchall() conn.close() return row
def get_user_by_email(email): conn, cursor = get_db_connection("forum") query = 'select * from user_details where email = "'+ email +'";' cursor.execute(query) row = cursor.fetchone() conn.close() return row
def insert_new_post(email, PostText): conn, cursor = get_db_connection("forum") result = (False, None) try: cursor.execute("""INSERT INTO comments (comment_text, commenting_user_email) VALUES (%s, %s)""",(PostText, email)) result = (True, cursor.lastrowid) conn.commit() except: conn.rollback() conn.close() return result
def updatePostInDB(CommentId, PostText): conn, cursor = get_db_connection("forum") result = False try: cursor.execute("""UPDATE comments SET comment_text = %s WHERE comment_id = %s""",(PostText, CommentId)) result = True conn.commit() except: conn.rollback() conn.close() return result
def insert_user(email, username): conn, cursor = get_db_connection("forum") result = True try: cursor.execute("""INSERT INTO user_details (username, email) VALUES (%s, %s)""",(username, email)) conn.commit() except: conn.rollback() result = False conn.close() return result
def insert_comment_hierarchy(ParentId, comment_id): conn, cursor = get_db_connection("forum") result = True try: if ParentId: cursor.execute("""INSERT INTO comment_hierarchy(comment_id, parent_comment_id) VALUES (%s, %s)""",(comment_id,ParentId)) else: cursor.execute("""INSERT INTO comment_hierarchy(comment_id) VALUES (%s)""",(comment_id)) conn.commit() except: result = False conn.rollback() conn.close() return result