问题描述
- sql 找错,一个很奇怪的错误
-
sql = "UPDATE bs2_dl_road_min SET count=count+{0} WHERE time='{1}' " "AND host_ip='{2}' AND module='{3}' AND method='{4}' AND status='{5}' " "AND size_level='{6}' AND level='{7}' AND submodule_road='{8}'".format(count, str_time, host_ip, module, method, status, size_level, level, submodule_road) if db.myCur.execute(sql) >= 1: return True except Exception, e: #logger.error(traceback.format_exc().replace(' ', ' ')) return False finally: db.myConn.commit() ############################ Insert try: sql = "INSERT INTO bs2_dl_road_min(region, zone_id, host_ip, module, method, " "status, size_level, level, submodule_road, count, time) " "VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', " "'{10}')".format(region, zone_id, host_ip, module, method, status, size_level, level, submodule_road, count, str_time) if db.myCur.execute(sql) >= 1: return True except Exception, e: #logger.error(traceback.format_exc().replace(' ', ' ')) return False finally: db.myConn.commit() ############################ Update try: sql = "UPDATE bs2_dl_road_min SET count=count+{0} WHERE time='{1}' " "AND host_ip='{2}' AND module='{3}' AND method='{4}' AND status='{5}' " "AND size_level='{6}' AND level='{7}' AND submodule_road='{8}'".format(count, str_time, host_ip, module, method, status, size_level, level, submodule_road) if db.myCur.execute(sql) >= 1: return True except Exception, e: #logger.error(traceback.format_exc().replace(' ', ' ')) return False finally: db.myConn.commit() 三段sql ,逻辑是第一段根据主键更新数据,如果更新失败,说明主键不存在,则用此主键插入数据。如果插入失败,说明可能此主键被别的线程的事务插入了,再一次执行第一步的更新动作,这个程序跑了至少一年,都没出过问题 现在问题是,三段都出错了,第一段返回0,第二段直接报错主键冲突,第三段又返回0,求高手指导可能的问题在哪
解决方案
关键你这个不是纯 sql,建议你调试下看看呢
解决方案二:
一个奇怪的错误
今天一个奇怪的错误
一个与命名空间有关的奇怪错误!
时间: 2024-10-18 13:10:00