0

table named excercise

CODB_cursor.execute(""" CREATE TABLE excercise (
                    distance INTEGER
                    timeOfRun INTEGER
                    avgHR INTEGER
                    dayOfExcercise timestamp
                    )""")

callOnDB.commit()

function that inserts values to the table named excercise

def insert_excercise(exc):
    with callOnDB:
        CODB_cursor.execute("INSERT INTO excercise VALUES(:distance,:timeOfRun,:avgHR,:dayOfExcercise)",
                            {'distance':exc.distance,'timeOfRun':exc.timeOfRun,
                            'avgHR':exc.avgHR,'dayOfExcercise':exc.dayOfExcercise})

in a different file named excercise there is a class named Excercise with self, distance, timeOfRun, avgHR, dayOfExcercise. exc_1 is passed to insert_excercise function

exc_1 = Excercise(4, 120, 154, datetime.datetime.now())
insert_excercise(exc_1)

i keep on getting :::sqlite3.OperationalError: table excercise has 1 columns but 4 values were supplied:::

i don't know why , i have 4 columns named (distance, timeOfRun, avgHR, dayOfExcercise) i have import sqlite3, import datetime, and from excercise import Excercise (this refers to the other file that has the class excercise)

1 Answer 1

1

This is creating one column!

CREATE TABLE excercise (
                    distance INTEGER
                    timeOfRun INTEGER
                    avgHR INTEGER
                    dayOfExcercise timestamp
                    )

Syntax requires a , between column definitions eg (col1 TYPE, col2 TYPE, col3 TYPE....)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.