我试图对数据库进行两次调用,调用是多线程的。然而,有时第一个调用数据可能是空的,因此它会得到一个错误:ProgrammingError:(2014,“Commands out-out-sync;you cannot run this command now”)
当我调用第二个查询时。有没有办法在不关闭数据库连接的情况下清除光标?在# 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