我编写了一个代码,从表中提取数据并将其插入字典,然后截断表并在表中插入新值,但是当我运行代码时,它会立即截断表。
我试图删除截断代码,但它仍然截断表。
import ccxt
import mysql.connector
import os
import sys
import time
from collections import defaultdict
import json
import requests
import logging
import telegram
cnx = mysql.connector.connect(user='root', password='',
host='localhost', database='coinbuys',
auth_plugin='mysql_native_password')
mycursor = cnx.cursor()
sql = """SELECT * FROM coinscores """
mycursor.execute(sql)
myresult = mycursor.fetchall()
for row in myresult:
coin_score_symbol = row[1]
coin_score_database_value = row[2]
print (coin_score_symbol)
print (coin_score_database_value)
# this prints nothing ^
sql = "INSERT INTO BUYWALLDATA3 (COINPAIR, price, size, volumethreshold) VALUES (%s, %s, %s, %s)"
val = [
(whichmarket[f],
var_element_check[0], sum_array_check, volume_threshold)
]
mycursor.executemany(sql, val)
cnx.commit()
print(mycursor.rowcount, "was inserted.")
for key in coins_with_buy_walls.keys():
sql = """SELECT * FROM BUYWALLDATA3 WHERE COINPAIR = '%s' """ % (key)
rows = 0
mycursor.execute(sql)
myresult = mycursor.fetchall()
for row in myresult:
rows = rows + 1
id_table = row[0]
ticker = row[1]
coin_price = row[2]
size_order = row[3]
volume_calculation = row[4]
volume_calculation = row[4] + volume_calculation
# Here would be the truncate statement
for a in coin_score:
coin_final_score = coin_score[a]
sql = "INSERT INTO coinscores (symbol, score) VALUES (%s, %s)"
val = [(a, coin_final_score)]
mycursor.executemany(sql, val)
cnx.commit()
print(mycursor.rowcount, "was inserted.")
# This is the code I used to create the coin scores table
mycursor.execute("CREATE TABLE coinscores (id INT AUTO_INCREMENT PRIMARY KEY, symbol VARCHAR(255), score VARCHAR(255))")
我已经包含了我所有的数据库语句,也许是它们有问题导致了这种情况。我希望第一个数据库调用打印coin scores中的所有值,然后擦除它并插入新数据。
1条答案
按热度按时间nzrxty8p1#
我在文件夹中有另一个文件,其中写入了截断行,出于某种原因,当我删除时,它修复了问题。