def raw_query(conn: pymysql.connections.Connection, query: str): """ Query Dangerously & Close DB Connection. :param conn: pymysql Connection Object :param query: Query Sentence :return: is_success, result """ try: c = conn.cursor() c.execute(query) return True, c.fetchall() except Exception as e: print("ERROROROROROROR!!!!!:", e) return False, e finally: conn.close()
def connected(connection: pymysql.connections.Connection): """A context with global convenience functions for MySQL/MariaDB queries. Specifically: — select(statement, vals) — execute(statement, vals) Where cursor.execute(statement, vals) is called. """ try: global select, execute def execute(statement: str, vals: Tuple = ()) -> None: with connection.cursor() as cursor: cursor.execute(statement, vals) connection.commit() def select(statement: str, vals: Tuple = ()) -> Iterator[Dict]: with connection.cursor() as cursor: cursor.execute(statement, vals) return cursor yield finally: connection.close()
def roll_back(conn: pymysql.connections.Connection, cursor: pymysql.cursors.Cursor): conn.rollback() cursor.close() conn.close()
def db_close(cls, db_conn: pymysql.connections.Connection) -> None: db_conn.close()
def Fecha_Conexao(connection: pymysql.connections.Connection) -> None: connection.close()
def closeConnection(con: pymysql.connections.Connection): if con: con.close()