为什么sql数据库显示错误的值

问题描述 投票:0回答:0
for i in values:   
    monthNum = i+1
    date = "1/" + str(monthNum) + "/" + str(year)
    value = m[i]
    data.append((int(xref), int(yref), date, int(value)))

# Create a connection to the database
conn = sqlite3.connect("data.db")
c = conn.cursor()

# Create the table if it doesn't already exist
c.execute('''CREATE TABLE IF NOT EXISTS data
             (Xref REAL, Yref REAL, Date TEXT, Value REAL)''')
print(data)
# Insert the data into the table
c.executemany('INSERT INTO data VALUES (:xref, :yref, :date, :value)', data)
#SELECT * FROM conn
c.execute("SELECT * FROM data LIMIT 25")
rows = c.fetchall()
for row in rows:
    print(row)

上面的代码将 4 个值附加到“数据”的每个元素中。 xref 和 yref 值基于从文件中读入的数据。它们在打印出来时显示预期的 int 值,甚至在打印出“数据”时,它也显示这些正确的值,但由于某种原因,在打印出数据库表的行时,它打印出 xref 和 yref 的值,我在开始时进行硬编码以对其进行测试(100 和 200),但此后已删除。

这些值在代码和正在读入的文件中的任何地方都没有提到。我什至尝试将这段代码复制并粘贴到另一个文件中,但同样的事情发生了。你知道为什么会这样吗?

python sql database sqlite readfile
© www.soinside.com 2019 - 2024. All rights reserved.