C
C
char9062021-02-07 01:12:15
Python
char906, 2021-02-07 01:12:15

Why is data not being written to SQlite?

def add_randcode(self, code):
        with self.connection:
            code = self.cursor.execute("SELECT * FROM `subscriptions` WHERE `code` = ?", (code, )).fetchone()
            if code == None:
                code = random.randint(1000,9999)
                self.cursor.execute("""INSERT INTO subscriptions(code) 
                VALUES (?)""", (code, ))
                return code
            else:
                return code


Good day, SQL syntax does not work, SELECT always returns None, and INSERT does not write anything to the database

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wispik, 2021-02-07
@char906

Why duplicate the question? They answered you there, you need to make a commit
self.connection.commit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question