我无法检索数据

时间:2020-09-27 13:02:34

标签: python database

我可以插入数字,例如102020,但是不能插入像833a7a763c15cc33e0d2157a1b8464047e9f2ad8f3e84f02f594a99a590f1ac5这样的键。我得到了这个错误。我仍然不知道。我已经解决了4个多小时。

这是错误消息

 Traceback (most recent call last):
  File "C:/Users/hp/Downloads/SimpleCoin-master/SimpleCoin-master/simpleCoin/recent.py", line 55, in <module>
    trans()
  File "C:/Users/hp/Downloads/SimpleCoin-master/SimpleCoin-master/simpleCoin/recent.py", line 38, in trans
    cursor.execute(sql_cmd)
sqlite3.OperationalError: unrecognized token: "833a7a763c15cc33e0d2157a1b8464047e9f2ad8f3e84f02f594a99a590f1ac5"

这是我的代码

import sqlite3, time
from datetime import datetime


def st():
    with sqlite3.connect("AA1.db") as db:
        cursor = db.cursor()
        # create table
        cursor.execute('''
            CREATE TABLE IF NOT EXISTS transactions(
            private_k VARCHAR(250) NOT NUll,
            sender_k VARCHAR(250) NOT NULL,
            receiver_k VARCHAR(250) NOT NULL,
            c_amount INTEGER NOT NULL,
            dNt TEXT NOT NULL);
            ''')
        # insert values to table from user input

        pri_key = input('Sender Private Key: ')
        pub_key = input('Sender Public Key: ')
        r_pub_k = input('Receiver Public Key: ')
        c_amount = input('Amount: ')
        dt_for = datetime.now().strftime("%B %d, %Y %I:%M%p")
        cursor.execute(""" 
            INSERT INTO transactions(private_k, sender_k, receiver_k, c_amount, dNt)
            VALUES (?,?,?,?,?)   
            """, (pri_key, pub_key, r_pub_k, c_amount, dt_for))
        db.commit()
        # print("Data entered successfully")


def trans():
    private_key = input("Enter your private key: ")
    with sqlite3.connect("AA1.db") as db:
        cursor = db.cursor()

    sql_cmd = 'SELECT * FROM transactions WHERE private_k={}'.format(private_key)
    cursor.execute(sql_cmd)
    for row in cursor.fetchall():
        #pri_key = row[0]
        pub_key = row[1]
        r_pub_k = row[2]
        c_amount = row[3]
        dt_for = row[4]
        #print(pri_key)
        print('-------------------------------')
        print("From:", pub_key)
        print("To:", r_pub_k)
        print("Amount: ", c_amount)
        print("Date and Time: ", dt_for)
        print('-------------------------------')


st()
trans()

0 个答案:

没有答案