def insert_one(dbname, sql, args): connection = MysqlConf.get_connection(dbname) cur = connection.cursor() cur.execute(sql, args) connection.commit() del cur del connection return 1
def fetchall(dbname, sql): connection = MysqlConf.get_connection(dbname) cur = connection.cursor() cur.execute(sql) res = cur.fetchall() del cur del connection return res
def fetchmany(dbname, sql, size=65535): connection = MysqlConf.get_connection(dbname) cur = connection.cursor() cur.execute(sql) res = cur.fetchmany(size) del cur del connection return res
def run_cache(): settings.configure() conf = MysqlConf() sql = "SELECT s_info_windcode,s_info_indexwindcode FROM chinamutualfundbenchmark " res = mysqlops.fetchmany(MysqlConf.DB.fof, sql) for n in res: wc = n['s_info_windcode'].decode() index = n['s_info_indexwindcode'].decode() cache.setdefault(wc, index) print('wind ma%s' % wc) print('index %s' % index)
def __init__(self, get_response=None): log.info("starting create database pool.") conf = MysqlConf() log.info("\r\n" "database pool created.\r\n" "Using :\r\n" "from conf import mysqlops,\r\n" + str(conf)) ThreadTool() load_cache() super().__init__(get_response)
def del_data(tname=None, sqlPa=None): connection = MysqlConf.get_connection(MysqlConf.DB.fof) cur = connection.cursor() try: if sqlPa: sql = sqlPa else: sql = 'delete from %s' % tname cur.execute(sql) connection.commit() except: print('删除表数据失败 %s' % tname) connection.rollback() connection.close() return False connection.close() return True