0

I can add the numbers like 2020 but cannot add my key to the sqlite3 database. my private key is like this 833a7a763c15cc33e0d2157a1b8464047e9f2ad8f3e84f02f594a99a590f1ac5 if i add the private key i got this error. i am new to python and i cannot find out the problem. i have been fixing the error more than 3 hours.

Here is the error msg

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

Here is my code

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 tran():
    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()
tran()
Python-
  • 1
  • 2
  • up up up someone pls help mee – Python- Sep 27 '20 at 12:03
  • Search [this page](https://docs.python.org/3/library/sqlite3.html) for "parameter substitution". Using `.format()` to create SQL statements doesn't always work as expected. – snakecharmerb Sep 27 '20 at 12:27
  • The answers to the question in the linked duplicate also contain examples of how to create SQL statements correctly. – snakecharmerb Sep 27 '20 at 12:30
  • which part is wrong sir. i can input the numbers but cannot find the results by alphabet @snakecharmerb – Python- Sep 27 '20 at 12:54
  • The traceback is telling you that `cursor.execute(sql_cmd)` is the line causing the error, and the cause of this is how you have constructed the query, as explained in the links provided to you. – snakecharmerb Sep 27 '20 at 13:15

0 Answers0