Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
894 views
in Technique[技术] by (71.8m points)

sql - Column Unknown Firebird Python

I'm trying to make a GUI with python and tkinter for a firebird database. When I try to write the input from boxes into the databse, I get error

fdb.fbcore.DatabaseError: ('Error while preparing SQL statement: - SQLCODE: -206 - Dynamic SQL Error - SQL error code = -206 - Column unknown - NUMBER - At line 1, column 99', -206, 335544569)

This is the code for the submit operation:

simnumbber = "SIM NUMBER"

def submit():

    #  Database connection in the function
    conn = fdb.connect(
    host='localhost', database='C:/SIMCARDS.fdb', user='user', password='password')
    # Cursor
    cur = conn.cursor()
    
    
    # Insert Into table
    cur.execute("""INSERT INTO table ("NUMBER", simnumbber, "OPERATOR", "TYPE", "TARIFF", "DATA", "STATUS") VALUES (:number, :simnumber, :operator, :type, :tariff, :data, :status);""",
    {
        'number': simnumber.get(),
        'simnumber': cardnumber.get(),
        'operator': operator.get(),
        'type': type.get(),
        'tariff': tariff.get(),
        'data': data.get(),
        'status': status.get()  

    })

    # Commit Cahanges
    conn.commit()
    # Close connection
    conn.close()

    # Clear Textboxes
    simnumber.delete(0, END)
    cardnumber.delete(0, END)
    operator.delete(0, END)
    type.delete(0, END)
    tariff.delete(0, END)
    data.delete(0, END)
    status.delete(0, END)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Leaving this here for anyone that has to do something like this. The problem was with the parameters I provided in the SQL query in the VALUES clause. Firebird didn't know what ':number' was. So the fixed query is this:
cur.execute("""INSERT INTO cards (number,"SIM NUMBER",OPERATOR,TYPE,TARIFF,DATA,STATUS) VALUES (?,?,?,?,?,?,?);""", (simnumber.get(),cardnumber.get(),operator.get(), type.get(), tariff.get(), data.get(), status.get()))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...