我正在尝试对数据库进行两次调用,调用是多线程的。但有时第一个调用数据可能为空,因此会出错:ProgrammingError:(2014,“命令不同步;您现在无法运行此命令”)
当我调用第二个查询时。有没有办法清除光标而不关闭数据库连接?
# CHECK IF NO RECORD IN DATABASE OF SKU
try:
cursor.execute('SELECT * FROM `amazon` inner join `ebay` on amazon.ASIN=ebay.SKU WHERE `ASIN` = "%s"' % (sku))
data = cursor.fetchall()
except Exception as ee:
conn.rollback()
data = None
print "Ebay error", ee
# IF NO RECORD ADD EVERYTHING
if not data:
try:
print "Inserting into ebay table: " + str((sku, float(price), int(quantity), itemID, float(cp_price)))
cursor.execute('INSERT INTO ebay VALUES ("%s", %.2f, %.2f, %s, %.2f, %s)' % (sku, float(price), int(quantity), itemID, float(cp_price), True))
conn.commit()
except Exception as ee:
print('DB insert error', ee)
i += 1
continue