user8558694
user8558694

Reputation:

Python3 - Database sqlite3 - sqlite3.OperationalError: no such column:

I am trying to create a small and simple accountancy program, here is my code:

import sqlite3 as lite #db
import sys #db
from pathlib import Path #check file exists

successful_login = False

def login_process():
    print("Welcome to your accountance program, write your username: ")
    user = input()
    my_file = Path("./%s" % (user,))

    if my_file.is_file():
        con = lite.connect(user)
        main_loop()

    else:
        con = lite.connect(user)
        print("Write the name of your bank account: ")
        bankaccount = input()
        print("Write how much money do you have on it: ")
        starting_money = int(input())
        print(starting_money)

        with con:
            cur = con.cursor()
            cur.execute("CREATE TABLE Bank(Name TEXT, Money INT)")
            cur.execute("INSERT INTO Bank VALUES (%s,%s)" %  (bankaccount,starting_money))
        main_loop()

And here is the error:

,

Why is this happening ?

Thank you !

Upvotes: 0

Views: 40

Answers (1)

DinoCoderSaurus
DinoCoderSaurus

Reputation: 6520

From the python sqlite API doc:

# Never do this -- insecure!
symbol = 'RHAT'
c.execute("SELECT * FROM stocks WHERE symbol = '%s'" % symbol)

(And examining this INSECURE example carefully should illuminate what is the error in this program).

Suggest you use the doc to learn how to use placeholders. It is an important habit to develop.

Upvotes: 0

Related Questions