0

I'm getting an AttributeError: 'sqlite3.Connection' object attribute 'execute' is read-only and I honestly dont know why since I used same INSERT INTO method with other tables succesfully. Can you tell me where the problem is?

import os, sys
import sqlite3
from sqlite3 import Error

connection = None
try:
    connection = sqlite3.connect('database.db')
    cursor = connection.cursor()
    print("Connection to SQLite DB successful")
except Error as e:
    print(f"The error '{e}' occurred")

cursor.execute("""CREATE TABLE IF NOT EXISTS Tickets ( 
    id INT,
    indexNumber INT,
    movieNumber INT,
    screeningHall VARCHAR(30),
    movieName VARCHAR(30),
    screeningDate VARCHAR(30),
    screeningTime VARCHAR(30),
    ticketRow INT,
    ticketCol INT,
    ticketType VARCHAR(30),
    ticketPrice VARCHAR(30))"""
)
idNum = 0
tempInfoDict = {'indexNumber': 0, 'movieNumber': 1, 'hall': 'Hall 1', 'name': 'Terminator', 'date': '2020-09-01', 'time': '10:40', 'row': 1, 'col': 0}

connection.execute = ("INSERT INTO Tickets (id, indexNumber, movieNumber, screeningHall, movieName, screeningDate, screeningTime, ticketRow, ticketCol, ticketType, ticketPrice) values(?,?,?,?,?,?,?,?,?,?,?)",
                                            (idNum, tempInfoDict['indexNumber'], tempInfoDict['movieNumber'], tempInfoDict['hall'], tempInfoDict['name'],
                                            tempInfoDict['date'], tempInfoDict['time'], tempInfoDict['row'], tempInfoDict['col'], 'Basic', '$20'))

connection.commit()
connection.close()

Thank you!

1
  • connection.execute(....) without the = sign. Commented Sep 1, 2020 at 7:17

1 Answer 1

1
connection.execute = ("INSERT INTO Tickets (id, indexNumber, movieNumber, screeningHall, movieName, screeningDate, screeningTime, ticketRow, ticketCol, ticketType, ticketPrice) values(?,?,?,?,?,?,?,?,?,?,?)",
                                            (idNum, tempInfoDict['indexNumber'], tempInfoDict['movieNumber'], tempInfoDict['hall'], tempInfoDict['name'],
                                            tempInfoDict['date'], tempInfoDict['time'], tempInfoDict['row'], tempInfoDict['col'], 'Basic', '$20'))

should be

cursor.execute("INSERT INTO Tickets (id, indexNumber, movieNumber, screeningHall, movieName, screeningDate, screeningTime, ticketRow, ticketCol, ticketType, ticketPrice) values(?,?,?,?,?,?,?,?,?,?,?)",
                                                (idNum, tempInfoDict['indexNumber'], tempInfoDict['movieNumber'], tempInfoDict['hall'], tempInfoDict['name'],
                                                tempInfoDict['date'], tempInfoDict['time'], tempInfoDict['row'], tempInfoDict['col'], 'Basic', '$20'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.