def query_data_from_mysql(db_path, port, db_name, user_name, pass_wd, table_name, check_list, unique_id_col, unique_id_value): """ mysql conditional query return : result DataFrame catch all exceptions """ _query_col = ",".join(check_list) try: _con = ConnectMysql.mysql_connection(db_path, port, user_name, pass_wd, db_name) _query_sql = "select %s from %s where %s = %s" % (_query_col, table_name, unique_id_col, unique_id_value) data_from_mysql = pd.read_sql(_query_sql, con=_con) _con.close() except Exception, ex: print Exception, ":", ex data_from_mysql = pd.DataFrame()
def query_data_from_mysql_mc(db_path, port, db_name, user_name, pass_wd, query_sql): """ mysql conditional query (query by SQL) return : result DataFrame catch all exceptions usage: pass """ # _query_col = ",".join(check_list) try: _con = ConnectMysql.mysql_connection(db_path, port, user_name, pass_wd, db_name) _query_sql = query_sql _data_from_mysql = pd.read_sql(_query_sql, con=_con) _con.close() except Exception, ex: print Exception, ":", ex _data_from_mysql = pd.DataFrame()
def query_data_from_mysql_mq(db_path, port, db_name, user_name, pass_wd, table_name, check_list, unique_id_col, value_list): """ mysql conditional query use in (multi conditional subquery) return : result DataFrame catch all exceptions usage: pass """ _query_col = ",".join(check_list) value_tuple = str(tuple(value_list)) try: _con = ConnectMysql.mysql_connection(db_path, port, user_name, pass_wd, db_name) _query_sql = "select %s from %s where %s in %s" % (_query_col, table_name, unique_id_col, value_tuple) data_from_mysql = pd.read_sql(_query_sql, con=_con) _con.close() except Exception, ex: print Exception, ":", ex data_from_mysql = pd.DataFrame()