关于pymysql无法读取最新数据,困扰两天了,求助大神
本帖最后由 Jimelor 于 2020-11-3 09:21 编辑这是我封装pymysql代码,__init__信息我没贴出来:
class MysqlDb(object):
def query(self, sql, state="all"):
"""
查询
:param sql:
:param state: all是默认查询全部
:return:
"""
try:
self.cur.execute(sql)
if state == "all":
# 查询全部
data = self.cur.fetchall()
else:
# 查询单条
data = self.cur.fetchone()
time.sleep(1)
self.log.logging_level("debug","执行SQL为:{1},查询结果为:{0}".format(data,sql))
return data
except Exception as e:
self.log.logging_level("total_error", "数据库操作异常 {0}".format(e))
self.conn.rollback()
finally:
self.conn.commit()
def execute(self, sql):
"""
更新、删除、新增
:param sql:
:return:
"""
try:
# 使用execute操作sql
rows = self.cur.execute(sql)
self.log.logging_level("debug", "执行SQL为:{1},共有{0}满足条件,执行完毕".format(rows,sql))
time.sleep(1)
return rows
except Exception as e:
self.log.logging_level("total_error","数据库操作异常 {0}".format(e))
self.conn.rollback()
finally:
self.conn.commit()
print("执行一次")
为什么我删除数据后,再添加数据,再用下面的红字进行查询时,有一个表无法查询到新增的数据,有一个表确能查询到新增数据,实际上两个表已经都新增了数据
def test_openpayareamain(self):
url = "http://xxxxx/user/partnerInfo/create"
data = {"phone":"15200000000","partnerTypeCode":"AREA_MAIN","createType":3,"remark":"32","giftSoftwareEditionSelectIndexs":0}
data_str = json.dumps(data)
self.yaml = OperationYaml()
self.authorization_info = self.yaml.get_yaml_keyvalue("token")
self.log.logging_level("debug","当前的最新token:{0}".format(self.authorization_info))
self.authorization_info.update({"Content-Type" : "application/json"})
res = self.runmethod.run_main("POST",url,data=data_str,headers=self.authorization_info)
select_stock_sql = "select * from`partner_software_edition_stock` where user_id ='1316270994166407169'"
stock_sql_result = self.user_db.query(select_stock_sql)
#校验partner_info 内是否有新增内容
select_partner_info_sql = "SELECT * FROM `partner_info` where user_id = '1316270994166407169' and partner_type_code = 'AREA_MAIN'"
partner_info_result = self.user_db.query(select_partner_info_sql)
self.assertNotEqual(partner_info_result,(), "partner_info内无信息,校验失败") 有大神帮忙看下吗 你这问题解决了吗?
页:
[1]