Mistake in an attempt to challenge the method that receives data from bd sqlite3



  • Python writes a violin that will make user requests. To work with sqlite, he wrote a class that has a method to get_user_queries.

    def get_user_queries(self, user_id):
        with self.connection:
            result = self.cursor.execute('SELECT query FROM user_query WHERE user_id = ?', (user_id,))
            queries = result.fetchall()
            return queries
    

    When calling this method

    queries = db.get_user_queries(user_id)
    

    There is a mistake:

    sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 13900 and this is thread id 16660.

    What's the reason and how to solve the problem?



  • Multi-flow support for SQLite3 should be included, adding the following arguments for connection with OBD

    sqlite.connect(":memory:", check_same_thread = False)
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2