[Tutor] Proper SQLite cursor handling?

boB Stepp robertvstepp at gmail.com
Fri Jul 2 23:55:14 EDT 2021


I have the start of a class to create solitaire game objects:

class SolitaireGame:
    """Representation of a solitaire game."""

    def __init__(self, db_cursor: sqlite3.Cursor, game_name: str) -> None:
        """Create or open a solitaire game."""
        self.cur = db_cursor
        self.game_name = game_name

My current thought is to create only a single cursor object and use it
throughout the program's lifetime.  Is this a sensible thing to do?
In the above class skeleton my intent is to retrieve the game
information from the database using the passed in cursor.  During the
course of a program session the user may have any number of different
solitaire games open, so each of these game objects would have its own
reference to the _same_ cursor object.  I have an uneasy feeling that
this might cause issues, but I don't know enough (yet) and am still at
the pondering point for this class.  Eventually I will write tests and
try things out to see what happens, but one of you might save me some
painful explorations and time!

TIA!
boB Stepp


More information about the Tutor mailing list