Home > Mobile >  Can't add a record to a database without "sqlite3.OperationalError: near "(": sy
Can't add a record to a database without "sqlite3.OperationalError: near "(": sy

Time:11-30

I made a 'dummy' version for my program consisting of just the first four fields but once I added the rest, this error keeps appearing. Anyone else I've seen with this issue was due to something else that doesn't apply to mine. I feel like it's something small that I've missed, if anyone could help me figure this out it'd be a great help, thanks. I hope this is enough of the code to figure it out. Even if someone could tell me that the problem lies outside this code it would be a big help.


        connection = sqlite3.connect("TempDatabase.db")
        cursor = connection.cursor()

        sqlCommand = """
           CREATE TABLE IF NOT EXISTS OrderTb1N1
           (
           OrderID INTEGER NOT NULL,
           dateOrdered DATE,
           customerFirstname TEXT,
           customerSurname TEXT,
           customerPhoneNumber TEXT,
           collectionDate DATE,
           flavours TEXT,
           glaze TEXT,
           toppings TEXT,
           personalisation TEXT,
           orderSize TEXT,
           price REAL,
           paymentStatus TEXT,
           employeeName TEXT


           primary key (OrderID)
           )
        """

        cursor.execute(sqlCommand)
        connection.commit()
        connection.close()

Since the database already exists, I intended for this code to add additional fields (from the 'dummy' tests) and allow me to input new records. I have deleted all records made during the dummy tests. According to the error output, the error is somewhere within 'sqlCommand=' .

CodePudding user response:

you should need to use comma(,) after employeeName TEXT.

Correct code-

connection = sqlite3.connect("TempDatabase.db")
        cursor = connection.cursor()

        sqlCommand = "
           CREATE TABLE IF NOT EXISTS OrderTb1N1
           (
           OrderID INTEGER NOT NULL,
           dateOrdered DATE,
           customerFirstname TEXT,
           customerSurname TEXT,
           customerPhoneNumber TEXT,
           collectionDate DATE,
           flavours TEXT,
           glaze TEXT,
           toppings TEXT,
           personalisation TEXT,
           orderSize TEXT,
           price REAL,
           paymentStatus TEXT,
           employeeName TEXT,
           primary key (OrderID)
           )
        "

        cursor.execute(sqlCommand)
        connection.commit()
        connection.close()
  • Related