Python Forum
SQLITE 3 Database error in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQLITE 3 Database error in Python
#1
Here is my code for my database....

import sqlite3

conn = sqlite3.connect("TestBase5.db")

c = conn.cursor()


# c.execute("""CREATE TABLE Students (
#             StudentID   INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
#             FirstName   string,
#             Surname string,
#             Password string
#             Highscore   integer,
#             AverageWeeklyPlays  integer,
#             ClassID integer
#             )""")
#
# c.execute("""CREATE TABLE Classes (
#             ClassID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
#             TeacherID   integer,
#             ClassName   string
#             )""")
#
# c.execute("""CREATE TABLE Teachers (
#             TeacherID   INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
#             TeacherName    string
#             )""")


def insertteacher(teachername):
    teachernam = str(teachername)
    c.execute("INSERT INTO teachers (TeacherName) Values (?)", (teachernam,))


def insertstudent(first, last, score, classname, password):
    c.execute("SELECT ClassID FROM classes WHERE ClassName = (?)", (classname,))
    classid = c.fetchall()
    classidstr = str(classid)
    classidint = classidstr[2:3]

    print(c.fetchall)
    print(classidstr)
    print(classidint)

    c.execute("INSERT INTO students (FirstName, Surname, Password, Highscore, AverageweeklyPlays, ClassID) Values (?,?,?,?,?,?)", (first, last, password, score, 0, classidint))


def insertclass(classname, teachername):
    c.execute("SELECT TeacherID FROM teachers WHERE TeacherName = (?)", (teachername,))
    teacher = c.fetchall()
    teacherstr = str(teacher)
    teacherid = teacherstr[2:3]

    c.execute("INSERT INTO Classes (TeacherID, ClassName) Values (?,?)", (teacherid, classname))


insertstudent("Kai", "Shepherd", 0,  "Year1", "Cunt")
#
# #
# insertteacher("MrTest")
# insertteacher("MrsTest")
# insertteacher("MrTest2")
# insertteacher(("MrsTest2"))
#
# insertclass("Year1", "MrTest")
# insertclass("Year2", "MrsTest")
# insertclass("Year3", "MrTest2")
# insertclass("Year4", "MrsTest2")
# #
# # insertstudent()

c.execute("SELECT * FROM classes")

print(c.fetchall())

conn.commit()

conn.close()
The problem that I am posed with is the error..... "sqlite3.OperationalError: table students has no column named Highscore" However there is clearly a column named highscore?

Help for this would be greatly appreciated
Reply
#2
Quote:# Password string
# Highscore integer,
There's no comma between these fields. I have no idea how sqlite handles malformed queries, but it might be worthwhile to do like a select * so you can see what the actual table structure is.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  database: json format and sqlite izan 1 7,228 Dec-28-2021, 06:45 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020