python中的sql语句无法执行的原因 50
从mysql数据库中读取数据,出现sql语句查询错误,sql语句在终端下运行可以正确得出查询结果源码cur.execute("selecthostidfromhostsw...
从mysql数据库中读取数据,出现sql语句查询错误,sql语句在终端下运行可以正确得出查询结果
源码
cur.execute("select hostid from hosts where host = %s",(remotehost)) #取出主机名
rows = cur.fetchone()
try :
hostid = rows[0]
except :
pass
cur.execute("select itemid from items where hostid = %s and key_='system.cpu.util[,idle]'",(hostid))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass
cur.execute("select value from history where itemid = %s and clock>%s and clock <=%s",(itemid,t2,t1))
rows = cur.fetchone()
try :
cpu = str(rows[0])
except:
pass
cur.execute("select itemid from items where hostid = %s and key_='system.cpu.util[,softirq]'",(hostid))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass
cur.execute("select value from history where itemid = %s and clock>%s and clock<=%s",(itemid,t2,t1))
rows = cur.fetchone()
try:
softirq = str(rows[0])
except:
pass
cur.execute("select itemid from items where hostid = %s and key_= %s",(hostid,item))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass
cur.execute("select value from history where itemid = %s and clock>%s and clock<=%s",(itemid,t3,t1))
rows = cur.fetchone()
try:
outgoing =float(rows[0])
outgoing = outgoing/1000
outgoing = str("%.2f"%outgoing)
except :
print "select value from history where itemid =",itemid," and clock>",t3," and clock<=",t1 #把错误的sql语句打印出来
pass 展开
源码
cur.execute("select hostid from hosts where host = %s",(remotehost)) #取出主机名
rows = cur.fetchone()
try :
hostid = rows[0]
except :
pass
cur.execute("select itemid from items where hostid = %s and key_='system.cpu.util[,idle]'",(hostid))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass
cur.execute("select value from history where itemid = %s and clock>%s and clock <=%s",(itemid,t2,t1))
rows = cur.fetchone()
try :
cpu = str(rows[0])
except:
pass
cur.execute("select itemid from items where hostid = %s and key_='system.cpu.util[,softirq]'",(hostid))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass
cur.execute("select value from history where itemid = %s and clock>%s and clock<=%s",(itemid,t2,t1))
rows = cur.fetchone()
try:
softirq = str(rows[0])
except:
pass
cur.execute("select itemid from items where hostid = %s and key_= %s",(hostid,item))
rows = cur.fetchone()
try:
itemid = int(rows[0])
except:
pass
cur.execute("select value from history where itemid = %s and clock>%s and clock<=%s",(itemid,t3,t1))
rows = cur.fetchone()
try:
outgoing =float(rows[0])
outgoing = outgoing/1000
outgoing = str("%.2f"%outgoing)
except :
print "select value from history where itemid =",itemid," and clock>",t3," and clock<=",t1 #把错误的sql语句打印出来
pass 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询