コード例 #1
0
def excecuteDeleteQuery(query):
    deleted = False
    try:
        # read connection parameters
        params = config()

        # connect to the PostgreSQL server
        print('Connecting to the PostgreSQL database...')
        conn = psycopg2.connect(**params)

        mydb = conn.cursor()
        mydb.execute(query)
        conn.commit()
        deleted = True
        mydb.close()
    except Exception as e:
        logging.debug(e)
    finally:
        if conn is not None:
            conn.close()
    return deleted
コード例 #2
0
def excecuteFetchAllQuery(query):
    myresult = ""
    try:
        # read connection parameters
        params = config()

        # connect to the PostgreSQL server
        print('Connecting to the PostgreSQL database...')
        conn = psycopg2.connect(**params)

        mydb = conn.cursour(cursor_factory=psycopg2.extras.DictCursor)
        mydb.execute(query)
        myresult = mydb.fetchall()
        logging.debug(myresult)
        mydb.close()
    except Exception as e:
        logging.debug(e)
    finally:
        if conn is not None:
            conn.close()
    return myresult