1

I've searched and tried most ideas on here about solving this, and I just don't know whats going on.

Class

class Posts:
    def __init__(self):
        self.connection = sqlite3.connect('C:/Users/mattv/Desktop/Scripts/simpsons-gpt2/comments.sqlite3')
        self.cursor = self.connection.cursor()

    def get(self, id):
        self.cursor.execute("SELECT * FROM comments where id='%s'" % id)

        row = self.cursor.fetchone()

        return row

    def add(self, id):
        try:
            self.cursor.execute("INSERT INTO comments VALUES('%s')" % id)
            lid = self.cursor.lastrowid
            self.connection.commit()
            return lid
        except sqlite3.IntegrityError:
            return False

Error

  File "c:/Users/mattv/Desktop/Scripts/simpsons-gpt2/comment_check.py", line 124, in get
    self.cursor.execute("SELECT * FROM database where id='%s'" % id)
sqlite3.OperationalError: no such table: database

The sqlite3 is definitely in the same folder as comment_check.py and I can see it in the opened folder of VSCode

Can anyone help?

Hadeess
  • 29
  • 2
  • 1
    The code that throws this error is not the code you posted here. – forpas Aug 24 '20 at 20:08
  • Look into [parameterization](https://docs.python.org/3.8/library/sqlite3.html) and note [`%` has been de-emphasized](https://stackoverflow.com/a/13452357/1422451) (not officially deprecated *yet*) in Python for string formatting. – Parfait Aug 24 '20 at 21:17
  • I figured it out, I was calling the "get"" function in the class and passing in a variable which had a chance to be Null – Hadeess Aug 26 '20 at 12:30

0 Answers0